# HG changeset patch # User Ingo Weinzierl # Date 1301309145 0 # Node ID 9ca5160cf0800b7c66c66a343f670ad792469cf4 # Parent 5b5ec0403844b1909d43ba1c61d820d5b9c68a92 Added a service that builds up requests to retrieve chart images. Use this service to display charts in the ChartOutputTab. flys-client/trunk@1584 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 5b5ec0403844 -r 9ca5160cf080 flys-client/ChangeLog --- a/flys-client/ChangeLog Mon Mar 28 10:40:50 2011 +0000 +++ b/flys-client/ChangeLog Mon Mar 28 10:45:45 2011 +0000 @@ -1,3 +1,19 @@ +2011-03-28 Ingo Weinzierl + + * src/main/java/de/intevation/flys/client/client/ui/ChartOutputTab.java: + The right side of this panel displays an image now. This image + represents a chart that is generated by an artifact. The request is made + up in the ChartOutputServiceImpl. + + * src/main/java/de/intevation/flys/client/server/ChartOutputServiceImpl.java: + New. This service creates the request to retrieve chart images and + writes the response to the output stream. + + NOTE: This service is not asynchron! It is derived directly from + HttpServlet. + + * src/main/webapp/WEB-INF/web.xml: Registered the ChartOutputService. + 2011-03-25 Raimund Renkert * src/main/java/de/intevation/flys/client/client/ui/CollectionView.java: diff -r 5b5ec0403844 -r 9ca5160cf080 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 Mon Mar 28 10:40:50 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ChartOutputTab.java Mon Mar 28 10:45:45 2011 +0000 @@ -1,5 +1,7 @@ package de.intevation.flys.client.client.ui; +import com.google.gwt.core.client.GWT; + import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.Img; import com.smartgwt.client.widgets.Label; @@ -48,6 +50,8 @@ Label todo = new Label("TODO: Implement theme editor."); Img chart = getChartImg(); + chart.setWidth100(); + chart.setHeight100(); left.addChild(todo); right.addChild(chart); @@ -74,10 +78,24 @@ protected String getImgUrl() { Config config = Config.getInstance(); String server = config.getServerUrl(); + String uuid = collection.getItem(0).identifier(); + + String imgUrl = GWT.getModuleBaseURL(); + imgUrl += "chart"; + imgUrl += "?target=chart"; + imgUrl += "&server=" + server; + imgUrl += "&mode=img"; + imgUrl += "&width=600"; + imgUrl += "&height=400"; + imgUrl += "&points=false"; + imgUrl += "&uuid=" + uuid; + imgUrl += "&hash=" + "TODO-HASH"; + + GWT.log("IMAGE URL = " + imgUrl); // TODO Build the correct url that points to the OUT() resource of the // collection. - return server; + return imgUrl; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 5b5ec0403844 -r 9ca5160cf080 flys-client/src/main/java/de/intevation/flys/client/server/ChartOutputServiceImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/ChartOutputServiceImpl.java Mon Mar 28 10:45:45 2011 +0000 @@ -0,0 +1,63 @@ +package de.intevation.flys.client.server; + +import java.io.OutputStream; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.w3c.dom.Document; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import de.intevation.artifacts.httpclient.http.HttpClient; +import de.intevation.artifacts.httpclient.http.HttpClientImpl; +import de.intevation.artifacts.httpclient.objects.Artifact; +import de.intevation.artifacts.httpclient.utils.ArtifactProtocolUtils; + + +/** + * This service is used to request a chart from the artifact server. The + * response is directed directly to the output stream, so the image that is + * retrieved is displayed in the UI afterwards. + * + * @author Ingo Weinzierl + */ +public class ChartOutputServiceImpl +extends HttpServlet +{ + public void doGet(HttpServletRequest req, HttpServletResponse resp) { + System.out.println("ChartOutputServiceImpl.doGet"); + + try { + OutputStream out = resp.getOutputStream(); + + String serverUrl = req.getParameter("server"); + String uuid = req.getParameter("uuid"); + String hash = req.getParameter("hash"); + String width = req.getParameter("width"); + String height = req.getParameter("height"); + String target = req.getParameter("target"); + String mimeType = "image/png"; + + Map opts = new HashMap(); + opts.put("width", width); + opts.put("height", height); + opts.put("mimeType", mimeType); + opts.put("points", "false"); + + Document chart = ArtifactProtocolUtils.createChartDocument( + new Artifact(hash, uuid), opts); + + HttpClient client = new HttpClientImpl(serverUrl); + client.out(new Artifact(uuid, hash), chart, target, out); + + out.close(); + out.flush(); + } + catch (IOException ioe) { + System.err.println(ioe.getMessage()); + } + } +} diff -r 5b5ec0403844 -r 9ca5160cf080 flys-client/src/main/webapp/WEB-INF/web.xml --- a/flys-client/src/main/webapp/WEB-INF/web.xml Mon Mar 28 10:40:50 2011 +0000 +++ b/flys-client/src/main/webapp/WEB-INF/web.xml Mon Mar 28 10:45:45 2011 +0000 @@ -75,6 +75,16 @@ add-artifact /flys/add-artifact + + + ChartOutputService + de.intevation.flys.client.server.ChartOutputServiceImpl + + + + ChartOutputService + /flys/chart +