changeset 78:9ca5160cf080

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
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 28 Mar 2011 10:45:45 +0000
parents 5b5ec0403844
children 17815a7354bc
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/ChartOutputTab.java flys-client/src/main/java/de/intevation/flys/client/server/ChartOutputServiceImpl.java flys-client/src/main/webapp/WEB-INF/web.xml
diffstat 4 files changed, 108 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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 <ingo@intevation.de>
+
+	* 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 <rrenkert@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/CollectionView.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 :
--- /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 <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+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());
+        }
+    }
+}
--- 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 @@
     <servlet-name>add-artifact</servlet-name>
     <url-pattern>/flys/add-artifact</url-pattern>
   </servlet-mapping>
+  
+  <servlet>
+    <servlet-name>ChartOutputService</servlet-name>
+    <servlet-class>de.intevation.flys.client.server.ChartOutputServiceImpl</servlet-class>
+  </servlet>
+
+  <servlet-mapping>
+    <servlet-name>ChartOutputService</servlet-name>
+    <url-pattern>/flys/chart</url-pattern>
+  </servlet-mapping>
 
   <!-- Default page to serve -->
   <welcome-file-list>

http://dive4elements.wald.intevation.org