|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectubiware.core.visualizer.StringEscapingUtils
public final class StringEscapingUtils
Convenience methods for escaping special characters related to HTML, XML, and regular expressions.
Taken from http://www.javapractices.com/topic/TopicAction.do?Id=96
To keep you safe by default, WEB4J goes to some effort to escape characters in your data when appropriate, such that you usually don't need to think too much about escaping special characters. Thus, you shouldn't need to directly use the services of this class very often.
For Model Objects containing free form user input, it is highly recommended that you use SafeText, not
String. Free form user input is open to malicious use, such as Cross Site Scripting attacks. Using SafeText will protect you
from such attacks, by always escaping special characters automatically in its toString() method.
The following WEB4J classes will automatically escape special characters for you, when needed :
SafeText class, used as a building block class for your application's Model Objects, for modeling all free form user
input
Populate tag used with forms
Report class used for creating quick reports
Text, TextFlow, and Tooltips custom tags used for translation
| Method Summary | |
|---|---|
static java.lang.String |
forHTML(java.lang.String aText)
Escape characters for text appearing in HTML markup. |
static java.lang.String |
forRegex(java.lang.String aRegexFragment)
Replace characters having special meaning in regular expressions with their escaped equivalents, preceded by a '\' character. |
static java.lang.String |
forScriptTagsOnly(java.lang.String aText)
Disable all tags in aText. |
static java.lang.String |
forURL(java.lang.String aURLFragment)
Synonym for URLEncoder.encode(String, "UTF-8"). |
static java.lang.String |
forXML(java.lang.String aText)
Escape characters for text appearing as XML data, between tags. |
static java.lang.String |
toDisableTags(java.lang.String aText)
Return aText with all '<' and '>' characters replaced by their escaped equivalents. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static java.lang.String forHTML(java.lang.String aText)
This method exists as a defence against Cross Site Scripting (XSS) hacks. This method escapes all characters recommended by the Open Web App Security Project - link.
The following characters are replaced with corresponding HTML character entities :
| Character | Encoding |
|---|---|
| < | < |
| > | > |
| & | & |
| " | " |
| ' | ' |
| ( | ( |
| ) | ) |
| # | # |
| % | % |
| ; | ; |
| + | + |
| - | - |
Note that JSTL's <c:out> escapes only the first
five of the above characters.
public static java.lang.String forURL(java.lang.String aURLFragment)
Used to ensure that HTTP query strings are in proper form, by escaping special characters such as spaces.
It is important to note that if a query string appears in an HREF attribute, then there are two issues - ensuring the query string is valid HTTP (it is URL-encoded), and ensuring it is valid HTML (ensuring the ampersand is escaped).
public static java.lang.String forXML(java.lang.String aText)
The following characters are replaced with corresponding character entities :
| Character | Encoding |
|---|---|
| < | < |
| > | > |
| & | & |
| " | " |
| ' | ' |
Note that JSTL's <c:out> escapes the exact same set of characters as this method. That is,
<c:out> is good for escaping to produce valid XML, but not for producing safe HTML.
public static java.lang.String toDisableTags(java.lang.String aText)
public static java.lang.String forRegex(java.lang.String aRegexFragment)
The escaped characters include :
public static java.lang.String forScriptTagsOnly(java.lang.String aText)
Insensitive to case.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||