[Dive4elements-commits] [PATCH 1 of 8] Add toJavaEncodedString function to encode strings in utf-16 notation

Wald Commits scm-commit at wald.intevation.org
Mon Apr 15 18:41:55 CEST 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1366018468 -7200
# Node ID 1103308b19ca5d5e1d9e52dd1f1b53d1d2edba89
# Parent  f5d966428703079d8dde066c73304d6cc0be65b8
Add toJavaEncodedString function to encode strings in utf-16 notation
used by java. This fixes printing of unicode characters.

diff -r f5d966428703 -r 1103308b19ca flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapPrintPanel.java
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapPrintPanel.java	Mon Apr 15 18:27:14 2013 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapPrintPanel.java	Mon Apr 15 11:34:28 2013 +0200
@@ -286,6 +286,26 @@
         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();
@@ -293,15 +313,15 @@
         GWT.log("MapPrintPanel.updateCollection via RPC now");
 
         List<Property> properties = new ArrayList<Property>();
-        properties.add(new PropertySetting(MAPFISH_MAPTITLE, this.pageTitle.getValueAsString()));
-//        properties.add(new PropertySetting(MAPFISH_LAYOUT, this.pageFormat.getValueAsString()));
-        properties.add(new PropertySetting(MAPFISH_SUBTITLE, this.pageSubtitle.getValueAsString()));
-        properties.add(new PropertySetting(MAPFISH_RANGE, this.pageRange.getValueAsString()));
-        properties.add(new PropertySetting(MAPFISH_STRETCH, this.pageStrech.getValueAsString()));
-        properties.add(new PropertySetting(MAPFISH_CREATED, this.pageCreated.getValueAsString()));
-        properties.add(new PropertySetting(MAPFISH_SOURCE, this.pageSource.getValueAsString()));
-        properties.add(new PropertySetting(MAPFISH_CREATOR, this.pageCreator.getValueAsString()));
-        properties.add(new PropertySetting(MAPFISH_DATEPLACE, this.pageDatePlace.getValueAsString()));
+        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(pageStrech.getValueAsString())));
+        properties.add(new PropertySetting(MAPFISH_CREATED, toJavaEncodedString(pageCreated.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())));
         settings.setSettings("default", properties);
 
         collection.addSettings("print-settings", settings);


More information about the Dive4elements-commits mailing list