[Dive4elements-commits] [PATCH] Further fix encoding handling in the print service

Wald Commits scm-commit at wald.intevation.org
Fri Jun 21 12:15:44 CEST 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1371809730 -7200
# Node ID 2987d81ea71986bb26b911a9da00d450dbe2eec3
# Parent  e26655a8f98d9453a2310b53145546f9c742092e
Further fix encoding handling in the print service

    - Strings are now html escaped additionaly to java encoding
    - Escaping / encoding moved into maputils
    - The legend url is urlencoded
    - Properties are no longer stored in an encoded manner but
    rather encoded on demand

diff -r e26655a8f98d -r 2987d81ea719 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/MapPrintPanel.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/MapPrintPanel.java	Fri Jun 21 11:42:35 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/MapPrintPanel.java	Fri Jun 21 12:15:30 2013 +0200
@@ -22,6 +22,7 @@
 import org.dive4elements.river.client.shared.model.Property;
 import org.dive4elements.river.client.shared.model.PropertySetting;
 import org.dive4elements.river.client.shared.model.Settings;
+import org.dive4elements.river.client.shared.MapUtils;
 
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.user.client.Window;
@@ -274,15 +275,16 @@
                 catch (MissingResourceException mre) {
                     localized = props.getName();
                 }
-                url.append(toJavaEncodedString(localized));
+                url.append(MapUtils.toSaveHTMLJavaString(localized));
                 url.append("=");
-                url.append(props.getValue());
+                url.append(MapUtils.toSaveHTMLJavaString((String)props.getValue()));
             }
         }
         // O.o
         String river = findRiver(((MapOutputTab)mapToolbar.getOutputTab()
                     ).getCollectionView().getArtifact());
-        url.append("&" + toJavaEncodedString(MSG.getString(MAPFISH_RIVER)) + "=" + river);
+        url.append("&" + MapUtils.toSaveHTMLJavaString(MSG.getString(MAPFISH_RIVER)) + "=" + 
+                MapUtils.toSaveHTMLJavaString(river));
     }
 
     // Copy of DatacageWindow's findRiver with added state for map.river
@@ -309,26 +311,6 @@
         return "";
     }
 
-    public static String toJavaEncodedString(String str) {
-        if (str == null) {
-            return null;
-        }
-        StringBuilder sb = new StringBuilder();
-        for (int i = 0, len = str.length(); i < len; i++) {
-            int unipoint = Character.codePointAt(str, i);
-            if ((unipoint < 32) || (unipoint > 127)) {
-                sb.append("\\u");
-                sb.append(Integer.toHexString((unipoint >> 3*4) & 0xf));
-                sb.append(Integer.toHexString((unipoint >> 2*4) & 0xf));
-                sb.append(Integer.toHexString((unipoint >> 1*4) & 0xf));
-                sb.append(Integer.toHexString((unipoint >> 0*4) & 0xf));
-            } else {
-                sb.append(str.charAt(i));
-            }
-        }
-        return sb.toString();
-    }
-
     protected void updateCollection() {
         final Config config = Config.getInstance();
         final String loc    = config.getLocale();
@@ -336,16 +318,16 @@
         GWT.log("MapPrintPanel.updateCollection via RPC now");
 
         List<Property> properties = new ArrayList<Property>();
-        properties.add(new PropertySetting(MAPFISH_MAPTITLE, toJavaEncodedString(pageTitle.getValueAsString())));
-//        properties.add(new PropertySetting(MAPFISH_LAYOUT, toJavaEncodedString(pageFormat.getValueAsString())));
-        properties.add(new PropertySetting(MAPFISH_SUBTITLE, toJavaEncodedString(pageSubtitle.getValueAsString())));
-        properties.add(new PropertySetting(MAPFISH_RANGE, toJavaEncodedString(pageRange.getValueAsString())));
-        properties.add(new PropertySetting(MAPFISH_STRETCH, toJavaEncodedString(pageStretch.getValueAsString())));
-        properties.add(new PropertySetting(MAPFISH_INSTITUTION, toJavaEncodedString(pageInstitution.getValueAsString())));
-        properties.add(new PropertySetting(MAPFISH_SOURCE, toJavaEncodedString(pageSource.getValueAsString())));
-        properties.add(new PropertySetting(MAPFISH_CREATOR, toJavaEncodedString(pageCreator.getValueAsString())));
-        properties.add(new PropertySetting(MAPFISH_DATEPLACE, toJavaEncodedString(pageDatePlace.getValueAsString())));
-        properties.add(new PropertySetting(MAPFISH_LOGO, toJavaEncodedString(pageLogo.getValueAsString())));
+        properties.add(new PropertySetting(MAPFISH_MAPTITLE, pageTitle.getValueAsString()));
+//        properties.add(new PropertySetting(MAPFISH_LAYOUT, pageFormat.getValueAsString()));
+        properties.add(new PropertySetting(MAPFISH_SUBTITLE, pageSubtitle.getValueAsString()));
+        properties.add(new PropertySetting(MAPFISH_RANGE, pageRange.getValueAsString()));
+        properties.add(new PropertySetting(MAPFISH_STRETCH, pageStretch.getValueAsString()));
+        properties.add(new PropertySetting(MAPFISH_INSTITUTION, pageInstitution.getValueAsString()));
+        properties.add(new PropertySetting(MAPFISH_SOURCE, pageSource.getValueAsString()));
+        properties.add(new PropertySetting(MAPFISH_CREATOR, pageCreator.getValueAsString()));
+        properties.add(new PropertySetting(MAPFISH_DATEPLACE, pageDatePlace.getValueAsString()));
+        properties.add(new PropertySetting(MAPFISH_LOGO, pageLogo.getValueAsString()));
         settings.setSettings("default", properties);
 
         collection.addSettings("print-settings", settings);
diff -r e26655a8f98d -r 2987d81ea719 gwt-client/src/main/java/org/dive4elements/river/client/server/MapPrintServiceImpl.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/server/MapPrintServiceImpl.java	Fri Jun 21 11:42:35 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/MapPrintServiceImpl.java	Fri Jun 21 12:15:30 2013 +0200
@@ -212,7 +212,7 @@
             Map<String, Object> legend = new LinkedHashMap<String, Object>();
             List<Object> classes = new ArrayList<Object>(1);
             Map<String, Object> clazz = new LinkedHashMap<String, Object>();
-            String lgu = MapUtils.getLegendGraphicUrl(layer.url, layer.layers, dpi);
+            String lgu = encode(MapUtils.getLegendGraphicUrl(layer.url, layer.layers, dpi));
             clazz.put("icon", lgu);
             clazz.put("name", layer.description);
             classes.add(clazz);
diff -r e26655a8f98d -r 2987d81ea719 gwt-client/src/main/java/org/dive4elements/river/client/shared/MapUtils.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/shared/MapUtils.java	Fri Jun 21 11:42:35 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/shared/MapUtils.java	Fri Jun 21 12:15:30 2013 +0200
@@ -10,6 +10,8 @@
 
 import java.util.Date;
 
+import com.google.gwt.safehtml.shared.SafeHtmlUtils;
+
 
 public class MapUtils {
 
@@ -47,5 +49,29 @@
 
         return url;
     }
+
+    public static String toSaveHTMLJavaString(String str) {
+        return str == null ? null : SafeHtmlUtils.htmlEscape(toJavaEncodedString(str));
+    }
+
+    public static String toJavaEncodedString(String str) {
+        if (str == null) {
+            return null;
+        }
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0, len = str.length(); i < len; i++) {
+            int unipoint = Character.codePointAt(str, i);
+            if ((unipoint < 32) || (unipoint > 127)) {
+                sb.append("\\u");
+                sb.append(Integer.toHexString((unipoint >> 3*4) & 0xf));
+                sb.append(Integer.toHexString((unipoint >> 2*4) & 0xf));
+                sb.append(Integer.toHexString((unipoint >> 1*4) & 0xf));
+                sb.append(Integer.toHexString((unipoint >> 0*4) & 0xf));
+            } else {
+                sb.append(str.charAt(i));
+            }
+        }
+        return sb.toString();
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :


More information about the Dive4elements-commits mailing list