velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Dekany <>
Subject Re: EscapeTool (and velocity-tool best practices)
Date Thu, 09 Dec 2004 03:21:18 GMT
Wednesday, December 8, 2004, 9:21:34 PM, Mike Kienenberger wrote:

> I started using EscapeTool today (since it was far more comprehensive that my 
> primitive and misnamed URLEncoder tool), and noticed that it only took 
> String arguments.
> So if I had did $esc.html($value) and value wasn't a String, I got 
> '$esc.html($value)' returned as a literal.
> In general, should Velocity tools that operate on a String operate on an 
> Object instead and perform a object.toString() conversion first?  Or at 
> least provide Object argument wrapper methods to call the String argument 
> methods?
> Obviously, I can easily subclass EscapeTool even if no one else agrees with 
> me and add "public String html(Object object)"-like methods, but I'm curious 
> what we consider to be best-practices....

The Object.toString() method doesn't return text that should be
displayed for end-users (in general), but text for programmers (e.g. for
debugging) or for programs (e.g. storing values in a textual config.
file). For example java.lang.Number-s and java.util.Date-s, which are
frequently used in Web applications, possibly return the values
malformed for non-english user, and sometimes in confusing form for
english users (consider what does Date.toString return). But since
Velocity itself displays values with Object.toString() (i.e. it can't
display other Objects correctly but String-s and a few other text
storing types -- isn't that strange design for a template language that
is for MVC V?), the escaping tool may follows that logic as well, for
the sake of consistency.

Best regards,
 Daniel Dekany

Miert fizetsz az internetert? Korlatlan, ingyenes internet hozzaferes a FreeStarttol.
Probald ki most!

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message