You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Shinobu Kawai <sh...@gmail.com> on 2004/10/14 06:00:21 UTC
EscapeTool
Hi all,
In case anyone is interested, I made a cool tool that works with escaping in Velocity. I usually put o.a.c.lang.StringEscapeUtils or o.a.v.anakia.Escape in the context, but with all the weird behaviour in VTL escaping, I figured I might as well make a new tool for Velocity. Since it uses StringEscapeUtils, it adds a dependency to commons-lang 2.0. Again, no documentation but the tests.
The class:
http://sylow.no-ip.com/pub/apache/jakarta/velocity/tools/EscapeTool.java
The test:
http://sylow.no-ip.com/pub/apache/jakarta/velocity/tools/EscapeToolTest.java
Simple manual
- Putting the tool in the context.
context.put("esc", new EscapeTool());
- Using it.
-- Escaping Java: (Assuming that $java is the Java string.)
$esc.java($java)
-- Escaping JavaScript: (Assuming that $javascript is the JavaScript string.)
$esc.javascript($javascript)
-- Escaping HTML: (Assuming that $html is the HTML string.)
$esc.html($html)
-- Escaping XML: (Assuming that $xml is the XML string.)
$esc.xml($xml)
-- Escaping SQL: (Assuming that $sql is the sqL string.)
$esc.sql($sql)
-- output $
$esc.dollar or $esc.d
-- output #
$esc.sharp or $esc.s
-- output \
$esc.backslash or $esc.b
-- output "
$esc.quote or $esc.q
-- output !
$esc.exclamation or $esc.e
Any comments welcome.
Best regards,
-- Shinobu Kawai
--
Shinobu Kawai <sh...@gmail.com>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org