| java.lang.Object org.apache.velocity.tools.generic.EscapeTool
EscapeTool | public class EscapeTool (Code) | | Tool for working with escaping in Velocity templates.
It provides methods to escape outputs for Java, JavaScript, HTML, HTTP, 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
$http -> hello here & there
$esc.http -> hello+here+%26+there
$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).
author: Shinobu Kawai version: $Id: $ since: VelocityTools 1.2 See Also: StringEscapeUtils |
Constructor Summary | |
public | EscapeTool() Default constructor. |
EscapeTool | public EscapeTool()(Code) | | Default constructor.
|
html | public String html(Object string)(Code) | | Escapes the characters in a String using HTML entities.
Delegates the process to
StringEscapeUtils.escapeHtml(String) .
Parameters: string - the string to escape, may be null a new escaped String , null if null string input See Also: StringEscapeUtils.escapeHtml(String) |
java | public String java(Object string)(Code) | | Escapes the characters in a String using Java String rules.
Delegates the process to
StringEscapeUtils.escapeJava(String) .
Parameters: string - the string to escape values, may be null String with escaped values, null if null string input See Also: StringEscapeUtils.escapeJava(String) |
javascript | public String javascript(Object string)(Code) | | Escapes the characters in a String using JavaScript String rules.
Delegates the process to
StringEscapeUtils.escapeJavaScript(String) .
Parameters: string - the string to escape values, may be null String with escaped values, null if null string input See Also: StringEscapeUtils.escapeJavaScript(String) |
sql | public String sql(Object string)(Code) | | Escapes the characters in a String to be suitable to pass to an SQL query.
Delegates the process to
StringEscapeUtils.escapeSql(String) .
Parameters: string - the string to escape, may be null a new String, escaped for SQL, null if null string input See Also: StringEscapeUtils.escapeSql(String) |
url | public String url(Object string)(Code) | | Escape the characters in a String to be suitable to use as an HTTP parameter value.
Uses UTF-8 as default character encoding.
Parameters: string - the string to escape, may be null a new escaped String , null if null string inputSee java.net.URLEncoder#encode(String,String). since: VelocityTools 1.3 |
xml | public String xml(Object string)(Code) | | Escapes the characters in a String using XML entities.
Delegates the process to
StringEscapeUtils.escapeXml(String) .
Parameters: string - the string to escape, may be null a new escaped String , null if null string input See Also: StringEscapeUtils.escapeXml(String) |
|
|