org.apache.velocity.tools.generic
Class EscapeTool
java.lang.Object

org.apache.velocity.tools.generic.EscapeTool
- public class EscapeTool
- extends java.lang.Object
Tool for working with escaping in Velocity templates. It provides methods to escape outputs for Java, JavaScript, HTML, XML and SQL. Also provides methods to render VTL characters that otherwise needs escaping.
Example uses:
$java -> He didn't say, "Stop!"
$esc.java($java) -> He didn't say, \"Stop!\"
$javascript -> He didn't say, "Stop!"
$esc.javascript($javascript) -> He didn\'t say, \"Stop!\"
$html -> "bread" & "butter"
$esc.html($html) -> "bread" & "butter"
$xml -> "bread" & "butter"
$esc.xml($xml) -> "bread" & "butter"
$sql -> McHale's Navy
$esc.sql($sql) -> McHale''s Navy
$esc.dollar -> $
$esc.d -> $
$esc.hash -> #
$esc.h -> #
$esc.backslash -> \
$esc.b -> \
$esc.quote -> "
$esc.q -> "
$esc.singleQuote -> '
$esc.s -> '
$esc.exclamation -> !
$esc.e -> !
Example toolbox.xml config (if you want to use this with VelocityView):
<tool>
<key>esc</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.EscapeTool</class>
</tool>
This tool is entirely threadsafe, and has no instance members. It may be used in any scope (request, session, or application).
- Since:
- VelocityTools 1.2
- Version:
- $Id: $
- Author:
- Shinobu Kawai
- See Also:
StringEscapeUtils
For complete documentation on this viewtool use the following link: EscapeTool
2