Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/server/MapPrintServiceImpl.java @ 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 | 0834c2591e14 |
children |
comparison
equal
deleted
inserted
replaced
9792:069d7ee4c0cb | 9793:2a78ac6c8045 |
---|---|
63 */ | 63 */ |
64 | 64 |
65 public class MapPrintServiceImpl | 65 public class MapPrintServiceImpl |
66 extends HttpServlet | 66 extends HttpServlet |
67 { | 67 { |
68 private static final String MAPFISH_DATA_PREFIX = "mapfish_data_"; | |
69 | |
68 private static final Logger log = | 70 private static final Logger log = |
69 LogManager.getLogger(MapPrintServiceImpl.class); | 71 LogManager.getLogger(MapPrintServiceImpl.class); |
70 | 72 |
71 protected static class Layer implements Comparable<Layer> { | 73 protected static class Layer implements Comparable<Layer> { |
72 | 74 |
290 List<Object> payload = new ArrayList<Object>(); | 292 List<Object> payload = new ArrayList<Object>(); |
291 data.put("data", payload); | 293 data.put("data", payload); |
292 Enumeration paramNames = req.getParameterNames(); | 294 Enumeration paramNames = req.getParameterNames(); |
293 List<String> params = Collections.list(paramNames); | 295 List<String> params = Collections.list(paramNames); |
294 Collections.sort(params); | 296 Collections.sort(params); |
297 final int prefixLength = MAPFISH_DATA_PREFIX.length(); | |
295 for (String paramName : params) { | 298 for (String paramName : params) { |
296 if (paramName.startsWith("mapfish_data_")) { | 299 if (paramName.startsWith(MAPFISH_DATA_PREFIX)) { |
297 // You can add mapfish_data variables that will be mapped | 300 // You can add mapfish_data variables that will be mapped |
298 // to a info value pairs to provide meta data for the map | 301 // to "info"/"value" pairs to provide meta data for the map. |
299 // The the info part starts with a number for sorting that | 302 // If the "info" part starts with a number for sorting, that |
300 // number will be stripped | 303 // number will be stripped |
301 String paramValue = req.getParameter(paramName); | |
302 Map<String, Object> data3 = new HashMap<String, Object>(); | 304 Map<String, Object> data3 = new HashMap<String, Object>(); |
303 int order = 0; | |
304 try { | 305 try { |
305 order = Integer.parseInt(paramName.substring(13, 14)); | 306 Integer.parseInt(paramName.substring( |
306 data3.put("info", paramName.substring(14)); | 307 prefixLength, prefixLength + 1)); |
308 data3.put("info", paramName.substring(prefixLength + 1)); | |
307 } catch (NumberFormatException nfe) { | 309 } catch (NumberFormatException nfe) { |
308 data3.put("info", paramName.substring(13)); | 310 data3.put("info", paramName.substring(prefixLength)); |
309 payload.add(data3); | 311 payload.add(data3); |
310 } | 312 } |
311 if (paramValue.equals("null")) | 313 |
312 data3.put("value", ""); | 314 String paramValue = req.getParameter(paramName); |
313 else | 315 data3.put("value", paramValue.equals("null") ? "" : paramValue); |
314 data3.put("value", paramValue); | |
315 payload.add(data3); | 316 payload.add(data3); |
316 } else if (paramName.startsWith("mapfish_")) { | 317 } else if (paramName.startsWith("mapfish_")) { |
317 String paramValue = req.getParameter(paramName); | 318 String paramValue = req.getParameter(paramName); |
318 if (paramValue.equals("null")) | 319 if (paramValue.equals("null")) |
319 paramValue = ""; | 320 paramValue = ""; |
418 if (s == null) return null; | 419 if (s == null) return null; |
419 return URLEncoder.encode(s, "UTF-8"); | 420 return URLEncoder.encode(s, "UTF-8"); |
420 } | 421 } |
421 catch (UnsupportedEncodingException usee) { | 422 catch (UnsupportedEncodingException usee) { |
422 // Should not happen. | 423 // Should not happen. |
424 log.error(usee.getMessage()); | |
423 return s; | 425 return s; |
424 } | 426 } |
425 } | 427 } |
426 | 428 |
427 protected void producePDF(String json, HttpServletResponse resp) | 429 protected void producePDF(String json, HttpServletResponse resp) |