← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1836: Improved EncoderVelocityContext. Was previously home-grown, now just a thin wrapper for commons-l...

 

------------------------------------------------------------
revno: 1836
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Mon 2010-05-10 22:29:36 +0200
message:
  Improved EncoderVelocityContext. Was previously home-grown, now just a thin wrapper for commons-lang StringEscapeUtils (Jo started this). Could be made simpler but that would require changing all vm templates. Also, the previous version did not work properly for utf8/vietnamese characters in xml files.
modified:
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/encoding/velocity/EncoderVelocityContext.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/encoding/velocity/EncoderVelocityContext.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/encoding/velocity/EncoderVelocityContext.java	2010-05-03 13:44:59 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/encoding/velocity/EncoderVelocityContext.java	2010-05-10 20:29:36 +0000
@@ -27,7 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-
 import org.apache.velocity.VelocityContext;
 
 import org.apache.commons.lang.StringEscapeUtils;
@@ -70,65 +69,25 @@
 
     public static class Encoder
     {
-        private static final String ESCAPE_JS = "\\\\";
-
-        private static final String QUOTE_JS = "'";
-
-        // ---------------------------------------------------------------------
-        // Public encode methods
-        // ---------------------------------------------------------------------
-
-        public String htmlEncode( Object object )
-        {
-            return xmlEncode( object );
-        }
-
-        public String xmlEncode( Object object )
-        {
-            if ( object == null )
-            {
-                return null;
-            }
-
-            return defaultEncode( object.toString() );
-        }
-
-        public String jsEncode( Object object )
-        {
-            if ( object == null )
-            {
-                return null;
-            }
-
-            String tmp = defaultEncode( object.toString() );
-            tmp = jsEscape( tmp, QUOTE_JS );
-
-            return tmp;
-        }
-
-        public String jsEscape( Object object, String quoteChar )
-        {
-            if ( object == null )
-            {
-                return null;
-            }
-
-            String tmp = object.toString();
-
-            tmp = tmp.replaceAll( "%", "%25" );
-            tmp = tmp.replaceAll( ESCAPE_JS, ESCAPE_JS + ESCAPE_JS );
-            tmp = tmp.replaceAll( quoteChar, ESCAPE_JS + quoteChar );            
-
-            return tmp;
-        }
-
-        // ---------------------------------------------------------------------
-        // Default encode method
-        // ---------------------------------------------------------------------
-
-        private String defaultEncode( String string )
-        {
-            return StringEscapeUtils.escapeHtml( string );
+        public String htmlEncode( String object )
+        {
+            return StringEscapeUtils.escapeHtml( object );
+        }
+
+        public String xmlEncode( String object )
+        {
+            return StringEscapeUtils.escapeXml( object );
+        }
+
+        public String jsEncode( String object )
+        {
+            return StringEscapeUtils.escapeJavaScript( object );
+        }
+        
+        @Deprecated
+        public String jsEscape( String object, String quoteChar )
+        {
+            return jsEncode( object );            
         }
     }
 }


Follow ups