commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r789584 - in /commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate: EntityArrays.java EscapeUtils.java UnescapeUtils.java
Date Tue, 30 Jun 2009 06:47:18 GMT
Author: bayard
Date: Tue Jun 30 06:47:18 2009
New Revision: 789584

URL: http://svn.apache.org/viewvc?rev=789584&view=rev
Log:
Making the EntityArrays class public by cloning the arrays when they are accessed. API might
need a sanity check as this is the old Entities stuff. Also changing the arrays to be private
and the rest of the code to use the cloning methods. This does add performance overhead, but
I think it'll be negligible and better to practice safe coding. Part of LANG-505

Modified:
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EntityArrays.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/text/translate/EntityArrays.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EntityArrays.java?rev=789584&r1=789583&r2=789584&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EntityArrays.java
(original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/translate/EntityArrays.java
Tue Jun 30 06:47:18 2009
@@ -17,15 +17,16 @@
 package org.apache.commons.lang.text.translate;
 
 /**
- * Package private class holding varius entity data for HTML and XML.
+ * Class holding various entity data for HTML and XML - generally for use with 
+ * the LookupTranslator.
  * All arrays are of length [*][2].
  *
  * @since 3.0
  */
-// TODO: These need to be public - make methods to return them for security purposes?
-class EntityArrays {
+public class EntityArrays {
 
-    static final String[][] ISO8859_1_ESCAPE = {
+    public static String[][] ISO8859_1_ESCAPE() { return ISO8859_1_ESCAPE.clone(); }
+    private static final String[][] ISO8859_1_ESCAPE = {
         {"\u00A0", " "}, // non-breaking space
         {"\u00A1", "¡"}, // inverted exclamation mark
         {"\u00A2", "¢"}, // cent sign
@@ -124,10 +125,12 @@
         {"\u00FF", "ÿ"}, // ΓΏ - lowercase y, umlaut
     };
 
-    static final String[][] ISO8859_1_UNESCAPE = invert(ISO8859_1_ESCAPE);
+    public static String[][] ISO8859_1_UNESCAPE() { return ISO8859_1_UNESCAPE.clone(); }
+    private static final String[][] ISO8859_1_UNESCAPE = invert(ISO8859_1_ESCAPE);
 
     // http://www.w3.org/TR/REC-html40/sgml/entities.html
-    static final String[][] HTML40_EXTENDED_ESCAPE = {
+    public static String[][] HTML40_EXTENDED_ESCAPE() { return HTML40_EXTENDED_ESCAPE.clone();
}
+    private static final String[][] HTML40_EXTENDED_ESCAPE = {
         // <!-- Latin Extended-B -->
         {"\u0192", "&fnof;"}, // latin small f with hook = function= florin, U+0192 ISOtech
-->
         // <!-- Greek -->
@@ -324,29 +327,34 @@
         {"\u20AC", "&euro;"}, // -- euro sign, U+20AC NEW -->
     };
 
-    static final String[][] HTML40_EXTENDED_UNESCAPE = invert(HTML40_EXTENDED_ESCAPE);
+    public static String[][] HTML40_EXTENDED_UNESCAPE() { return HTML40_EXTENDED_UNESCAPE.clone();
}
+    private static final String[][] HTML40_EXTENDED_UNESCAPE = invert(HTML40_EXTENDED_ESCAPE);
 
-    static final String[][] BASIC_ESCAPE = {
+    public static String[][] BASIC_ESCAPE() { return BASIC_ESCAPE.clone(); }
+    private static final String[][] BASIC_ESCAPE = {
         {"\"", "&quot;"}, // " - double-quote
         {"&", "&amp;"},   // & - ampersand
         {"<", "&lt;"},    // < - less-than
         {">", "&gt;"},    // > - greater-than
     };
 
-    static final String[][] BASIC_UNESCAPE = invert(BASIC_ESCAPE);
+    public static String[][] BASIC_UNESCAPE() { return BASIC_UNESCAPE.clone(); }
+    private static final String[][] BASIC_UNESCAPE = invert(BASIC_ESCAPE);
 
-    static final String[][] APOS_ESCAPE = {
+    public static String[][] APOS_ESCAPE() { return APOS_ESCAPE.clone(); }
+    private static final String[][] APOS_ESCAPE = {
         {"'", "&apos;"}, // XML apostrophe
     };
 
-    static final String[][] APOS_UNESCAPE = invert(APOS_ESCAPE);
+    public static String[][] APOS_UNESCAPE() { return APOS_UNESCAPE.clone(); }
+    private static final String[][] APOS_UNESCAPE = invert(APOS_ESCAPE);
 
     /**
      * Used to invert an escape array into an unescape array
      * @param array String[][] to be inverted
      * @return String[][] inverted array
      */
-    static String[][] invert(String[][] array) {
+    public static String[][] invert(String[][] array) {
         String[][] newarray = new String[array.length][2];
         for(int i = 0; i<array.length; i++) {
             newarray[i][0] = array[i][1];

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=789584&r1=789583&r2=789584&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
Tue Jun 30 06:47:18 2009
@@ -76,8 +76,8 @@
                 
     public static final CharSequenceTranslator ESCAPE_XML = 
         new AggregateTranslator(
-            new LookupTranslator(EntityArrays.BASIC_ESCAPE),
-            new LookupTranslator(EntityArrays.APOS_ESCAPE),
+            new LookupTranslator(EntityArrays.BASIC_ESCAPE()),
+            new LookupTranslator(EntityArrays.APOS_ESCAPE()),
             NumericEntityEscaper.above(0x7f)
         );
 
@@ -87,8 +87,8 @@
                 
     public static final CharSequenceTranslator ESCAPE_HTML3 = 
         new AggregateTranslator(
-            new LookupTranslator(EntityArrays.BASIC_ESCAPE),
-            new LookupTranslator(EntityArrays.ISO8859_1_ESCAPE),
+            new LookupTranslator(EntityArrays.BASIC_ESCAPE()),
+            new LookupTranslator(EntityArrays.ISO8859_1_ESCAPE()),
             NumericEntityEscaper.above(0x7f)
         );
 
@@ -98,9 +98,9 @@
                 
     public static final CharSequenceTranslator ESCAPE_HTML4 = 
         new AggregateTranslator(
-            new LookupTranslator(EntityArrays.BASIC_ESCAPE),
-            new LookupTranslator(EntityArrays.ISO8859_1_ESCAPE),
-            new LookupTranslator(EntityArrays.HTML40_EXTENDED_ESCAPE),
+            new LookupTranslator(EntityArrays.BASIC_ESCAPE()),
+            new LookupTranslator(EntityArrays.ISO8859_1_ESCAPE()),
+            new LookupTranslator(EntityArrays.HTML40_EXTENDED_ESCAPE()),
             NumericEntityEscaper.above(0x7f)
         );
 

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=789584&r1=789583&r2=789584&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
Tue Jun 30 06:47:18 2009
@@ -59,8 +59,8 @@
                 
     public static final CharSequenceTranslator UNESCAPE_HTML3 = 
         new AggregateTranslator(
-            new LookupTranslator(EntityArrays.BASIC_UNESCAPE),
-            new LookupTranslator(EntityArrays.ISO8859_1_UNESCAPE),
+            new LookupTranslator(EntityArrays.BASIC_UNESCAPE()),
+            new LookupTranslator(EntityArrays.ISO8859_1_UNESCAPE()),
             new NumericEntityUnescaper()
         );
 
@@ -70,9 +70,9 @@
                 
     public static final CharSequenceTranslator UNESCAPE_HTML4 = 
         new AggregateTranslator(
-            new LookupTranslator(EntityArrays.BASIC_UNESCAPE),
-            new LookupTranslator(EntityArrays.ISO8859_1_UNESCAPE),
-            new LookupTranslator(EntityArrays.HTML40_EXTENDED_UNESCAPE),
+            new LookupTranslator(EntityArrays.BASIC_UNESCAPE()),
+            new LookupTranslator(EntityArrays.ISO8859_1_UNESCAPE()),
+            new LookupTranslator(EntityArrays.HTML40_EXTENDED_UNESCAPE()),
             new NumericEntityUnescaper()
         );
 
@@ -82,8 +82,8 @@
                 
     public static final CharSequenceTranslator UNESCAPE_XML = 
         new AggregateTranslator(
-            new LookupTranslator(EntityArrays.BASIC_UNESCAPE),
-            new LookupTranslator(EntityArrays.APOS_UNESCAPE),
+            new LookupTranslator(EntityArrays.BASIC_UNESCAPE()),
+            new LookupTranslator(EntityArrays.APOS_UNESCAPE()),
             new NumericEntityUnescaper()
         );
 



Mime
View raw message