diff --git a/src/java/org/apache/commons/lang/StringEscapeUtils.java b/src/java/org/apache/commons/lang/StringEscapeUtils.java index 328a39ab8..2f49dd2d6 100644 --- a/src/java/org/apache/commons/lang/StringEscapeUtils.java +++ b/src/java/org/apache/commons/lang/StringEscapeUtils.java @@ -78,7 +78,7 @@ public class StringEscapeUtils { * @return String with escaped values, null if null string input */ public static String escapeJava(String str) { - return EscapeUtils.ESCAPE_JAVA.translate(str); + return EscapeUtils.escapeJava(str); } /** @@ -119,7 +119,7 @@ public class StringEscapeUtils { * @return String with escaped values, null if null string input */ public static String escapeJavaScript(String str) { - return EscapeUtils.ESCAPE_ECMASCRIPT.translate(str); + return EscapeUtils.escapeEcmaScript(str); } /** @@ -148,7 +148,7 @@ public class StringEscapeUtils { * @return a new unescaped String, null if null string input */ public static String unescapeJava(String str) { - return UnescapeUtils.UNESCAPE_JAVA.translate(str); + return UnescapeUtils.unescapeJava(str); } /** @@ -182,7 +182,7 @@ public class StringEscapeUtils { * @return A new unescaped String, null if null string input */ public static String unescapeJavaScript(String str) { - return UnescapeUtils.UNESCAPE_ECMASCRIPT.translate(str); + return UnescapeUtils.unescapeEcmaScript(str); } /** @@ -234,7 +234,7 @@ public class StringEscapeUtils { * @see HTML 4.01 Code positions */ public static String escapeHtml(String str) { - return EscapeUtils.ESCAPE_HTML4.translate(str); + return EscapeUtils.escapeHtml4(str); } /** @@ -288,7 +288,7 @@ public class StringEscapeUtils { * @see #escapeHtml(Writer, String) */ public static String unescapeHtml(String str) { - return UnescapeUtils.UNESCAPE_HTML4.translate(str); + return UnescapeUtils.unescapeHtml4(str); } /** @@ -355,7 +355,7 @@ public class StringEscapeUtils { * @see #unescapeXml(java.lang.String) */ public static String escapeXml(String str) { - return EscapeUtils.ESCAPE_XML.translate(str); + return EscapeUtils.escapeXml(str); } //----------------------------------------------------------------------- @@ -396,7 +396,7 @@ public class StringEscapeUtils { * @see #escapeXml(String) */ public static String unescapeXml(String str) { - return UnescapeUtils.UNESCAPE_XML.translate(str); + return UnescapeUtils.unescapeXml(str); } //----------------------------------------------------------------------- @@ -424,7 +424,7 @@ public class StringEscapeUtils { * @since 2.4 */ public static String escapeCsv(String str) { - return EscapeUtils.ESCAPE_CSV.translate(str); + return EscapeUtils.escapeCsv(str); } /** @@ -477,7 +477,7 @@ public class StringEscapeUtils { * @since 2.4 */ public static String unescapeCsv(String str) { - return UnescapeUtils.UNESCAPE_CSV.translate(str); + return UnescapeUtils.unescapeCsv(str); } /** diff --git a/src/java/org/apache/commons/lang/text/translate/EscapeUtils.java b/src/java/org/apache/commons/lang/text/translate/EscapeUtils.java index 0d17da359..17f789482 100644 --- a/src/java/org/apache/commons/lang/text/translate/EscapeUtils.java +++ b/src/java/org/apache/commons/lang/text/translate/EscapeUtils.java @@ -39,6 +39,10 @@ public class EscapeUtils { new EscapeLowAsciiAsUnicode(), new EscapeNonAsciiAsUnicode() ); + + public static final String escapeJava(String input) { + return ESCAPE_JAVA.translate(input); + } public static final CharSequenceTranslator ESCAPE_ECMASCRIPT = new AggregateTranslator( @@ -53,6 +57,10 @@ public class EscapeUtils { new EscapeNonAsciiAsUnicode() ); + public static final String escapeEcmaScript(String input) { + return ESCAPE_ECMASCRIPT.translate(input); + } + public static final CharSequenceTranslator ESCAPE_XML = new AggregateTranslator( new LookupTranslator(EntityArrays.BASIC_ESCAPE), @@ -60,6 +68,10 @@ public class EscapeUtils { new EscapeNonAsciiAsNumericEntity() ); + public static final String escapeXml(String input) { + return ESCAPE_XML.translate(input); + } + public static final CharSequenceTranslator ESCAPE_HTML3 = new AggregateTranslator( new LookupTranslator(EntityArrays.BASIC_ESCAPE), @@ -67,6 +79,10 @@ public class EscapeUtils { new EscapeNonAsciiAsNumericEntity() ); + public static final String escapeHtml3(String input) { + return ESCAPE_HTML3.translate(input); + } + public static final CharSequenceTranslator ESCAPE_HTML4 = new AggregateTranslator( new LookupTranslator(EntityArrays.BASIC_ESCAPE), @@ -75,8 +91,16 @@ public class EscapeUtils { new EscapeNonAsciiAsNumericEntity() ); + public static final String escapeHtml4(String input) { + return ESCAPE_HTML4.translate(input); + } + public static final CharSequenceTranslator ESCAPE_CSV = new CsvEscaper(); + public static final String escapeCsv(String input) { + return ESCAPE_CSV.translate(input); + } + // TODO: Create a parent class - 'SinglePassTranslator' ? // TODO: It would handle the index checking, and length returning, and // TODO: could also have an optimization check method. diff --git a/src/java/org/apache/commons/lang/text/translate/UnescapeUtils.java b/src/java/org/apache/commons/lang/text/translate/UnescapeUtils.java index 3931853db..fcfb95ffb 100644 --- a/src/java/org/apache/commons/lang/text/translate/UnescapeUtils.java +++ b/src/java/org/apache/commons/lang/text/translate/UnescapeUtils.java @@ -47,8 +47,27 @@ public class UnescapeUtils { }) ); + public static final String unescapeJava(String input) { + return UNESCAPE_JAVA.translate(input); + } + public static final CharSequenceTranslator UNESCAPE_ECMASCRIPT = UNESCAPE_JAVA; + public static final String unescapeEcmaScript(String input) { + return UNESCAPE_ECMASCRIPT.translate(input); + } + + public static final CharSequenceTranslator UNESCAPE_HTML3 = + new AggregateTranslator( + new LookupTranslator(EntityArrays.BASIC_UNESCAPE), + new LookupTranslator(EntityArrays.ISO8859_1_UNESCAPE), + new NumericEntityUnescaper() + ); + + public static final String unescapeHtml3(String input) { + return UNESCAPE_HTML3.translate(input); + } + public static final CharSequenceTranslator UNESCAPE_HTML4 = new AggregateTranslator( new LookupTranslator(EntityArrays.BASIC_UNESCAPE), @@ -57,6 +76,10 @@ public class UnescapeUtils { new NumericEntityUnescaper() ); + public static final String unescapeHtml4(String input) { + return UNESCAPE_HTML4.translate(input); + } + public static final CharSequenceTranslator UNESCAPE_XML = new AggregateTranslator( new LookupTranslator(EntityArrays.BASIC_UNESCAPE), @@ -64,8 +87,16 @@ public class UnescapeUtils { new NumericEntityUnescaper() ); + public static final String unescapeXml(String input) { + return UNESCAPE_XML.translate(input); + } + public static final CharSequenceTranslator UNESCAPE_CSV = new CsvUnescaper(); + public static final String unescapeCsv(String input) { + return UNESCAPE_CSV.translate(input); + } + static class CsvUnescaper extends CharSequenceTranslator { private static final char CSV_DELIMITER = ',';