EscapeTool Class

Last Updated: May 3, 2021
documentation for the dotCMS Content Management System

org.apache.velocity.tools.generic
Class EscapeTool

java.lang.Object

extended by

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@5a4f04f5 ->; McHale's Navy
com.dotcms.rendering.velocity.viewtools.SQLResultsViewTool@5a4f04f5 ->; 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

On this page

×

We Dig Feedback

Selected excerpt:

×