# HG changeset patch # User Ingo Weinzierl # Date 1305191686 0 # Node ID b493d606fdef5a80b4cb92d1ed2ce5788c9873ff # Parent e763d8efd42fcba6fddc731c0ed353c18182b995 Enabled the client to request charts in different sizes. flys-client/trunk@1909 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r e763d8efd42f -r b493d606fdef flys-client/ChangeLog --- a/flys-client/ChangeLog Thu May 12 07:08:27 2011 +0000 +++ b/flys-client/ChangeLog Thu May 12 09:14:46 2011 +0000 @@ -1,3 +1,12 @@ +2011-05-12 Ingo Weinzierl + + * src/main/java/de/intevation/flys/client/client/ui/ChartOutputTab.java: + Defined the chart size (600x500). + + * src/main/java/de/intevation/flys/client/server/ChartOutputServiceImpl.java: + Query the chart in the requested size defined in the GET-parameters of + the request. + 2011-05-12 Ingo Weinzierl ISSUE-34 diff -r e763d8efd42f -r b493d606fdef flys-client/src/main/java/de/intevation/flys/client/client/ui/ChartOutputTab.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ChartOutputTab.java Thu May 12 07:08:27 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ChartOutputTab.java Thu May 12 09:14:46 2011 +0000 @@ -164,6 +164,8 @@ imgUrl += "&server=" + config.getServerUrl(); imgUrl += "&locale=" + config.getLocale(); imgUrl += "×tamp=" + new Date().getTime(); + imgUrl += "&width=" + Integer.toString(600); + imgUrl += "&height=" + Integer.toString(500); return imgUrl; } diff -r e763d8efd42f -r b493d606fdef 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 Thu May 12 07:08:27 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/ChartOutputServiceImpl.java Thu May 12 09:14:46 2011 +0000 @@ -4,12 +4,16 @@ import java.io.IOException; 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; @@ -25,6 +29,13 @@ 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"); @@ -35,10 +46,9 @@ String uuid = req.getParameter("uuid"); String type = req.getParameter("type"); String locale = req.getParameter("locale"); - String mimeType = "image/png"; Document request = ClientProtocolUtils.newOutCollectionDocument( - uuid, type); + uuid, type, getChartAttributes(req)); HttpClient client = new HttpClientImpl(serverUrl, locale); client.collectionOut(request, uuid, "chart", out); @@ -49,5 +59,63 @@ catch (IOException ioe) { System.err.println(ioe.getMessage()); } + catch (Exception e) { + 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); + + appendChartSize(req, doc, ec); + + 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 doc The attribute document used to adjust chart settings. + * @param ec The ElementCreator that might be used to create new Elements. + */ + protected void appendChartSize( + HttpServletRequest req, + Document doc, + 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); + + doc.appendChild(size); } } +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :