|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.velocity.tools.generic.EscapeTool
public class EscapeTool
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 $url -> hello here & there $esc.url -> 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).
StringEscapeUtils
Constructor Summary | |
---|---|
EscapeTool()
Default constructor. |
Method Summary | |
---|---|
protected java.lang.String |
dumpString(java.lang.String string,
boolean key)
This code was pulled from the Apache Harmony project. |
java.lang.String |
getB()
Renders a backslash (\). |
java.lang.String |
getBackslash()
Renders a backslash (\). |
java.lang.String |
getD()
Renders a dollar sign ($). |
java.lang.String |
getDollar()
Renders a dollar sign ($). |
java.lang.String |
getE()
Renders an exclamation mark (!). |
java.lang.String |
getExclamation()
Renders an exclamation mark (!). |
java.lang.String |
getH()
Renders a hash (#). |
java.lang.String |
getHash()
Renders a hash (#). |
java.lang.String |
getQ()
Renders a double quotation mark ("). |
java.lang.String |
getQuote()
Renders a double quotation mark ("). |
java.lang.String |
getS()
Renders a single quotation mark ('). |
java.lang.String |
getSingleQuote()
Renders a single quotation mark ('). |
java.lang.String |
html(java.lang.Object string)
Escapes the characters in a String using HTML entities. |
java.lang.String |
java(java.lang.Object string)
Escapes the characters in a String using Java String rules. |
java.lang.String |
javascript(java.lang.Object string)
Escapes the characters in a String using JavaScript String rules. |
java.lang.String |
propertyKey(java.lang.Object string)
Escapes the characters in a String using java.util.Properties rules for escaping property keys. |
java.lang.String |
propertyValue(java.lang.Object string)
Escapes the characters in a String using java.util.Properties rules for escaping property values. |
java.lang.String |
sql(java.lang.Object string)
Escapes the characters in a String to be suitable to pass to an SQL query. |
java.lang.String |
url(java.lang.Object string)
Escape the characters in a String to be suitable to use as an HTTP parameter value. |
java.lang.String |
xml(java.lang.Object string)
Escapes the characters in a String using XML entities. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public EscapeTool()
Method Detail |
---|
public java.lang.String java(java.lang.Object string)
String
using Java String rules.
StringEscapeUtils.escapeJava(String)
.
string
- the string to escape values, may be null
null
if null string inputStringEscapeUtils.escapeJava(String)
public java.lang.String propertyKey(java.lang.Object string)
String
using java.util.Properties rules for escaping property keys.
string
- the string to escape values, may be null
null
if null string inputdumpString(String, boolean)
public java.lang.String propertyValue(java.lang.Object string)
String
using java.util.Properties rules for escaping property values.
string
- the string to escape values, may be null
null
if null string inputdumpString(String, boolean)
protected java.lang.String dumpString(java.lang.String string, boolean key)
public java.lang.String javascript(java.lang.Object string)
String
using JavaScript String rules.
StringEscapeUtils.escapeJavaScript(String)
.
string
- the string to escape values, may be null
null
if null string inputStringEscapeUtils.escapeJavaScript(String)
public java.lang.String html(java.lang.Object string)
String
using HTML entities.
StringEscapeUtils.escapeHtml(String)
.
string
- the string to escape, may be null
String
, null
if null string inputStringEscapeUtils.escapeHtml(String)
public java.lang.String url(java.lang.Object string)
String
to be suitable to use as an HTTP parameter value.
string
- the string to escape, may be null
String
, null
if null string input
See java.net.URLEncoder#encode(String,String).public java.lang.String xml(java.lang.Object string)
String
using XML entities.
StringEscapeUtils.escapeXml(String)
.
string
- the string to escape, may be null
String
, null
if null string inputStringEscapeUtils.escapeXml(String)
public java.lang.String sql(java.lang.Object string)
String
to be suitable to pass to an SQL query.
StringEscapeUtils.escapeSql(String)
.
string
- the string to escape, may be null
null
if null string inputStringEscapeUtils.escapeSql(String)
public java.lang.String getDollar()
getD()
public java.lang.String getD()
getDollar()
public java.lang.String getHash()
getH()
public java.lang.String getH()
getHash()
public java.lang.String getBackslash()
getB()
public java.lang.String getB()
getBackslash()
public java.lang.String getQuote()
getQ()
public java.lang.String getQ()
getQuote()
public java.lang.String getSingleQuote()
getS()
public java.lang.String getS()
getSingleQuote()
public java.lang.String getExclamation()
getE()
public java.lang.String getE()
getExclamation()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |