changeset 9793:2a78ac6c8045 3.2.x

Improve MapFish print parameter handling a bit
author Tom Gottfried <tom@intevation.de>
date Wed, 01 Nov 2023 19:06:30 +0100
parents 069d7ee4c0cb
children 47eee0be5792
files gwt-client/src/main/java/org/dive4elements/river/client/server/MapPrintServiceImpl.java
diffstat 1 files changed, 14 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- 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;
         }
     }

http://dive4elements.wald.intevation.org