commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r787903 - in /commons/proper/lang/trunk/src/java/org/apache/commons/lang: StringEscapeUtils.java text/translate/EscapeUtils.java text/translate/UnescapeUtils.java
Date Wed, 24 Jun 2009 04:41:52 GMT
Author: bayard
Date: Wed Jun 24 04:41:51 2009
New Revision: 787903

URL: http://svn.apache.org/viewvc?rev=787903&view=rev
Log:
Adding escapeXxx(String) and unescapeXxx(String) methods to EscapeUtils + UnescapeUtils, and
changing StringEscapeUtils to use them. LANG-505

Modified:
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringEscapeUtils.java
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EscapeUtils.java
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnescapeUtils.java

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringEscapeUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringEscapeUtils.java?rev=787903&r1=787902&r2=787903&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringEscapeUtils.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/StringEscapeUtils.java Wed
Jun 24 04:41:51 2009
@@ -78,7 +78,7 @@
      * @return String with escaped values, <code>null</code> if null string input
      */
     public static String escapeJava(String str) {
-        return EscapeUtils.ESCAPE_JAVA.translate(str);
+        return EscapeUtils.escapeJava(str);
     }
 
     /**
@@ -119,7 +119,7 @@
      * @return String with escaped values, <code>null</code> if null string input
      */
     public static String escapeJavaScript(String str) {
-        return EscapeUtils.ESCAPE_ECMASCRIPT.translate(str);
+        return EscapeUtils.escapeEcmaScript(str);
     }
 
     /**
@@ -148,7 +148,7 @@
      * @return a new unescaped <code>String</code>, <code>null</code>
if null string input
      */
     public static String unescapeJava(String str) {
-        return UnescapeUtils.UNESCAPE_JAVA.translate(str);
+        return UnescapeUtils.unescapeJava(str);
     }
 
     /**
@@ -182,7 +182,7 @@
      * @return A new unescaped <code>String</code>, <code>null</code>
if null string input
      */
     public static String unescapeJavaScript(String str) {
-        return UnescapeUtils.UNESCAPE_ECMASCRIPT.translate(str);
+        return UnescapeUtils.unescapeEcmaScript(str);
     }
 
     /**
@@ -234,7 +234,7 @@
      * @see <a href="http://www.w3.org/TR/html401/charset.html#code-position">HTML
4.01 Code positions</a>
      */
     public static String escapeHtml(String str) {
-        return EscapeUtils.ESCAPE_HTML4.translate(str);
+        return EscapeUtils.escapeHtml4(str);
     }
 
     /**
@@ -288,7 +288,7 @@
      * @see #escapeHtml(Writer, String)
      */
     public static String unescapeHtml(String str) {
-        return UnescapeUtils.UNESCAPE_HTML4.translate(str);
+        return UnescapeUtils.unescapeHtml4(str);
     }
 
     /**
@@ -355,7 +355,7 @@
      * @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 @@
      * @see #escapeXml(String)
      */
     public static String unescapeXml(String str) {
-        return UnescapeUtils.UNESCAPE_XML.translate(str);
+        return UnescapeUtils.unescapeXml(str);
     }
 
     //-----------------------------------------------------------------------
@@ -424,7 +424,7 @@
      * @since 2.4
      */
     public static String escapeCsv(String str) {
-        return EscapeUtils.ESCAPE_CSV.translate(str);
+        return EscapeUtils.escapeCsv(str);
     }
 
     /**
@@ -477,7 +477,7 @@
      * @since 2.4
      */
     public static String unescapeCsv(String str) {
-        return UnescapeUtils.UNESCAPE_CSV.translate(str);
+        return UnescapeUtils.unescapeCsv(str);
     }
 
     /**

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EscapeUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EscapeUtils.java?rev=787903&r1=787902&r2=787903&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EscapeUtils.java
(original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EscapeUtils.java
Wed Jun 24 04:41:51 2009
@@ -39,6 +39,10 @@
             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 @@
             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 @@
             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 @@
             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 @@
             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.

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnescapeUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnescapeUtils.java?rev=787903&r1=787902&r2=787903&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnescapeUtils.java
(original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/UnescapeUtils.java
Wed Jun 24 04:41:51 2009
@@ -47,8 +47,27 @@
                       })
         );
 
+    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 @@
             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 @@
             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 = ',';



Mime
View raw message