diff flys-client/src/main/java/de/intevation/flys/client/server/ChartOutputServiceImpl.java @ 549:e74bf6bfeeb6

Use the same code to create the attribute document for the chart creation in ChartOutputService and ChartInfoService. flys-client/trunk@2060 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 07 Jun 2011 10:03:19 +0000
parents 7c57149e8715
children 51d4b51a51ed
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ChartOutputServiceImpl.java	Mon Jun 06 11:56:15 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/ChartOutputServiceImpl.java	Tue Jun 07 10:03:19 2011 +0000
@@ -2,18 +2,16 @@
 
 import java.io.OutputStream;
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.w3c.dom.Document;
-import org.w3c.dom.Element;
 
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import de.intevation.artifacts.common.ArtifactNamespaceContext;
 import de.intevation.artifacts.common.utils.ClientProtocolUtils;
-import de.intevation.artifacts.common.utils.XMLUtils;
-import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
 
 import de.intevation.artifacts.httpclient.http.HttpClient;
 import de.intevation.artifacts.httpclient.http.HttpClientImpl;
@@ -29,13 +27,6 @@
 public class ChartOutputServiceImpl
 extends      HttpServlet
 {
-    /** The default chart width if no value is specified in the request.*/
-    public static final int DEFAULT_CHART_WIDTH  = 600;
-
-    /** The default chart height if no value is specified in the request.*/
-    public static final int DEFAULT_CHART_HEIGHT = 400;
-
-
     public void doGet(HttpServletRequest req, HttpServletResponse resp) {
         System.out.println("ChartOutputServiceImpl.doGet");
 
@@ -48,7 +39,8 @@
             String locale    = req.getParameter("locale");
 
             Document request = ClientProtocolUtils.newOutCollectionDocument(
-                uuid, type, type, getChartAttributes(req));
+                uuid, type, type,
+                ChartServiceHelper.getChartAttributes(prepareChartAttributes(req)));
 
             HttpClient client = new HttpClientImpl(serverUrl, locale);
             client.collectionOut(request, uuid, "chart", out);
@@ -57,127 +49,29 @@
             out.flush();
         }
         catch (IOException ioe) {
+            ioe.printStackTrace();
             System.err.println(ioe.getMessage());
         }
         catch (Exception e) {
+            e.printStackTrace();
             System.err.println(e.getMessage());
         }
     }
 
 
-    /**
-     * This method returns a document which might contain parameters to adjust
-     * chart settings. The document is created using the information that are
-     * contained in the request object.
-     *
-     * @param req The request document.
-     *
-     * @return a document to adjust chart settings.
-     */
-    protected Document getChartAttributes(HttpServletRequest req) {
-        Document doc = XMLUtils.newDocument();
-
-        ElementCreator ec = new ElementCreator(
-            doc,
-            ArtifactNamespaceContext.NAMESPACE_URI,
-            ArtifactNamespaceContext.NAMESPACE_PREFIX);
-
-        Element attributes = ec.create("attributes");
-
-        appendChartSize(req, attributes, ec);
-        appendXRange(req, attributes, ec);
-        appendYRange(req, attributes, ec);
-
-        doc.appendChild(attributes);
-
-        return doc;
-    }
-
-
-    /**
-     * This method extracts the size (width/height) of a chart from request
-     * object and append those values - if they exist - to the attribute
-     * document used to adjust chart settings.
-     *
-     * @param req The request object that might contain the chart size.
-     * @param attributes The attributes element used to adjust chart settings.
-     * @param ec The ElementCreator that might be used to create new Elements.
-     */
-    protected void appendChartSize(
-        HttpServletRequest req,
-        Element            attributes,
-        ElementCreator     ec)
-    {
-        Element size = ec.create("size");
-
-        String width  = req.getParameter("width");
-        String height = req.getParameter("height");
-
-        if (width == null || height == null) {
-            width  = Integer.toString(DEFAULT_CHART_WIDTH);
-            height = Integer.toString(DEFAULT_CHART_HEIGHT);
-        }
-
-        ec.addAttr(size, "width", width, true);
-        ec.addAttr(size, "height", height, true);
+    protected Map<String, String> prepareChartAttributes(HttpServletRequest req) {
+        Map<String, String> attr = new HashMap<String, String>();
 
-        attributes.appendChild(size);
-    }
-
-
-    /**
-     * This method extracts the x range for the chart from request object and
-     * appends those range - if it exists - to the attribute document used to
-     * adjust the chart settings.
-     *
-     * @param req The request object that might contain the chart size.
-     * @param doc The attribute document used to adjust chart settings.
-     * @param ec The ElementCreator that might be used to create new Elements.
-     */
-    protected void appendXRange(
-        HttpServletRequest req,
-        Element            attributes,
-        ElementCreator     ec)
-    {
-        Element range = ec.create("xrange");
-
-        String from = req.getParameter("minx");
-        String to   = req.getParameter("maxx");
-
-        if (from != null && to != null) {
-            ec.addAttr(range, "from", from, true);
-            ec.addAttr(range, "to", to, true);
+        Map params = req.getParameterMap();
 
-            attributes.appendChild(range);
-        }
-    }
-
+        attr.put("width", req.getParameter("width"));
+        attr.put("height", req.getParameter("height"));
+        attr.put("minx", req.getParameter("minx"));
+        attr.put("maxx", req.getParameter("maxx"));
+        attr.put("miny", req.getParameter("miny"));
+        attr.put("maxy", req.getParameter("maxy"));
 
-    /**
-     * This method extracts the x range for the chart from request object and
-     * appends those range - if it exists - to the attribute document used to
-     * adjust the chart settings.
-     *
-     * @param req The request object that might contain the chart size.
-     * @param doc The attribute document used to adjust chart settings.
-     * @param ec The ElementCreator that might be used to create new Elements.
-     */
-    protected void appendYRange(
-        HttpServletRequest req,
-        Element            attributes,
-        ElementCreator     ec)
-    {
-        Element range = ec.create("yrange");
-
-        String from = req.getParameter("miny");
-        String to   = req.getParameter("maxy");
-
-        if (from != null && to != null) {
-            ec.addAttr(range, "from", from, true);
-            ec.addAttr(range, "to", to, true);
-
-            attributes.appendChild(range);
-        }
+        return attr;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org