changeset 2503:e3bd1f412421

Added GET parameters to map printer flys-client/trunk@4348 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 04 May 2012 17:03:04 +0000
parents 328aa273ef3b
children 425bc486a40f
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/server/MapHelper.java flys-client/src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java
diffstat 3 files changed, 105 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Fri May 04 15:19:30 2012 +0000
+++ b/flys-client/ChangeLog	Fri May 04 17:03:04 2012 +0000
@@ -1,3 +1,13 @@
+2012-05-04	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/server/MapHelper.java:
+	  Added logger.isDebugEnable() as a condition for serializing
+	  XML to the log.
+
+	* src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java:
+	  Evaluate 'uuid', 'minx', 'maxx', 'miny', 'maxy' and 'maptype'
+	  from GET parameters.
+
 2012-05-04	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/server/MapHelper.java	Fri May 04 15:19:30 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/MapHelper.java	Fri May 04 17:03:04 2012 +0000
@@ -32,7 +32,9 @@
     public static MapConfig parseConfig(Document raw) {
         logger.debug("MapHelper.parseConfig");
 
-        logger.debug(XMLUtils.toString(raw));
+        if (logger.isDebugEnabled()) {
+            logger.debug(XMLUtils.toString(raw));
+        }
 
         MapConfig config = new MapConfig();
 
--- a/flys-client/src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java	Fri May 04 15:19:30 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java	Fri May 04 17:03:04 2012 +0000
@@ -24,6 +24,18 @@
 
 import org.mapfish.print.utils.PJsonObject;
 
+import de.intevation.artifacts.common.utils.StringUtils;
+import de.intevation.artifacts.common.utils.XMLUtils;
+import de.intevation.artifacts.common.utils.ClientProtocolUtils;
+
+import de.intevation.artifacts.httpclient.http.HttpClient;
+import de.intevation.artifacts.httpclient.http.HttpClientImpl;
+import de.intevation.artifacts.httpclient.exceptions.ConnectionException;
+
+import org.w3c.dom.Document;
+
+import de.intevation.flys.client.shared.model.MapConfig;
+
 public class MapPrintServiceImpl
 extends      HttpServlet
 {
@@ -127,7 +139,83 @@
     "}";
 
 
-    private MapPrinter getMapPrinter() throws ServletException, IOException {
+    @Override
+    public void doGet(HttpServletRequest req, HttpServletResponse resp) 
+    throws  ServletException, IOException
+    {
+        log.info("MapPrintServiceImpl.doGet");
+
+        String uuid = req.getParameter("uuid");
+
+        if (uuid == null || !StringUtils.checkUUID(uuid)) {
+            throw new ServletException("Missing or misspelled UUID");
+        }
+
+        String minXS = req.getParameter("minx");
+        String maxXS = req.getParameter("maxx");
+        String minYS = req.getParameter("miny");
+        String maxYS = req.getParameter("maxy");
+
+        if (minXS == null || maxXS == null
+        ||  minYS == null || maxYS == null) {
+            throw new ServletException("Missing minX, minY, maxX or maxY");
+        }
+
+        double minX, maxX, minY, maxY;
+
+        try {
+            minX = Double.parseDouble(minXS);
+            minY = Double.parseDouble(minYS);
+            maxX = Double.parseDouble(maxXS);
+            maxY = Double.parseDouble(maxYS);
+        }
+        catch (NumberFormatException nfe) {
+            throw new ServletException("Misspelled minX, minY, maxX or maxY");
+        }
+
+        String mapType = req.getParameter("maptype");
+
+        if (mapType == null || !mapType.equals("map")) {
+            mapType = "floodmap";
+        }
+
+        String url = getURL();
+
+        Document request = ClientProtocolUtils.newOutCollectionDocument(
+            uuid, mapType, mapType);
+
+        Document result;
+        try {
+            HttpClient client = new HttpClientImpl(url);
+            InputStream    is = client.collectionOut(request, uuid, mapType);
+            try {
+                result = XMLUtils.parseDocument(is);
+            }
+            finally {
+                is.close();
+            }
+        }
+        catch (ConnectionException ce) {
+            log.error(ce);
+            throw new ServletException(ce);
+        }
+
+        MapConfig mapConfig = MapHelper.parseConfig(result);
+
+        System.err.println(XMLUtils.toString(result));
+
+        producePDF(DEMO_JSON, resp);
+    }
+
+    protected String getURL() throws ServletException {
+        String url = getServletContext().getInitParameter("server-url");
+        if (url == null) {
+            throw new ServletException("Missing server-url");
+        }
+        return url;
+    }
+
+    protected MapPrinter getMapPrinter() throws ServletException, IOException {
         String configPath = getInitParameter("config");
         if (configPath == null) {
             throw new ServletException("Missing configuration in web.xml");
@@ -145,12 +233,10 @@
         return new MapPrinter(configFile);
     }
 
-    @Override
-    public void doGet(HttpServletRequest req, HttpServletResponse resp) 
-    throws  ServletException, IOException
+
+    protected void producePDF(String json, HttpServletResponse resp)
+    throws ServletException, IOException
     {
-        log.info("MapPrintServiceImpl.doGet");
-
         PJsonObject jsonSpec = MapPrinter.parseSpec(DEMO_JSON);
 
         MapPrinter printer = getMapPrinter();

http://dive4elements.wald.intevation.org