[stringtemplate-interest] String manipulations
Emond Papegaaij
e.papegaaij at student.utwente.nl
Wed Aug 30 23:42:52 PDT 2006
On Wednesday 30 August 2006 23:11, Terence Parr wrote:
> On Aug 28, 2006, at 11:32 PM, Emond Papegaaij wrote:
> > On Tuesday 29 August 2006 02:50, Terence Parr wrote:
> >> On Aug 28, 2006, at 9:07 AM, Emond Papegaaij wrote:
> >>> First of all: StringTemplate really rocks! It's clean, easy to
> >>> use and
> >>> really powerful!
> >>>
> >>> There is however a single problem I keep facing. In many places I
> >>> have to
> >>> generate get- and set-methods for properties. For example the
> >>> property 'value' will get the methods 'getValue' and 'setValue'.
> >>> Right now
> >>> I'm passing both the lower case 'value' and the upper case
> >>> 'Value' to
> >>> these templates, but this is rather cumbersome. Is there any way to
> >>> perform simple string transformations with StringTemplate? That
> >>> would
> >>> greatly simplify most of my templates.
> >>
> >> Hi. Is this C#?
> >
> > No, Java.
>
> Ah. Ok, well, currently we have no "capitalize" predefined method.
> I suggest overriding setAttribute in ST to autowrap each String with
> another object that adds a capitalize method. Costs memory, but for
> now that is an easy solution. There are anumber of these like
> "escape URL".
>
Maybe it is an idea to look at the functions that are available in XSLT and
add similar functionality to StringTemplate? You could see them as
predefined templates, and perhaps even allow a developer to add his own
functions (such as Xalan Java extensions). I think functions like these
will allow a more clean separation between model and view, because the
model no longer needs to perform transformations that are actually part of
the view. There is however a risk of introducing too much power, which
allows a developer to put logic in the view. However I do think that if
the functions remain fairly simple (and don't have side-effects) this risk
is fairly small.
Best regards,
Emond Papegaaij
More information about the stringtemplate-interest
mailing list