changeset 2493:f905c936ffff

Added the XSL transformation to generate the fixings overview. flys-client/trunk@4286 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 20 Apr 2012 15:23:27 +0000
parents e64e0d094843
children 88b51e6e0334
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/services/FixingsOverviewService.java flys-client/src/main/java/de/intevation/flys/client/client/services/FixingsOverviewServiceAsync.java flys-client/src/main/java/de/intevation/flys/client/server/FixingsKMChartServiceImpl.java flys-client/src/main/java/de/intevation/flys/client/server/FixingsOverviewServiceImpl.java flys-client/src/main/webapp/WEB-INF/stylesheets/fixoverview2html.xsl
diffstat 6 files changed, 207 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Fri Apr 20 11:02:26 2012 +0000
+++ b/flys-client/ChangeLog	Fri Apr 20 15:23:27 2012 +0000
@@ -1,3 +1,18 @@
+2012-04-20	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/server/FixingsKMChartServiceImpl.java:
+	  Use the XSL transform to render the overview.
+
+	* src/main/java/de/intevation/flys/client/server/FixingsOverviewServiceImpl.java,
+	  src/main/java/de/intevation/flys/client/client/services/FixingsOverviewServiceAsync.java:
+	  Adjusted signature to pass locale, too.
+
+	* src/main/java/de/intevation/flys/client/client/services/FixingsOverviewService.java:
+	  Simplification.
+
+	* src/main/webapp/WEB-INF/stylesheets/fixoverview2html.xsl: New. Generates the
+	  HTML table overview.
+
 2012-04-20	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/webapp/WEB-INF/web.xml: Fixed incorrect servlet mapping.
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/FixingsOverviewService.java	Fri Apr 20 11:02:26 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/FixingsOverviewService.java	Fri Apr 20 15:23:27 2012 +0000
@@ -9,6 +9,7 @@
 public interface FixingsOverviewService extends RemoteService {
 
     String generateOverview(
+        String  locale,
         String  uuid,
         boolean checkboxes,
         String  filter
--- a/flys-client/src/main/java/de/intevation/flys/client/client/services/FixingsOverviewServiceAsync.java	Fri Apr 20 11:02:26 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/FixingsOverviewServiceAsync.java	Fri Apr 20 15:23:27 2012 +0000
@@ -5,6 +5,7 @@
 public interface FixingsOverviewServiceAsync {
 
     void generateOverview(
+        String  locale,
         String  uuid,
         boolean checkboxes,
         String  filter,
--- a/flys-client/src/main/java/de/intevation/flys/client/server/FixingsKMChartServiceImpl.java	Fri Apr 20 11:02:26 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/FixingsKMChartServiceImpl.java	Fri Apr 20 15:23:27 2012 +0000
@@ -58,15 +58,10 @@
             return;
         }
 
-        HttpClient client;
-
-        client = new HttpClientImpl(url, locale);
-
-        resp.setHeader("Content-Type", guessMIMEType(filterDoc));
-
         InputStream in;
         
         try {
+            HttpClient client = new HttpClientImpl(url, locale);
             in = (InputStream)client.callService(
                 url, // XXX: Why? The URL is passed by construction already.
                 SERVICE_NAME,
@@ -78,6 +73,8 @@
             return;
         }
 
+        resp.setHeader("Content-Type", guessMIMEType(filterDoc));
+
         try {
             OutputStream out = resp.getOutputStream();
 
--- a/flys-client/src/main/java/de/intevation/flys/client/server/FixingsOverviewServiceImpl.java	Fri Apr 20 11:02:26 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/FixingsOverviewServiceImpl.java	Fri Apr 20 15:23:27 2012 +0000
@@ -2,23 +2,83 @@
 
 import com.google.gwt.user.server.rpc.RemoteServiceServlet;
 
+import de.intevation.artifacts.common.utils.XMLUtils;
+import de.intevation.artifacts.common.utils.XSLTransformer;
+
+import de.intevation.artifacts.httpclient.exceptions.ConnectionException;
+
+import de.intevation.artifacts.httpclient.http.HttpClient;
+import de.intevation.artifacts.httpclient.http.HttpClientImpl;
+
 import de.intevation.flys.client.client.services.FixingsOverviewService;
 
 import de.intevation.flys.client.shared.exceptions.ServerException;
 
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.log4j.Logger;
+
+import org.w3c.dom.Document;
+
 public class FixingsOverviewServiceImpl
 extends      RemoteServiceServlet
 implements   FixingsOverviewService
 {
+    private static final Logger log =
+        Logger.getLogger(FixingsOverviewServiceImpl.class);
+
+    public static final String SERVICE_NAME = "fixings-overview";
+
+    public static final String XSL_TRANSFORM =
+        "/WEB-INF/stylesheets/fixoverview2html.xsl";
+
     @Override
     public String generateOverview(
+        String locale,
         String  uuid,
         boolean checkboxes,
         String  filter
     ) 
     throws ServerException
     {
-        // TODO: Implement me!
+        log.info("FixingsOverviewServiceImpl.doGet");
+
+        if (filter == null || filter.length() == 0) {
+            log.warn("Missing 'filter' parameter.");
+            return "";
+        }
+
+        Document filterDoc = XMLUtils.jsonToXML(filter);
+
+        if (filterDoc == null) {
+            log.warn("Creating filter document failed.");
+            return "";
+        }
+
+        InputStream transform =
+            getServletContext().getResourceAsStream(XSL_TRANSFORM);
+
+        try {
+            String url = getServletContext().getInitParameter("server-url");
+            HttpClient client = new HttpClientImpl(url, locale);
+            Document resultDoc =
+                client.callService(url, SERVICE_NAME, filterDoc);
+            XSLTransformer xformer = new XSLTransformer();
+            xformer.addParameter("project-uuid", uuid);
+            xformer.addParameter(
+                "render-checkboxes", checkboxes ? "true()" : "false()");
+            String result = xformer.transform(resultDoc, transform);
+            return result != null ? result : "";
+        }
+        catch (ConnectionException ce) {
+            log.error(ce);
+        }
+        finally {
+            try { transform.close(); }
+            catch (IOException ioe) {}
+        }
+
         return "";
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/webapp/WEB-INF/stylesheets/fixoverview2html.xsl	Fri Apr 20 15:23:27 2012 +0000
@@ -0,0 +1,126 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet
+  version="1.0"
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+  <xsl:output method="html" encoding="UTF-8"/>
+
+  <xsl:param name="project-uuid">de3f3307-3429-4ff9-8f43-3fb2fcf21b27</xsl:param>
+  <xsl:param name="render-checkboxes" select="true()"/>
+
+  <xsl:template name="percent">
+    <xsl:param name="sector"/>
+    <xsl:variable name="rfrom" select="number(/fixings/river/@from)"/>
+    <xsl:variable name="rto" select="number(/fixings/river/@to)"/>
+    <xsl:variable name="rlength" select="$rto - $rfrom"/>
+
+    <xsl:variable name="sfrom" select="number($sector/@from)"/>
+    <xsl:variable name="sto" select="number($sector/@to)"/>
+    <xsl:variable name="slength" select="$sto - $sfrom"/>
+    <xsl:value-of select="100.0 * ($slength div $rlength)"/>
+  </xsl:template>
+
+  <xsl:template name="emit-gap">
+    <xsl:param name="sector"/>
+    <xsl:variable name="preds" select="$sector/preceding-sibling::sector"/>
+    <xsl:variable name="num-preds" select="count($preds)"/>
+    <xsl:variable name="glength">
+      <xsl:choose>
+        <xsl:when test="$num-preds &lt; 1">
+          <xsl:variable name="rfrom" select="number(/fixings/river/@from)"/>
+          <xsl:value-of select="number($sector/@from) - $rfrom"/>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:variable name="bend" select="number($preds[last()]/@to)"/>
+          <xsl:value-of select="number($sector/@from) - $bend"/>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:variable>
+    <xsl:choose>
+      <xsl:when test="number($glength) &lt; 0.05 "/>
+      <xsl:otherwise>
+        <div>
+          <xsl:attribute name="style">
+            <xsl:text>width:</xsl:text>
+              <xsl:variable name="rfrom" select="number(/fixings/river/@from)"/>
+              <xsl:variable name="rto" select="number(/fixings/river/@to)"/>
+              <xsl:variable name="rlength" select="$rto - $rfrom"/>
+              <xsl:value-of select="100.0 * ($glength div $rlength)"/>
+            <xsl:text>%;float:left</xsl:text>
+          </xsl:attribute>
+          <xsl:text disable-output-escaping="yes"><![CDATA[&nbsp;]]></xsl:text>
+        </div>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+  <xsl:template match="sector" mode="sectors">
+    <xsl:call-template name="emit-gap">
+      <xsl:with-param name="sector" select="."/>
+    </xsl:call-template>
+    <div>
+      <xsl:attribute name="style">
+        <xsl:text>background:</xsl:text>
+        <xsl:choose>
+          <xsl:when test="@class = '0'">green</xsl:when>
+          <xsl:when test="@class = '1'">blue</xsl:when>
+          <xsl:when test="@class = '2'">magenta</xsl:when>
+          <xsl:when test="@class = '3'">red</xsl:when>
+          <xsl:otherwise>black</xsl:otherwise>
+        </xsl:choose>
+        <xsl:text>;width:</xsl:text>
+        <xsl:call-template name="percent">
+          <xsl:with-param name="sector" select="."/>
+        </xsl:call-template>
+        <xsl:text>%</xsl:text>
+        <xsl:text>;float:left</xsl:text>
+      </xsl:attribute>
+      <xsl:attribute name="title">
+        <xsl:text>km </xsl:text>
+        <xsl:value-of select="@from"/>
+        <xsl:text> - </xsl:text>
+        <xsl:value-of select="@to"/>
+      </xsl:attribute>
+      <xsl:text disable-output-escaping="yes"><![CDATA[&nbsp;]]></xsl:text>
+    </div>
+  </xsl:template>
+
+  <xsl:template match="event">
+    <tr>
+      <xsl:if test="$render-checkboxes">
+        <td>
+          <input type="checkbox" name="{$project-uuid}:{@cid}"/>
+        </td>
+      </xsl:if>
+      <td>
+        <xsl:apply-templates mode="sectors"/>
+      </td>
+      <td align="center">
+        <xsl:attribute name="title"><xsl:value-of select="@name"/></xsl:attribute>
+        <xsl:value-of select="@date"/>
+      </td>
+    </tr>
+  </xsl:template>
+
+  <xsl:template match="events">
+    <table width="95%" border="1" cellspacing="0" cellpadding="0"
+           style="font-size: 11pt;font-family:Arial;Verdana,sans-serif">
+      <colgroup>
+        <xsl:if test="$render-checkboxes">
+            <col width="1em"/>
+        </xsl:if>
+        <col width="*"/>
+        <col width="11em"/>
+      </colgroup>
+      <xsl:apply-templates/>
+    </table>
+  </xsl:template>
+
+  <xsl:template match="/">
+    <xsl:apply-templates/>
+  </xsl:template>
+
+  <xsl:template match="text()"/>
+  <xsl:template match="text()" mode="sectors"/>
+
+</xsl:stylesheet>

http://dive4elements.wald.intevation.org