changeset 668:ccd47d9887ec

Added an options panel for wms customization (issue198). gnv/trunk@775 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 15 Mar 2010 13:46:05 +0000
parents c4f051adc6e7
children ef1ff5fdab5b
files gnv/ChangeLog gnv/src/main/java/de/intevation/gnv/action/WMSAction.java gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java gnv/src/main/resources/applicationMessages.properties gnv/src/main/resources/applicationMessages_en.properties gnv/src/main/webapp/WEB-INF/jsp/includes/display_wms_options_inc.jsp gnv/src/main/webapp/WEB-INF/jsp/index.jsp
diffstat 8 files changed, 171 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/gnv/ChangeLog	Fri Mar 12 11:56:07 2010 +0000
+++ b/gnv/ChangeLog	Mon Mar 15 13:46:05 2010 +0000
@@ -1,9 +1,36 @@
+2010-03-15  Ingo Weinzierl <ingo.weinzierl@intevation.de>
+
+	  Issue198
+
+	* src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java,
+	  src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java:
+	  Added the method signature for publishing wms layers. 'publishWMS'
+	  requires a collection of InputParameters which are used to create the
+	  request xml document. These input parameters can be used to adjust some
+	  wms settings. At the moment, the only parameter which written to the
+	  request xml document is the title for a wms layer.
+
+	* src/main/java/de/intevation/gnv/action/WMSAction.java: Search for user
+	  input and append given input values to request xml document. Put the layer
+	  title into request object to be accessible in jsp files.
+
+	* src/main/webapp/WEB-INF/jsp/index.jsp: Render wms option panel if wms is
+	  requested.
+
+	* src/main/webapp/WEB-INF/jsp/includes/display_wms_options_inc.jsp: New.
+	  Option panel for wms customization. At the moment, the user has the
+	  possibility to adjust wms layers' title.
+
+	* src/main/resources/applicationMessages.properties,
+	  src/main/resources/applicationMessages_en.properties: Added some labels
+	  for wms options.
+
 2010-03-12  Tim Englich  <tim.englich@intevation.de>
 
 	* src/test/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClientTestCase.java (testArtifactDatabaseClient):
 	  Fixed Compilation-Error because of InterfaceChanges of the 
 	  ArtifactDatabaseClient-Interface.
- 
+
 2010-03-12  Tim Englich  <tim.englich@intevation.de>
 
 	* src/main/resources/applicationMessages*.properties: 
--- a/gnv/src/main/java/de/intevation/gnv/action/WMSAction.java	Fri Mar 12 11:56:07 2010 +0000
+++ b/gnv/src/main/java/de/intevation/gnv/action/WMSAction.java	Mon Mar 15 13:46:05 2010 +0000
@@ -1,5 +1,9 @@
 package de.intevation.gnv.action;
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
@@ -10,11 +14,16 @@
 
 import org.w3c.dom.Document;
 
+import de.intevation.gnv.action.sessionmodel.DiagrammOptions;
 import de.intevation.gnv.action.sessionmodel.SessionModel;
 import de.intevation.gnv.action.sessionmodel.SessionModelFactory;
 import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClient;
 import de.intevation.gnv.artifactdatabase.client.ArtifactDatabaseClientFactory;
 import de.intevation.gnv.artifactdatabase.objects.ArtifactObject;
+import de.intevation.gnv.artifactdatabase.objects.DefaultInputParameter;
+import de.intevation.gnv.artifactdatabase.objects.InputParameter;
+import de.intevation.gnv.artifactdatabase.objects.OutputMode;
+import de.intevation.gnv.artifactdatabase.objects.OutputParameter;
 import de.intevation.gnv.util.XMLUtils;
 
 /**
@@ -28,6 +37,9 @@
     public static final String XPATH_MAPSERVER_MAPFILE =
         "/art:meta/art:mapserver/art:map/text()";
 
+    public static final String XPATH_LAYER_TITLE =
+        "/art:meta/art:layer/art:title/text()";
+
     /**
      * the logger, used to log exceptions and additonaly information
      */
@@ -48,6 +60,39 @@
         try {
             SessionModel sm = SessionModelFactory.getInstance().getSessionModel(
                 request);
+
+            OutputMode outputMode          = sm.getOutputMode("wms");
+            Collection<InputParameter> ips = null;
+            if (outputMode != null) {
+                Collection<OutputParameter> inputParameter =
+                    outputMode.getOutputParameters();
+
+                if (inputParameter != null) {
+                    ips = new ArrayList<InputParameter>(inputParameter.size());
+                    Iterator<OutputParameter> it = inputParameter.iterator();
+                    DiagrammOptions diagrammOptions = new DiagrammOptions();
+
+                    int params = 0;
+                    while (it.hasNext()) {
+                        String name       = it.next().getName();
+                        String[] values   = request.getParameterValues(name);
+                        String value      = request.getParameter(name);
+                        InputParameter ip = new DefaultInputParameter(name,
+                                values);
+                        ips.add(ip);
+
+                        if (value != null) {
+                            ++params;
+                            diagrammOptions.setValue(name, value);
+                        }
+                    }
+
+                    if (params > 0) {
+                        sm.setDiagrammOptions(diagrammOptions);
+                    }
+                }
+            }
+
             ArtifactObject artifact = sm.getCurrentArtifact();
 
             ArtifactDatabaseClientFactory factory =
@@ -57,15 +102,25 @@
             ArtifactObject artifactfactory = sm.getSelectedArtifactFactory();
 
             // do wms publishing
-            Document meta        = adc.publishWMS(artifactfactory, artifact);
+            Document meta        = adc.publishWMS(artifactfactory,artifact,ips);
             String mapserverPath = XMLUtils.getStringXPath(
                 meta, XPATH_MAPSERVER_PATH);
             String mapfilePath   = XMLUtils.getStringXPath(
                 meta, XPATH_MAPSERVER_MAPFILE);
+            String layer         = XMLUtils.getStringXPath(
+                meta, XPATH_LAYER_TITLE);
+            layer                = layer != null ? layer : artifact.getId();
 
+            if (logger.isDebugEnabled()) {
+                logger.debug("Mapserver path: " + mapserverPath);
+                logger.debug("Mapfile path: " + mapfilePath);
+                logger.debug("Layer title: " + layer);
+            }
+
+            request.setAttribute("wms", true);
             request.setAttribute("mapserver", mapserverPath);
             request.setAttribute("mapfile", mapfilePath);
-            request.setAttribute("layer", artifact.getId());
+            request.setAttribute("layer", layer);
 
             return super.execute(mapping, form, request, response);
         }
--- a/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java	Fri Mar 12 11:56:07 2010 +0000
+++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java	Mon Mar 15 13:46:05 2010 +0000
@@ -113,7 +113,11 @@
      * @param artifact
      * @return URL to wms service as string
      */
-    public Document publishWMS(ArtifactObject factory, ArtifactObject artifact);
+    public Document publishWMS(
+        ArtifactObject             factory,
+        ArtifactObject             artifact,
+        Collection<InputParameter> inputParameter
+    );
 
 
     /**
--- a/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java	Fri Mar 12 11:56:07 2010 +0000
+++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java	Mon Mar 15 13:46:05 2010 +0000
@@ -792,29 +792,29 @@
 
     private void check4ExceptionReport(Document document)
     throws ArtifactDatabaseClientException, ArtifactDatabaseInputException {
-        log.debug("REPORT: " + XMLUtils.writeDocument2String(document));
-
         String message = new XMLUtils().getStringXPath(document,
             EXCEPTION_GENERAL);
         if (message != null) {
-            log.error("FOUND GENERAL EXCEPTION !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
             throw new ArtifactDatabaseClientException(message);
         }
 
         String input = XMLUtils.getStringXPath(document, EXCEPTION_USER_INPUT);
         if (input != null) {
-            log.error("FOUND INPUT EXCEPTION !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
             throw new ArtifactDatabaseInputException(input);
         }
     }
 
-    public Document publishWMS(ArtifactObject factory, ArtifactObject artifact) {
+    public Document publishWMS(
+        ArtifactObject             factory,
+        ArtifactObject             artifact,
+        Collection<InputParameter> inputParameter
+    ) {
         log.debug("Start wms publishing...");
 
         String target     = "wms";
         String requestURL = getArtifactUrl(factory, artifact) + "/" + target;
         Document request  = createOutRequestBody(
-            artifact, target, "", "text/xml", null);
+            artifact, target, "", "text/xml", inputParameter);
         try {
             InputStream input = doPostRequest(requestURL, request);
             Document result   = XMLUtils.readDocument(input);
--- a/gnv/src/main/resources/applicationMessages.properties	Fri Mar 12 11:56:07 2010 +0000
+++ b/gnv/src/main/resources/applicationMessages.properties	Mon Mar 15 13:46:05 2010 +0000
@@ -70,6 +70,7 @@
 # wms
 gnviewer.wms.server.path=URL des WMS
 gnviewer.wms.server.layer=Name des Layers
+gnviewer.wms.options.header.title=WMS Optionen
 
 # attachedOutputOptions
 gnviewer.output.options.diagramm.alt=Diagramm
@@ -88,6 +89,7 @@
 height=H\u00f6he
 width=Breite
 points=Zeichne Datenpunkte
+title=Titel
 
 # Fehlermeldungen:
 
--- a/gnv/src/main/resources/applicationMessages_en.properties	Fri Mar 12 11:56:07 2010 +0000
+++ b/gnv/src/main/resources/applicationMessages_en.properties	Mon Mar 15 13:46:05 2010 +0000
@@ -70,6 +70,7 @@
 # wms
 gnviewer.wms.server.path=WMS URL
 gnviewer.wms.server.layer=Layername
+gnviewer.wms.options.header.title=WMS Optionen
 
 # attachedOutputOptions
 gnviewer.output.options.diagramm.alt=Diagram
@@ -88,6 +89,7 @@
 height=Height
 width=Width
 points=Draw data points
+title=Title
 
 java.io.ioexception..connection.refused = The Connection to the ArtifactDatabase is interrupted. Please try again later.
 java.io.ioexception..unable.to.parse.the.response.http.version..end.of.stream.reached.too.early= The Connection to the ArtifactDatabase was interrupted unexpected.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv/src/main/webapp/WEB-INF/jsp/includes/display_wms_options_inc.jsp	Mon Mar 15 13:46:05 2010 +0000
@@ -0,0 +1,66 @@
+<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
+<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean-el" prefix="bean-el" %>
+<%@page import="de.intevation.gnv.action.CommunicationKeys"%>
+<%@page import="de.intevation.gnv.action.sessionmodel.DiagrammOptions"%>
+<%@page import="de.intevation.gnv.action.sessionmodel.SessionModel"%>
+<%@page import="de.intevation.gnv.action.sessionmodel.SessionModelFactory"%>
+<%@page import="de.intevation.gnv.artifactdatabase.objects.OutputMode"%>
+<%@page import="de.intevation.gnv.artifactdatabase.objects.OutputParameter"%>
+<%@page import="java.util.Collection"%>
+<%@page import="java.util.Iterator"%>
+<%@page import="java.net.URLEncoder"%>
+<%
+    String exceptionMsg  = (String) request.getAttribute(CommunicationKeys.REQUEST_EXCEPTION_MESSAGE);
+    String exceptionValue= (String) request.getAttribute(CommunicationKeys.REQUEST_EXCEPTION_VALUE);
+    String layer         = (String) request.getAttribute("layer");
+    String target        = "wms";
+    SessionModel      sm = SessionModelFactory.getInstance().getSessionModel(request);
+    OutputMode        om = sm.getOutputMode(target);
+    DiagrammOptions opts = sm.getDiagrammOptions();
+    String uuid          = sm.getCurrentArtifact().getId();
+%>
+
+<div id="diagramOptionsContent">
+    <fieldset>
+        <legend onmousedown="displayDiv('diagramOptionsContent');" class="expandableFieldset">
+            <bean:message key="gnviewer.wms.options.header.title"/>
+        </legend>
+
+        <% if (exceptionMsg != null) {%>
+            <div id="chartException" class="chartException">
+                '<%=exceptionValue%>' <bean-el:message key="<%=exceptionMsg%>"/>
+            </div>
+        <%}%>
+
+        <form id="outputOptionsForm" method="POST" action="<%=response.encodeURL("wms.do")%>">
+            <table>
+            <%  Collection<OutputParameter> params = om.getOutputParameters();
+                if (om != null && params != null && !params.isEmpty()) {
+                    Iterator<OutputParameter> iter = params.iterator();
+                    while (iter.hasNext()) {
+                        OutputParameter param = iter.next(); %>
+
+                        <tr>
+                            <td><bean-el:message key="<%=param.getName()%>"/></td>
+                            <td>
+                                <%if (param.getType().equalsIgnoreCase("boolean")) {
+                                    boolean checked = (opts != null) ? "true".equalsIgnoreCase(opts.getValue(param.getName())) : param.getValue().equalsIgnoreCase("true");
+                                %>
+                                    <input type="checkbox" name="<%=param.getName()%>" <%=checked ? " value=\"true\" checked=\"checked\"": "" %>/>
+                                <%}
+                                else {%>
+                                    <input type="text" name="<%=param.getName() %>" value="<%= (opts != null) ? opts.getValue(param.getName()) : param.getValue()%>"/>
+                                <%}%>
+                            </td>
+                        </tr>
+                    <%}
+                }%>
+                <tr>
+                    <td>
+                        <input type="image" name="target" value="wms" src="images/arrow_refresh.png" alt="<bean:message key="gnviewer.draw.button"/>"/>
+                    </td>
+                </tr>
+            </table>
+        </form>
+    </fieldset>
+</div>
--- a/gnv/src/main/webapp/WEB-INF/jsp/index.jsp	Fri Mar 12 11:56:07 2010 +0000
+++ b/gnv/src/main/webapp/WEB-INF/jsp/index.jsp	Mon Mar 15 13:46:05 2010 +0000
@@ -79,3 +79,8 @@
     <%if (histogram != null) {%>
         <jsp:include page="includes/display_histogram_inc.jsp"></jsp:include>
     <%}%>
+
+    <%-- render wms options --%>
+    <%if (wms != null) {%>
+        <jsp:include page="/WEB-INF/jsp/includes/display_wms_options_inc.jsp"></jsp:include>
+    <%}%>

http://dive4elements.wald.intevation.org