# HG changeset patch # User Ingo Weinzierl # Date 1307440999 0 # Node ID e74bf6bfeeb658021b9b64d75d76404a100e2085 # Parent aff225e07720347a9c36cc7efb1eb20edefd1b92 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 diff -r aff225e07720 -r e74bf6bfeeb6 flys-client/ChangeLog --- a/flys-client/ChangeLog Mon Jun 06 11:56:15 2011 +0000 +++ b/flys-client/ChangeLog Tue Jun 07 10:03:19 2011 +0000 @@ -1,3 +1,20 @@ +2011-06-07 Ingo Weinzierl + + * src/main/java/de/intevation/flys/client/server/ChartServiceHelper.java: + New. This class helps generating the attribute document that is used for + generating charts. + + * src/main/java/de/intevation/flys/client/client/services/ChartInfoServiceAsync.java, + src/main/java/de/intevation/flys/client/client/services/ChartInfoService.java, + src/main/java/de/intevation/flys/client/server/ChartInfoServiceImpl.java, + * src/main/java/de/intevation/flys/client/server/ChartOutputServiceImpl.java: + Removed the code to create the chart attribute document. This work is + done in the ChartServiceHelper. + + * src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java: + Added a method that returns all attribute that should be used for the + chart creation. Currently, there are width, height, x and y ranges. + 2011-06-06 Ingo Weinzierl * src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java: diff -r aff225e07720 -r e74bf6bfeeb6 flys-client/src/main/java/de/intevation/flys/client/client/services/ChartInfoService.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/services/ChartInfoService.java Mon Jun 06 11:56:15 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/ChartInfoService.java Tue Jun 07 10:03:19 2011 +0000 @@ -1,5 +1,7 @@ package de.intevation.flys.client.client.services; +import java.util.Map; + import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @@ -14,12 +16,11 @@ public interface ChartInfoService extends RemoteService { Transform2D getChartInfo( - Collection collection, - String url, - String locale, - String type, - int width, - int height) + Collection collection, + String url, + String locale, + String type, + Map attr) throws ServerException; } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r aff225e07720 -r e74bf6bfeeb6 flys-client/src/main/java/de/intevation/flys/client/client/services/ChartInfoServiceAsync.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/services/ChartInfoServiceAsync.java Mon Jun 06 11:56:15 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/ChartInfoServiceAsync.java Tue Jun 07 10:03:19 2011 +0000 @@ -1,5 +1,7 @@ package de.intevation.flys.client.client.services; +import java.util.Map; + import com.google.gwt.user.client.rpc.AsyncCallback; import de.intevation.flys.client.shared.Transform2D; @@ -12,12 +14,11 @@ public interface ChartInfoServiceAsync { public void getChartInfo( - Collection collection, - String url, - String locale, - String type, - int width, - int height, + Collection collection, + String url, + String locale, + String type, + Map attr, AsyncCallback callback); } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r aff225e07720 -r e74bf6bfeeb6 flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java Mon Jun 06 11:56:15 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java Tue Jun 07 10:03:19 2011 +0000 @@ -1,6 +1,8 @@ package de.intevation.flys.client.client.ui.chart; import java.util.Date; +import java.util.HashMap; +import java.util.Map; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -156,6 +158,7 @@ yrange[0] = upper[1]; yrange[1] = lower[1]; + updateTransformer(); updateChartPanel(); } @@ -196,8 +199,6 @@ * Updates the Transform2D object using the chart info service. */ public void updateTransformer() { - Canvas chart = getChartPanel(); - Config config = Config.getInstance(); String url = config.getServerUrl(); String locale = config.getLocale(); @@ -207,8 +208,7 @@ url, locale, mode.getName(), - chart.getWidth(), - chart.getHeight(), + getChartAttributes(), new AsyncCallback() { public void onFailure(Throwable caught) { GWT.log("ERROR: " + caught.getMessage()); @@ -347,5 +347,26 @@ return imgUrl; } + + + public Map getChartAttributes() { + Map attr = new HashMap(); + + Canvas chart = getChartPanel(); + attr.put("width", chart.getWidth().toString()); + attr.put("height", chart.getHeight().toString()); + + if (xrange != null) { + attr.put("minx", Double.toString(xrange[0])); + attr.put("maxx", Double.toString(xrange[1])); + } + + if (yrange != null) { + attr.put("miny", Double.toString(yrange[0])); + attr.put("maxy", Double.toString(yrange[1])); + } + + return attr; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r aff225e07720 -r e74bf6bfeeb6 flys-client/src/main/java/de/intevation/flys/client/server/ChartInfoServiceImpl.java --- a/flys-client/src/main/java/de/intevation/flys/client/server/ChartInfoServiceImpl.java Mon Jun 06 11:56:15 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/ChartInfoServiceImpl.java Tue Jun 07 10:03:19 2011 +0000 @@ -2,11 +2,11 @@ import java.io.InputStream; import java.io.IOException; +import java.util.Map; import javax.xml.xpath.XPathConstants; import org.w3c.dom.Document; -import org.w3c.dom.Element; import org.w3c.dom.Node; import com.google.gwt.user.server.rpc.RemoteServiceServlet; @@ -14,7 +14,6 @@ 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; @@ -43,12 +42,11 @@ public Transform2D getChartInfo( - Collection collection, - String url, - String locale, - String type, - int width, - int height) + Collection collection, + String url, + String locale, + String type, + Map attr) throws ServerException { System.out.println("ChartInfoServiceImpl.getChartInfo"); @@ -57,7 +55,7 @@ collection.identifier(), type, type, - getChartAttributes(width, height)); + ChartServiceHelper.getChartAttributes(attr)); try { HttpClient client = new HttpClientImpl(url, locale); @@ -81,36 +79,6 @@ /** - * 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(int width, int height) { - Document doc = XMLUtils.newDocument(); - - ElementCreator ec = new ElementCreator( - doc, - ArtifactNamespaceContext.NAMESPACE_URI, - ArtifactNamespaceContext.NAMESPACE_PREFIX); - - Element attr = ec.create("attributes"); - Element size = ec.create("size"); - - ec.addAttr(size, "width", String.valueOf(width), true); - ec.addAttr(size, "height", String.valueOf(height), true); - - attr.appendChild(size); - doc.appendChild(attr); - - return doc; - } - - - /** * Parses the chart info document and extract the Transform2D values. * * @param doc The chart info document. diff -r aff225e07720 -r e74bf6bfeeb6 flys-client/src/main/java/de/intevation/flys/client/server/ChartOutputServiceImpl.java --- 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 prepareChartAttributes(HttpServletRequest req) { + Map attr = new HashMap(); - 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 : diff -r aff225e07720 -r e74bf6bfeeb6 flys-client/src/main/java/de/intevation/flys/client/server/ChartServiceHelper.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/ChartServiceHelper.java Tue Jun 07 10:03:19 2011 +0000 @@ -0,0 +1,151 @@ +package de.intevation.flys.client.server; + +import java.util.Map; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import de.intevation.artifacts.common.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; + + +/** + * @author Ingo Weinzierl + */ +public class ChartServiceHelper { + + /** 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; + + + private ChartServiceHelper() { + } + + /** + * 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 static Document getChartAttributes(Map req) { + System.out.println("ChartServiceHelper.getChartAttributes"); + + 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 static void appendChartSize( + Map req, + Element attributes, + ElementCreator ec) + { + System.out.println("ChartServiceHelper.appendChartSize"); + + Element size = ec.create("size"); + + String width = req.get("width"); + String height = req.get("height"); + + if (width == null || height == null) { + width = String.valueOf(DEFAULT_CHART_WIDTH); + height = String.valueOf(DEFAULT_CHART_HEIGHT); + } + + ec.addAttr(size, "width", width, true); + ec.addAttr(size, "height", height, true); + + 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 static void appendXRange( + Map req, + Element attributes, + ElementCreator ec) + { + System.out.println("ChartServiceHelper.appendXRange"); + + Element range = ec.create("xrange"); + + String from = req.get("minx"); + String to = req.get("maxx"); + + if (from != null && to != null) { + ec.addAttr(range, "from", from, true); + ec.addAttr(range, "to", to, true); + + attributes.appendChild(range); + } + } + + + /** + * 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 static void appendYRange( + Map req, + Element attributes, + ElementCreator ec) + { + System.out.println("ChartServiceHelper.appendYRange"); + + Element range = ec.create("yrange"); + + String from = req.get("miny"); + String to = req.get("maxy"); + + if (from != null && to != null) { + ec.addAttr(range, "from", from, true); + ec.addAttr(range, "to", to, true); + + attributes.appendChild(range); + } + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :