org.apache.commons.lang

Class StringEscapeUtils


public class StringEscapeUtils
extends Object

Escapes and unescapes Strings for Java, Java Script, HTML, XML, and SQL.
Since:
2.0

Constructor Summary

StringEscapeUtils()
StringEscapeUtils instances should NOT be constructed in standard programming.

Method Summary

static void
escapeCsv(Writer out, String str)
Writes a String value for a CSV column enclosed in double quotes, if required.
static String
escapeCsv(String str)
Returns a String value for a CSV column enclosed in double quotes, if required.
static void
escapeHtml(Writer writer, String string)
Escapes the characters in a String using HTML entities and writes them to a Writer.
static String
escapeHtml(String str)
Escapes the characters in a String using HTML entities.
static void
escapeJava(Writer out, String str)
Escapes the characters in a String using Java String rules to a Writer.
static String
escapeJava(String str)
Escapes the characters in a String using Java String rules.
static void
escapeJavaScript(Writer out, String str)
Escapes the characters in a String using JavaScript String rules to a Writer.
static String
escapeJavaScript(String str)
Escapes the characters in a String using JavaScript String rules.
static String
escapeSql(String str)
Escapes the characters in a String to be suitable to pass to an SQL query.
static void
escapeXml(Writer writer, String str)
Escapes the characters in a String using XML entities.
static String
escapeXml(String str)
Escapes the characters in a String using XML entities.
static void
unescapeCsv(Writer out, String str)
Returns a String value for an unescaped CSV column.
static String
unescapeCsv(String str)
Returns a String value for an unescaped CSV column.
static void
unescapeHtml(Writer writer, String string)
Unescapes a string containing entity escapes to a string containing the actual Unicode characters corresponding to the escapes.
static String
unescapeHtml(String str)
Unescapes a string containing entity escapes to a string containing the actual Unicode characters corresponding to the escapes.
static void
unescapeJava(Writer out, String str)
Unescapes any Java literals found in the String to a Writer.
static String
unescapeJava(String str)
Unescapes any Java literals found in the String.
static void
unescapeJavaScript(Writer out, String str)
Unescapes any JavaScript literals found in the String to a Writer.
static String
unescapeJavaScript(String str)
Unescapes any JavaScript literals found in the String.
static void
unescapeXml(Writer writer, String str)
Unescapes a string containing XML entity escapes to a string containing the actual Unicode characters corresponding to the escapes.
static String
unescapeXml(String str)
Unescapes a string containing XML entity escapes to a string containing the actual Unicode characters corresponding to the escapes.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

StringEscapeUtils

public StringEscapeUtils()
StringEscapeUtils instances should NOT be constructed in standard programming.

Instead, the class should be used as:

StringEscapeUtils.escapeJava("foo");

This constructor is public to permit tools that require a JavaBean instance to operate.

Usages and Demos :

View More Examples of StringEscapeUtils()
   1: 
   2:         context.put("escapeTool", new StringEscapeUtils());
   3:         context.put("util", new Util());
   4:         boolean result = false;

View Full Code Here

Method Details

escapeCsv

public static void escapeCsv(Writer out,
                             String str)
            throws IOException
Writes a String value for a CSV column enclosed in double quotes, if required.

If the value contains a comma, newline or double quote, then the String value is written enclosed in double quotes.

Any double quote characters in the value are escaped with another double quote.

If the value does not contain a comma, newline or double quote, then the String value is written unchanged (null values are ignored). see Wikipedia and RFC 4180.

Parameters:
out - Writer to write input string to, enclosed in double quotes if it contains a comma, newline or double quote
str - the input CSV column String, may be null
Throws:
IOException - if error occurs on underlying Writer
Since:
2.4

escapeCsv

public static String escapeCsv(String str)
Returns a String value for a CSV column enclosed in double quotes, if required.

If the value contains a comma, newline or double quote, then the String value is returned enclosed in double quotes.

Any double quote characters in the value are escaped with another double quote.

If the value does not contain a comma, newline or double quote, then the String value is returned unchanged. see Wikipedia and RFC 4180.

Parameters:
str - the input CSV column String, may be null
Returns:
the input String, enclosed in double quotes if the value contains a comma, newline or double quote, null if null string input
Since:
2.4

escapeHtml

public static void escapeHtml(Writer writer,
                              String string)
            throws IOException
Escapes the characters in a String using HTML entities and writes them to a Writer.

For example: "bread" & "butter"

becomes: "bread" & "butter".

Supports all known HTML 4.0 entities, including funky accents. Note that the commonly used apostrophe escape character (') is not a legal entity and so is not supported).

Parameters:
writer - the writer receiving the escaped string, not null
string - the String to escape, may be null
Throws:
IllegalArgumentException - if the writer is null
IOException - when Writer passed throws the exception from calls to the Writer.write(int) methods.
Usages and Demos :

View More Examples of escapeHtml(Writer writer,String string)
   1: 
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: 
   4:         ...
   5:         try {
   6:             pageContext.getOut().print(StringEscapeUtils.escapeHtml(session.format(key, params)));
   7:         } catch (IOException e) {
   8:             throw new JspException(e);
   9:         }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: 
   4:         ...
   5:         sb.append("<table width=100% align='center'><tr>\r\n").append(
   6:         StringEscapeUtils.escapeHtml(session.format("wamm.showingXResources", param))).append("</tr>\r\n");
   7:         String act = null;
   8:         ...
   9:             sb.append("<tr><td><hr/>").append(
  10:             StringEscapeUtils.escapeHtml(session.format("wamm.pages", new ArrayList()))).append(
  11:             wammActionForm.getIntProperty("page")).append("</td></tr><tr> ").append(
  12:         ...
  13:             sb.append("<tr><td><hr/>").append(
  14:             StringEscapeUtils.escapeHtml(session.format("wamm.pages", new ArrayList()))).append(

View Full Code Here

escapeHtml

public static String escapeHtml(String str)
Escapes the characters in a String using HTML entities.

For example:

"bread" & "butter" becomes:

&quot;bread&quot; &amp; &quot;butter&quot;.

Supports all known HTML 4.0 entities, including funky accents. Note that the commonly used apostrophe escape character (&apos;) is not a legal entity and so is not supported).

Parameters:
str - the String to escape, may be null
Returns:
a new escaped String, null if null string input
Usages and Demos :

View More Examples of escapeHtml(String str)
   1: 
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: 
   4:         ...
   5:     static String getEscapedString(String input) {
   6:         return StringEscapeUtils.escapeHtml(input);
   7:     }
   8:     
   9: }

View Full Code Here
   1: import org.apache.commons.lang.StringEscapeUtils;
   2: 
   3:         ...
   4:         String strHTMLInput = "<p>MyName<p>";
   5:         String strEscapeHTML = StringEscapeUtils.escapeHtml(strHTMLInput);
   6:         ...
   7:         String strUnEscapeHTML = StringEscapeUtils.unescapeHtml(strEscapeHTML);
   8:         System.out.println("Escaped HTML >>> " + strEscapeHTML);

View Full Code Here
   1: 
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: import org.apache.commons.lang.StringUtils;
   4:         ...
   5:     public static String escapeHtmlAndQuotes(String text) {
   6:         return StringUtils.replace(StringEscapeUtils.escapeHtml(text), "'", "&#39;");
   7:     }
   8:         ...
   9:     public static String textEscapeHtml(String text) {
  10:         String escaped = StringEscapeUtils.escapeHtml(text);
  11:         escaped = escaped.replaceAll("\\n", "<BR/>");

View Full Code Here
   1: 
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: 
   4:         ...
   5:                 sb.append("<input type='hidden' name='").append(name).append("' value=\"").append(
   6:                 StringEscapeUtils.escapeHtml(current.toString())).append("\"/>");
   7:         }
   8:     }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: import org.jitterbit.integration.ui.interchange.resources.InterchangeResources;
   4:         ...
   5:     private static String getEscapedString(String s) {
   6:         return StringEscapeUtils.escapeHtml(s);
   7:     }
   8: }

View Full Code Here

escapeJava

public static void escapeJava(Writer out,
                              String str)
            throws IOException
Escapes the characters in a String using Java String rules to a Writer.

A null string input has no effect.

Parameters:
out - Writer to write escaped string into
str - String to escape values in, may be null
Throws:
IllegalArgumentException - if the Writer is null
IOException - if error occurs on underlying Writer

escapeJava

public static String escapeJava(String str)
Escapes the characters in a String using Java String rules.

Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)

So a tab becomes the characters '\\' and 't'.

The only difference between Java strings and JavaScript strings is that in JavaScript, a single quote must be escaped.

Example:

 input string: He didn't say, "Stop!"
 output string: He didn't say, \"Stop!\"
 
Parameters:
str - String to escape values in, may be null
Returns:
String with escaped values, null if null string input
Usages and Demos :

View More Examples of escapeJava(String str)
   1: 
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: import org.apache.commons.lang.StringUtils;
   4:         ...
   5:     public static String format(String key, Object[] params) {
   6:         String result = StringEscapeUtils.escapeJava(key);
   7:         for (int j = 0; j < params.length; j++)
   8:         ...
   9:             params[j] = StringEscapeUtils.escapeJava((String) params[j]);
  10:         for (int i = 0; i < params.length; i++) {
  11:         ...
  12:         }
  13:         return StringEscapeUtils.unescapeJava(result);

View Full Code Here
   1: import org.andromda.translation.ocl.ExpressionKinds;
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: import org.apache.commons.lang.StringUtils;
   4:         ...
   5:         {
   6:             documentation = "An undocumented constraint has been violated: " + StringEscapeUtils.escapeJava(getBody());
   7:         }
   8:         return documentation;
   9:     }

View Full Code Here
   1: import org.apache.commons.lang.ObjectUtils;
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: import org.apache.commons.lang.StringUtils;
   4:         ...
   5:         String returnString = ObjectUtils.toString(rawValue);
   6:         returnString = StringEscapeUtils.escapeJava(StringUtils.trimToEmpty(returnString));
   7:         returnString = StringUtils.replace(StringUtils.trim(returnString), "\\t", "    ");
   8:         ...
   9:         returnString = StringUtils.replace(StringUtils.trim(returnString), "\\r", " ");
  10:         returnString = StringEscapeUtils.unescapeJava(returnString);
  11:         return returnString;

View Full Code Here

escapeJavaScript

public static void escapeJavaScript(Writer out,
                                    String str)
            throws IOException
Escapes the characters in a String using JavaScript String rules to a Writer.

A null string input has no effect.

Parameters:
out - Writer to write escaped string into
str - String to escape values in, may be null
Throws:
IllegalArgumentException - if the Writer is null
IOException - if error occurs on underlying Writer

escapeJavaScript

public static String escapeJavaScript(String str)
Escapes the characters in a String using JavaScript String rules.

Escapes any values it finds into their JavaScript String form. Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)

So a tab becomes the characters '\\' and 't'.

The only difference between Java strings and JavaScript strings is that in JavaScript, a single quote must be escaped.

Example:

 input string: He didn't say, "Stop!"
 output string: He didn\'t say, \"Stop!\"
 
Parameters:
str - String to escape values in, may be null
Returns:
String with escaped values, null if null string input
Usages and Demos :

View More Examples of escapeJavaScript(String str)
   1: import java.util.Map;
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: import org.apache.commons.logging.Log;
   4:         ...
   5:     public String getDescription() {
   6:         return StringEscapeUtils.escapeJavaScript(description);
   7:     }
   8:     
   9:     

View Full Code Here
   1: 
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: import org.apache.commons.logging.Log;
   4:         ...
   5:     public String getDescription() { 
   6:         return StringEscapeUtils.escapeJavaScript(description); 
   7:     }
   8:     
   9:     

View Full Code Here
   1: 
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: import org.openrdf.model.URI;
   4:         ...
   5:     public String escape(String str) {
   6:         return StringEscapeUtils.escapeJavaScript(StringEscapeUtils.escapeXml(str));
   7:     }
   8:         ...
   9:     public String escapeForJavascript(String str) {
  10:         return StringEscapeUtils.escapeJavaScript(str);
  11:     }
  12:         ...
  13:     public String escapeForXML(String str) {
  14:         return StringEscapeUtils.escapeXml(str);

View Full Code Here
   1: 
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: import org.openrdf.model.Literal;
   4:         ...
   5:     public String escape(String str) {
   6:         return StringEscapeUtils.escapeJavaScript(StringEscapeUtils.escapeXml(str));
   7:     }
   8:         ...
   9:     public String escapeForJavascript(String str) {
  10:         return StringEscapeUtils.escapeJavaScript(str);
  11:     }
  12:         ...
  13:     public String escapeForXML(String str) {
  14:         return StringEscapeUtils.escapeXml(str);

View Full Code Here
   1: 
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: import org.apache.commons.lang.StringUtils;
   4:         ...
   5:                 String typeLabel = schemaModel.getLabel(typeURI, "", true);
   6:                 legend.add(new LegendEntry(StringEscapeUtils.escapeXml(markerURL), typeLabel));
   7:             }
   8:         ...
   9: 
  10:                     MapLocation location = new MapLocation(index++, ll.m_latitude, ll.m_longitude, StringEscapeUtils.escapeXml(markerURL));
  11: 
  12:         ...
  13:                             endString,
  14:                             StringEscapeUtils.escapeJavaScript(objectURI),

View Full Code Here

escapeSql

public static String escapeSql(String str)
Escapes the characters in a String to be suitable to pass to an SQL query.

For example,

statement.executeQuery("SELECT * FROM MOVIES WHERE TITLE='" + 
   StringEscapeUtils.escapeSql("McHale's Navy") + 
   "'");

At present, this method only turns single-quotes into doubled single-quotes ("McHale's Navy" => "McHale''s Navy"). It does not handle the cases of percent (%) or underscore (_) for use in LIKE clauses. see http://www.jguru.com/faq/view.jsp?EID=8881

Parameters:
str - the string to escape, may be null
Returns:
a new String, escaped for SQL, null if null string input
Usages and Demos :

View More Examples of escapeSql(String str)
   1: 
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: import org.apache.commons.lang.StringUtils;
   4:         ...
   5:     protected String formatString(Object value) {
   6:         return "'" + StringEscapeUtils.escapeSql((String) value) + "'";
   7:     }
   8: 
   9:     protected Object parseAnyURI(String valueAsString) {

View Full Code Here
   1: 
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: import org.apache.commons.lang.StringUtils;
   4:         ...
   5:     protected String formatString(Object value) {
   6:         return "'" + StringEscapeUtils.escapeSql((String) value) + "'";
   7:     }
   8: 
   9:     protected Object parseAnyURI(String valueAsString) {

View Full Code Here
   1: import org.andromda.core.common.ExceptionUtils;
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: import org.apache.commons.lang.StringUtils;
   4:         ...
   5:         }
   6:         return StringEscapeUtils.escapeSql(sqlName.toString());
   7:     }
   8: 
   9:     public static String getSqlNameFromTaggedValue(

View Full Code Here
   1: 
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: 
   4:         ...
   5:         sqlMapping.getSQLPropertyMapping(prop).getTable().getColumn(1).getName()).append(") values ('").append(
   6:         resource.getOID()).append("', '").append(StringEscapeUtils.escapeSql(value)).append("')");
   7:         stmts.add(insert.toString());
   8:         ...
   9:                     .append(") values ('").append(resource.getOID()).append("', '").append(
  10:                     StringEscapeUtils.escapeSql(value)).append("') update duplicates");
  11:                 } else {
  12:         ...
  13:                     .append(" set ").append(sqlMapping.getSQLPropertyMapping(prop).getTable().getColumn(1).getName())
  14:                     .append("='").append(StringEscapeUtils.escapeSql(value)).append("' where ").append(

View Full Code Here

escapeXml

public static void escapeXml(Writer writer,
                             String str)
            throws IOException
Escapes the characters in a String using XML entities.

For example: "bread" & "butter" => &quot;bread&quot; &amp; &quot;butter&quot;.

Supports only the five basic XML entities (gt, lt, quot, amp, apos). Does not support DTDs or external entities.

Note that unicode characters greater than 0x7f are currently escaped to their numerical \\u equivalent. This may change in future releases.

Parameters:
writer - the writer receiving the unescaped string, not null
str - the String to escape, may be null
Throws:
IllegalArgumentException - if the writer is null
IOException - if there is a problem writing

escapeXml

public static String escapeXml(String str)
Escapes the characters in a String using XML entities.

For example: "bread" & "butter" => &quot;bread&quot; &amp; &quot;butter&quot;.

Supports only the five basic XML entities (gt, lt, quot, amp, apos). Does not support DTDs or external entities.

Note that unicode characters greater than 0x7f are currently escaped to their numerical \\u equivalent. This may change in future releases.

Parameters:
str - the String to escape, may be null
Returns:
a new escaped String, null if null string input
Usages and Demos :

View More Examples of escapeXml(String str)
   1: 
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: import org.jdom.Text;
   4:         ...
   5: 
   6:         return StringEscapeUtils.escapeXml( result );
   7:     }
   8:     
   9:     public String getText()

View Full Code Here
   1: 
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: import org.displaytag.model.TableModel;
   4:         ...
   5:         {
   6:             return StringEscapeUtils.escapeXml(value.toString());
   7:         }
   8:         return null;
   9:     }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: import org.openrdf.model.URI;
   4:         ...
   5:     public String escape(String str) {
   6:         return StringEscapeUtils.escapeJavaScript(StringEscapeUtils.escapeXml(str));
   7:     }
   8:         ...
   9:     public String escapeForJavascript(String str) {
  10:         return StringEscapeUtils.escapeJavaScript(str);
  11:     }
  12:         ...
  13:     public String escapeForXML(String str) {
  14:         return StringEscapeUtils.escapeXml(str);

View Full Code Here
   1: 
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: import org.openrdf.model.Literal;
   4:         ...
   5:     public String escape(String str) {
   6:         return StringEscapeUtils.escapeJavaScript(StringEscapeUtils.escapeXml(str));
   7:     }
   8:         ...
   9:     public String escapeForJavascript(String str) {
  10:         return StringEscapeUtils.escapeJavaScript(str);
  11:     }
  12:         ...
  13:     public String escapeForXML(String str) {
  14:         return StringEscapeUtils.escapeXml(str);

View Full Code Here
   1: 
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: 
   4:         ...
   5:     public static String escapeForHTMLJavascript(String s) {
   6:         return escapeForHTML(StringEscapeUtils.escapeJavaScript(s));
   7:     }
   8:         ...
   9:     public static String escapeForMarkupAttribute(String s) {
  10:         return StringEscapeUtils.escapeXml(s);
  11:     }
  12:         ...
  13:         while((line=reader.readLine()) != null){
  14:             out.println(StringEscapeUtils.escapeHtml(line));

View Full Code Here

unescapeCsv

public static void unescapeCsv(Writer out,
                               String str)
            throws IOException
Returns a String value for an unescaped CSV column.

If the value is enclosed in double quotes, and contains a comma, newline or double quote, then quotes are removed.

Any double quote escaped characters (a pair of double quotes) are unescaped to just one double quote.

If the value is not enclosed in double quotes, or is and does not contain a comma, newline or double quote, then the String value is returned unchanged. see Wikipedia and RFC 4180.

Parameters:
out - Writer to write the input String to, with enclosing double quotes removed and embedded double quotes unescaped, null if null string input
str - the input CSV column String, may be null
Throws:
IOException - if error occurs on underlying Writer
Since:
2.4

unescapeCsv

public static String unescapeCsv(String str)
Returns a String value for an unescaped CSV column.

If the value is enclosed in double quotes, and contains a comma, newline or double quote, then quotes are removed.

Any double quote escaped characters (a pair of double quotes) are unescaped to just one double quote.

If the value is not enclosed in double quotes, or is and does not contain a comma, newline or double quote, then the String value is returned unchanged. see Wikipedia and RFC 4180.

Parameters:
str - the input CSV column String, may be null
Returns:
the input String, with enclosing double quotes removed and embedded double quotes unescaped, null if null string input
Since:
2.4

unescapeHtml

public static void unescapeHtml(Writer writer,
                                String string)
            throws IOException
Unescapes a string containing entity escapes to a string containing the actual Unicode characters corresponding to the escapes. Supports HTML 4.0 entities.

For example, the string "&lt;Fran&ccedil;ais&gt;" will become "<Français>"

If an entity is unrecognized, it is left alone, and inserted verbatim into the result string. e.g. "&gt;&zzzz;x" will become ">&zzzz;x".

Parameters:
writer - the writer receiving the unescaped string, not null
string - the String to unescape, may be null
Throws:
IllegalArgumentException - if the writer is null
IOException - if an IOException occurs

unescapeHtml

public static String unescapeHtml(String str)
Unescapes a string containing entity escapes to a string containing the actual Unicode characters corresponding to the escapes. Supports HTML 4.0 entities.

For example, the string "&lt;Fran&ccedil;ais&gt;" will become "<Français>"

If an entity is unrecognized, it is left alone, and inserted verbatim into the result string. e.g. "&gt;&zzzz;x" will become ">&zzzz;x".

Parameters:
str - the String to unescape, may be null
Returns:
a new unescaped String, null if null string input
Usages and Demos :

View More Examples of unescapeHtml(String str)
   1: import org.apache.commons.lang.StringEscapeUtils;
   2: 
   3:         ...
   4:         String strHTMLInput = "<p>MyName<p>";
   5:         String strEscapeHTML = StringEscapeUtils.escapeHtml(strHTMLInput);
   6:         ...
   7:         String strUnEscapeHTML = StringEscapeUtils.unescapeHtml(strEscapeHTML);
   8:         System.out.println("Escaped HTML >>> " + strEscapeHTML);

View Full Code Here
   1: 
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: 
   4:         ...
   5:             MessageTag tag = (MessageTag) getParent();
   6:             tag.addParameter(StringEscapeUtils.unescapeHtml(getBodyContent().getString()));
   7:         } catch (ClassCastException e) {
   8:             throw new JspException("<param> should only be used inside <message>");
   9:         }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: import org.apache.tools.ant.filters.BaseParamFilterReader;
   4:         ...
   5:         if(ESCAPE.equalsIgnoreCase(mode)){
   6:             return StringEscapeUtils.escapeHtml(queuedData2);
   7:         } else {
   8:         ...
   9:             return  StringEscapeUtils.unescapeHtml(queuedData2);
  10:         }

View Full Code Here
   1: 
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: 
   4:         ...
   5:            String query = uri.getQuery();
   6:            query = StringEscapeUtils.unescapeHtml(query);
   7:            if(query!=null && query!=""){
   8:            List tokens = Arrays.asList(query.split("&"));
   9:            Iterator itTokens = tokens.iterator();

View Full Code Here
   1: 
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: 
   4:         ...
   5:     public static String escapeForHTMLJavascript(String s) {
   6:         return escapeForHTML(StringEscapeUtils.escapeJavaScript(s));
   7:     }
   8:         ...
   9:     public static String escapeForMarkupAttribute(String s) {
  10:         return StringEscapeUtils.escapeXml(s);
  11:     }
  12:         ...
  13:         return (startEntityCode != 0 && endEntityCode != 0)?
  14:             StringEscapeUtils.unescapeHtml(cs.toString()): cs;

View Full Code Here

unescapeJava

public static void unescapeJava(Writer out,
                                String str)
            throws IOException
Unescapes any Java literals found in the String to a Writer.

For example, it will turn a sequence of '\' and 'n' into a newline character, unless the '\' is preceded by another '\'.

A null string input has no effect.

Parameters:
out - the Writer used to output unescaped characters
str - the String to unescape, may be null
Throws:
IllegalArgumentException - if the Writer is null
IOException - if error occurs on underlying Writer

unescapeJava

public static String unescapeJava(String str)
Unescapes any Java literals found in the String. For example, it will turn a sequence of '\' and 'n' into a newline character, unless the '\' is preceded by another '\'.
Parameters:
str - the String to unescape, may be null
Returns:
a new unescaped String, null if null string input
Usages and Demos :

View More Examples of unescapeJava(String str)
   1: 
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: import org.apache.commons.lang.StringUtils;
   4:         ...
   5:     public static String format(String key, Object[] params) {
   6:         String result = StringEscapeUtils.escapeJava(key);
   7:         for (int j = 0; j < params.length; j++)
   8:         ...
   9:             params[j] = StringEscapeUtils.escapeJava((String) params[j]);
  10:         for (int i = 0; i < params.length; i++) {
  11:         ...
  12:         }
  13:         return StringEscapeUtils.unescapeJava(result);

View Full Code Here
   1: import org.apache.commons.lang.ObjectUtils;
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: import org.apache.commons.lang.StringUtils;
   4:         ...
   5:         String returnString = ObjectUtils.toString(rawValue);
   6:         returnString = StringEscapeUtils.escapeJava(StringUtils.trimToEmpty(returnString));
   7:         returnString = StringUtils.replace(StringUtils.trim(returnString), "\\t", "    ");
   8:         ...
   9:         returnString = StringUtils.replace(StringUtils.trim(returnString), "\\r", " ");
  10:         returnString = StringEscapeUtils.unescapeJava(returnString);
  11:         return returnString;

View Full Code Here
   1: import org.apache.commons.lang.ArrayUtils;
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: import org.apache.commons.lang.StringUtils;
   4:         ...
   5:             String[] property = parseProperty(line);
   6:             propertyName = StringEscapeUtils.unescapeJava(property[0]);
   7:             propertyValue = unescapeJava(property[1], delimiter);
   8:         ...
   9:         {
  10:             String escapedValue = StringEscapeUtils.escapeJava(String.valueOf(value));
  11:             if (delimiter != 0)

View Full Code Here

unescapeJavaScript

public static void unescapeJavaScript(Writer out,
                                      String str)
            throws IOException
Unescapes any JavaScript literals found in the String to a Writer.

For example, it will turn a sequence of '\' and 'n' into a newline character, unless the '\' is preceded by another '\'.

A null string input has no effect.

Parameters:
out - the Writer used to output unescaped characters
str - the String to unescape, may be null
Throws:
IllegalArgumentException - if the Writer is null
IOException - if error occurs on underlying Writer

unescapeJavaScript

public static String unescapeJavaScript(String str)
Unescapes any JavaScript literals found in the String.

For example, it will turn a sequence of '\' and 'n' into a newline character, unless the '\' is preceded by another '\'.

Parameters:
str - the String to unescape, may be null
Returns:
A new unescaped String, null if null string input

unescapeXml

public static void unescapeXml(Writer writer,
                               String str)
            throws IOException
Unescapes a string containing XML entity escapes to a string containing the actual Unicode characters corresponding to the escapes.

Supports only the five basic XML entities (gt, lt, quot, amp, apos). Does not support DTDs or external entities.

Note that numerical \\u unicode codes are unescaped to their respective unicode characters. This may change in future releases.

Parameters:
writer - the writer receiving the unescaped string, not null
str - the String to unescape, may be null
Throws:
IllegalArgumentException - if the writer is null
IOException - if there is a problem writing

unescapeXml

public static String unescapeXml(String str)
Unescapes a string containing XML entity escapes to a string containing the actual Unicode characters corresponding to the escapes.

Supports only the five basic XML entities (gt, lt, quot, amp, apos). Does not support DTDs or external entities.

Note that numerical \\u unicode codes are unescaped to their respective unicode characters. This may change in future releases.

Parameters:
str - the String to unescape, may be null
Returns:
a new unescaped String, null if null string input
Usages and Demos :

View More Examples of unescapeXml(String str)
   1: 
   2: import org.apache.commons.lang.StringEscapeUtils;
   3: import org.jitterbit.ui.IUiDecor;
   4:         ...
   5:                 pane.append(attribute.getFirst(), Colors.ATTRIBUTE);
   6:                 pane.append(StringEscapeUtils.escapeXml(attribute.getSecond()), 
   7:                                 Colors.TEXT);
   8:         ...
   9:             if (hasValue()) {
  10:                 pane.append(StringEscapeUtils.unescapeXml(m_value), Colors.TEXT);
  11:             }

View Full Code Here