Velocity Tools
Generic Tools
Tool Documentation
Other Subprojects
|
EscapeTool Reference Documentation
|
|
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.
Class |
| org.apache.velocity.tools.generic.EscapeTool |
Name |
| $esc (this is the recommended name of the tool in
the Velocity context) |
Toolbox Configuration Example |
| <tool>
<key>esc</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.EscapeTool</class>
</tool> |
Author(s) |
| Shinobu Kawai
|
- Method Overview
-
java() |
Escapes the characters in a String using Java String rules.
|
javascript() |
Escapes the characters in a String using JavaScript String rules.
|
html() |
Escapes the characters in a String using HTML entities.
|
xml() |
Escapes the characters in a String using XML entities.
|
sql() |
Escapes the characters in a String to be suitable to pass to an SQL query.
|
getDollar() |
Renders a dollar sign ($).
|
getD() |
Renders a dollar sign ($).
|
getHash() |
Renders a hash (#).
|
getH() |
Renders a hash (#).
|
getBackslash() |
Renders a backslash (\).
|
getB() |
Renders a backslash (\).
|
getQuote() |
Renders a double quotation mark (").
|
getQ() |
Renders a double quotation mark (").
|
getSingleQuote() |
Renders a single quotation mark (').
|
getS() |
Renders a single quotation mark (').
|
getExclamation() |
Renders an exclamation mark (!).
|
getE() |
Renders an exclamation mark (!).
|
|
java()
|
|
Escapes the characters in a String using Java String rules.
String java(Object string)
|
- Parameters
-
- string
-
the string to escape values, may be null.
- Returns
-
String with escaped values,
null if null string input.
Delegates the process to
StringEscapeUtils#escapeJava(String).
If $java had the following value:
then the following Velocity script:
produces this output:
|
javascript()
|
|
Escapes the characters in a String using JavaScript String rules.
String javascript(Object string)
|
- Parameters
-
- string
-
the string to escape values, may be null.
- Returns
-
String with escaped values,
null if null string input.
Delegates the process to
StringEscapeUtils#escapeJavaScript(String).
If $javascript had the following value:
then the following Velocity script:
$esc.javascript($javascript)
|
|
produces this output:
He didn\'t say, \"Stop!\"
|
|
|
html()
|
|
Escapes the characters in a String using HTML entities.
String html(Object string)
|
- Parameters
-
- string
-
the string to escape values, may be null.
- Returns
-
a new escaped
String , null if null string input
Delegates the process to
StringEscapeUtils#escapeHtml(String).
If $html had the following value:
then the following Velocity script:
produces this output:
"bread" & "butter"
|
|
|
xml()
|
|
Escapes the characters in a String using XML entities.
String xml(Object string)
|
- Parameters
-
- string
-
the string to escape values, may be null.
- Returns
-
a new escaped
String , null if null string input
Delegates the process to
StringEscapeUtils#escapeXml(String).
If $xml had the following value:
then the following Velocity script:
produces this output:
"bread" & "butter"
|
|
|
sql()
|
|
Escapes the characters in a String to be suitable to pass to an SQL query.
String sql(Object string)
|
- Parameters
-
- string
-
the string to escape values, may be null.
- Returns
-
a new String, escaped for SQL,
null if null string input
Delegates the process to
StringEscapeUtils#escapeSql(String).
If $sql had the following value:
then the following Velocity script:
produces this output:
|
getDollar()
|
|
Renders a dollar sign ($).
- Returns
-
a dollar sign ($).
The following Velocity script:
produces this output:
|
getD()
|
|
Renders a dollar sign ($).
- Returns
-
a dollar sign ($).
The following Velocity script:
produces this output:
|
getHash()
|
|
Renders a hash (#).
- Returns
-
a hash (#).
The following Velocity script:
produces this output:
|
getH()
|
|
Renders a hash (#).
- Returns
-
a hash (#).
The following Velocity script:
produces this output:
|
getBackslash()
|
|
Renders a backslash (\).
- Returns
-
a backslash (\).
The following Velocity script:
produces this output:
|
getB()
|
|
Renders a backslash (\).
- Returns
-
a backslash (\).
The following Velocity script:
produces this output:
|
getQuote()
|
|
Renders a double quotation mark (").
- Returns
-
a double quotation mark (").
The following Velocity script:
produces this output:
|
getQ()
|
|
Renders a double quotation mark (").
- Returns
-
a double quotation mark (").
The following Velocity script:
produces this output:
|
getSingleQuote()
|
|
Renders a single quotation mark (').
- Returns
-
a single quotation mark (').
The following Velocity script:
produces this output:
|
getS()
|
|
Renders a single quotation mark (').
- Returns
-
a single quotation mark (').
The following Velocity script:
produces this output:
|
getExclamation()
|
|
Renders an exclamation mark (!).
- Returns
-
an exclamation mark (!).
The following Velocity script:
produces this output:
|
getE()
|
|
Renders an exclamation mark (!).
- Returns
-
an exclamation mark (!).
The following Velocity script:
produces this output:
|
|