You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by le...@apache.org on 2012/03/22 09:38:06 UTC

svn commit: r1303684 - /ofbiz/branches/release11.04/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java

Author: lektran
Date: Thu Mar 22 08:38:05 2012
New Revision: 1303684

URL: http://svn.apache.org/viewvc?rev=1303684&view=rev
Log:
Merged from trunk r1303145
Ensure that collections (except for maps) are properly encoded for html when rendered using toString()

Modified:
    ofbiz/branches/release11.04/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java

Modified: ofbiz/branches/release11.04/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release11.04/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java?rev=1303684&r1=1303683&r2=1303684&view=diff
==============================================================================
--- ofbiz/branches/release11.04/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java (original)
+++ ofbiz/branches/release11.04/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java Thu Mar 22 08:38:05 2012
@@ -21,6 +21,7 @@ package org.ofbiz.widget.screen;
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
@@ -41,6 +42,7 @@ import org.ofbiz.widget.html.HtmlWidgetR
 import org.w3c.dom.Element;
 
 import freemarker.ext.beans.BeansWrapper;
+import freemarker.ext.beans.CollectionModel;
 import freemarker.ext.beans.StringModel;
 import freemarker.template.Configuration;
 import freemarker.template.Template;
@@ -61,6 +63,7 @@ public class HtmlWidget extends ModelScr
 
     // not sure if this is the best way to get FTL to use my fancy MapModel derivative, but should work at least...
     public static class ExtendedWrapper extends BeansWrapper {
+        @SuppressWarnings("unchecked")
         @Override
         public TemplateModel wrap(Object object) throws TemplateModelException {
             /* NOTE: don't use this and the StringHtmlWrapperForFtl or things will be double-encoded
@@ -71,6 +74,9 @@ public class HtmlWidget extends ModelScr
             // and handles most things without causing too many problems
             if (object instanceof String) {
                 return new StringHtmlWrapperForFtl((String) object, this);
+            } else if (object instanceof Collection && !(object instanceof Map)) {
+                // An additional wrapper to ensure ${aCollection} is properly encoded for html
+                return new CollectionHtmlWrapperForFtl((Collection) object, this);
             }
             return super.wrap(object);
         }
@@ -86,6 +92,20 @@ public class HtmlWidget extends ModelScr
         }
     }
 
+    public static class CollectionHtmlWrapperForFtl extends CollectionModel {
+
+        @SuppressWarnings("unchecked")
+        public CollectionHtmlWrapperForFtl(Collection collection, BeansWrapper wrapper) {
+            super(collection, wrapper);
+        }
+
+        @Override
+        public String getAsString() {
+            return StringUtil.htmlEncoder.encode(super.getAsString());
+        }
+
+    }
+
     // End Static, begin class section
 
     protected List<ModelScreenWidget> subWidgets = new ArrayList<ModelScreenWidget>();