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"
com.dotcms.rendering.velocity.viewtools.SQLResultsViewTool@11b5fd16 ->; McHale's Navy
com.dotcms.rendering.velocity.viewtools.SQLResultsViewTool@11b5fd16 ->; McHale''s Navy
$ ->; $
$ ->; $
# ->; #
# ->; #
\ ->; \
\ ->; \
" ->; "
" ->; "
' ->; '
' ->; '
! ->; !
! ->; !
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