[PATCH] Improve MapFish print parameter handling a bit

Wald Commits scm-commit at wald.intevation.org
Wed Nov 1 19:08:09 CET 2023


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1698861990 -3600
#      Wed Nov 01 19:06:30 2023 +0100
# Branch 3.2.x
# Node ID 2a78ac6c804537d14a9834048211992b0e27e80c
# Parent  069d7ee4c0cb1711825b7ff4d3e5cfdab0bb7244
Improve MapFish print parameter handling a bit

diff -r 069d7ee4c0cb -r 2a78ac6c8045 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	Mon Aug 14 12:29:25 2023 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/MapPrintServiceImpl.java	Wed Nov 01 19:06:30 2023 +0100
@@ -65,6 +65,8 @@
 public class MapPrintServiceImpl
 extends      HttpServlet
 {
+    private static final String MAPFISH_DATA_PREFIX = "mapfish_data_";
+
     private static final Logger log =
         LogManager.getLogger(MapPrintServiceImpl.class);
 
@@ -292,26 +294,25 @@
         Enumeration paramNames = req.getParameterNames();
         List<String> params = Collections.list(paramNames);
         Collections.sort(params);
+        final int prefixLength = MAPFISH_DATA_PREFIX.length();
         for (String paramName : params) {
-            if (paramName.startsWith("mapfish_data_")) {
+            if (paramName.startsWith(MAPFISH_DATA_PREFIX)) {
                 // You can add mapfish_data variables that will be mapped
-                // to a info value pairs to provide meta data for the map
-                // The the info part starts with a number for sorting that
+                // to "info"/"value" pairs to provide meta data for the map.
+                // If the "info" part starts with a number for sorting, that
                 // number will be stripped
-                String paramValue = req.getParameter(paramName);
                 Map<String, Object> data3 = new HashMap<String, Object>();
-                int order = 0;
                 try {
-                    order = Integer.parseInt(paramName.substring(13, 14));
-                    data3.put("info", paramName.substring(14));
+                    Integer.parseInt(paramName.substring(
+                            prefixLength, prefixLength + 1));
+                    data3.put("info", paramName.substring(prefixLength + 1));
                 } catch (NumberFormatException nfe) {
-                    data3.put("info", paramName.substring(13));
+                    data3.put("info", paramName.substring(prefixLength));
                     payload.add(data3);
                 }
-                if (paramValue.equals("null"))
-                    data3.put("value", "");
-                else
-                    data3.put("value", paramValue);
+
+                String paramValue = req.getParameter(paramName);
+                data3.put("value", paramValue.equals("null") ? "" : paramValue);
                 payload.add(data3);
             } else if (paramName.startsWith("mapfish_")) {
                 String paramValue = req.getParameter(paramName);
@@ -420,6 +421,7 @@
         }
         catch (UnsupportedEncodingException usee) {
             // Should not happen.
+            log.error(usee.getMessage());
             return s;
         }
     }


More information about the Dive4Elements-commits mailing list