changeset 585:2e690cb2247c

Show information about MapServer path and layer name after publishing calculated shapefiles as wms. Use MapServer settings configured in conf.xml to feed OpenLayers client. gnv/trunk@736 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 05 Mar 2010 09:33:30 +0000
parents b31e81f35b64
children 97d90e314af5
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/java/de/intevation/gnv/util/XMLUtils.java gnv/src/main/resources/applicationMessages.properties gnv/src/main/resources/applicationMessages_en.properties gnv/src/main/webapp/WEB-INF/jsp/wmslayout.jsp gnv/src/main/webapp/styles/default.css
diffstat 9 files changed, 141 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/gnv/ChangeLog	Thu Mar 04 14:27:26 2010 +0000
+++ b/gnv/ChangeLog	Fri Mar 05 09:33:30 2010 +0000
@@ -1,3 +1,29 @@
+2010-03-05  Ingo Weinzierl <ingo.weinzierl@intevation.de>
+
+	* src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java,
+	  src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java:
+	  'publishWMS' returns a whole document which contains meta information used
+	  for mapfile generation - not just a string. These information contain
+	  MapServer URL and the path to its mapfile.
+
+	* src/main/java/de/intevation/gnv/action/WMSAction.java: Fetch MapServer
+	  settings from resulting document after wms-publishing to display these
+	  values in gui.
+
+	* src/main/java/de/intevation/gnv/util/XMLUtils.java: Converted class
+	  methods into static methods to use them without initializing an object of
+	  XMLUtils.
+
+	* src/main/webapp/WEB-INF/jsp/wmslayout.jsp: Show MapServer and layer
+	  information in gui and use MapServer settings to feed OpenLayers client.
+
+	* src/main/webapp/styles/default.css: Added some classes to adjust style of
+	  information table (wms service, layer name) and map area.
+
+	* src/main/resources/applicationMessages.properties,
+	  src/main/resources/applicationMessages_en.properties: Added column labels 
+	  for displaying MapServer information.
+
 2010-03-04  Ingo Weinzierl <ingo.weinzierl@intevation.de>
 
 	* src/main/webapp/WEB-INF/jsp/index.jsp,
--- a/gnv/src/main/java/de/intevation/gnv/action/WMSAction.java	Thu Mar 04 14:27:26 2010 +0000
+++ b/gnv/src/main/java/de/intevation/gnv/action/WMSAction.java	Fri Mar 05 09:33:30 2010 +0000
@@ -8,16 +8,26 @@
 import org.apache.struts.action.ActionForward;
 import org.apache.struts.action.ActionMapping;
 
+import org.w3c.dom.Document;
+
 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.util.XMLUtils;
 
 /**
  * @author Ingo Weinzierl (ingo.weinzierl@intevation.de)
  */
 public class WMSAction extends DescribeUIAction {
+
+    public static final String XPATH_MAPSERVER_PATH =
+        "/art:meta/art:mapserver/art:server/text()";
+
+    public static final String XPATH_MAPSERVER_MAPFILE =
+        "/art:meta/art:mapserver/art:map/text()";
+
     /**
      * the logger, used to log exceptions and additonaly information
      */
@@ -47,7 +57,14 @@
             ArtifactObject artifactfactory = sm.getSelectedArtifactFactory();
 
             // do wms publishing
-            String url = adc.publishWMS(artifactfactory, artifact);
+            Document meta        = adc.publishWMS(artifactfactory, artifact);
+            String mapserverPath = XMLUtils.getStringXPath(
+                meta, XPATH_MAPSERVER_PATH);
+            String mapfilePath   = XMLUtils.getStringXPath(
+                meta, XPATH_MAPSERVER_MAPFILE);
+
+            request.setAttribute("mapserver", mapserverPath);
+            request.setAttribute("mapfile", mapfilePath);
             request.setAttribute("layer", artifact.getId());
 
             return super.execute(mapping, form, request, response);
--- a/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java	Thu Mar 04 14:27:26 2010 +0000
+++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/ArtifactDatabaseClient.java	Fri Mar 05 09:33:30 2010 +0000
@@ -1,6 +1,3 @@
-/**
- *
- */
 package de.intevation.gnv.artifactdatabase.client;
 
 import java.io.IOException;
@@ -8,6 +5,8 @@
 import java.util.Collection;
 import java.util.Locale;
 
+import org.w3c.dom.Document;
+
 import de.intevation.gnv.artifactdatabase.client.exception.ArtifactDatabaseClientException;
 import de.intevation.gnv.artifactdatabase.objects.ArtifactDescription;
 import de.intevation.gnv.artifactdatabase.objects.ArtifactObject;
@@ -16,8 +15,8 @@
 import de.intevation.gnv.artifactdatabase.objects.map.MapService;
 
 /**
- * @author Tim Englich <tim.englich@intevation.de>
- * 
+ * @author Tim Englich (tim.englich@intevation.de)
+ * @author Ingo Weinzierl (ingo.weinzierl@intevation.de)
  */
 public interface ArtifactDatabaseClient {
 
@@ -113,7 +112,7 @@
      * @param artifact
      * @return URL to wms service as string
      */
-    public String publishWMS(ArtifactObject factory, ArtifactObject artifact);
+    public Document publishWMS(ArtifactObject factory, ArtifactObject artifact);
 
 
     /**
--- a/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java	Thu Mar 04 14:27:26 2010 +0000
+++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java	Fri Mar 05 09:33:30 2010 +0000
@@ -788,7 +788,7 @@
 
     }
 
-    public String publishWMS(ArtifactObject factory, ArtifactObject artifact) {
+    public Document publishWMS(ArtifactObject factory, ArtifactObject artifact) {
         log.debug("Start wms publishing...");
 
         String target     = "wms";
@@ -798,14 +798,13 @@
         try {
             InputStream input = doPostRequest(requestURL, request);
             Document result   = XMLUtils.readDocument(input);
+
+            return result;
         }
         catch (IOException ioe) {
             log.error(ioe, ioe);
             return null;
         }
-
-        // TODO Return URL to WMS service
-        return null;
     }
 
     public Collection<ArtifactStatisticsSet> calculateStatistics(
--- a/gnv/src/main/java/de/intevation/gnv/util/XMLUtils.java	Thu Mar 04 14:27:26 2010 +0000
+++ b/gnv/src/main/java/de/intevation/gnv/util/XMLUtils.java	Fri Mar 05 09:33:30 2010 +0000
@@ -64,7 +64,7 @@
         }
     } // class ElementCreator
 
-    public Document newDocument() {
+    public static Document newDocument() {
         try {
             return DocumentBuilderFactory.newInstance().newDocumentBuilder()
                     .newDocument();
@@ -74,11 +74,11 @@
         return null;
     }
 
-    public XPath newXPath() {
+    public static XPath newXPath() {
         return newXPath(null);
     }
 
-    public XPath newXPath(NamespaceContext namespaceContext) {
+    public static XPath newXPath(NamespaceContext namespaceContext) {
         XPathFactory factory = XPathFactory.newInstance();
         XPath xpath = factory.newXPath();
         if (namespaceContext != null) {
@@ -87,11 +87,11 @@
         return xpath;
     }
 
-    public Object xpath(Object root, String query, QName returnTyp) {
+    public static Object xpath(Object root, String query, QName returnTyp) {
         return xpath(root, query, returnTyp, null);
     }
 
-    public final String xpathString(Object root, String query,
+    public static final String xpathString(Object root, String query,
                                     NamespaceContext namespaceContext) {
         return (String) xpath(root, query, XPathConstants.STRING,
                 namespaceContext);
@@ -116,33 +116,33 @@
         return null;
     }
 
-    public Object getXPath(Object root, String query, QName returnType) {
+    public static Object getXPath(Object root, String query, QName returnType) {
         return getXPath(root,query,returnType,ArtifactNamespaceContext.INSTANCE);
     }
 
-    public Object getXPath(
+    public static Object getXPath(
         Object root, String query, QName returnType, NamespaceContext context
     ) {
         return xpath(root, query, returnType, context);
     }
 
-    public String getStringXPath(String xpath) {
+    public static String getStringXPath(String xpath) {
         return getStringXPath(xpath, null);
     }
 
-    public NodeList getNodeSetXPath(Object root, String query) {
+    public static NodeList getNodeSetXPath(Object root, String query) {
         return (NodeList) getXPath(root, query, XPathConstants.NODESET);
     }
 
-    public Node getNodeXPath(Object root, String query) {
+    public static Node getNodeXPath(Object root, String query) {
         return (Node) getXPath(root, query, XPathConstants.NODE);
     }
 
-    public String getStringXPath(Object root, String xpath) {
+    public static String getStringXPath(Object root, String xpath) {
         return getStringXPath(root, xpath, null);
     }
 
-    public String getStringXPath(Object root, String query, String def) {
+    public static String getStringXPath(Object root, String query, String def) {
         String s = (String) getXPath(root, query, XPathConstants.STRING);
         return s == null || s.length() == 0 ? def : s;
     }
@@ -165,7 +165,7 @@
         return returnValue;
     }
 
-    public String writeNode2String(Node node) {
+    public static String writeNode2String(Node node) {
         try {
             DOMSource source = new DOMSource(node);
             return writeDOMSource2String(source);
@@ -179,14 +179,14 @@
         return null;
     }
 
-    public Document reInitDocument(Document document) {
+    public static Document reInitDocument(Document document) {
 
-        StringBufferInputStream inputStream = new StringBufferInputStream(this
-                .writeDocument2String(document));
-        return this.readDocument(inputStream);
+        StringBufferInputStream inputStream = new StringBufferInputStream(
+                writeDocument2String(document));
+        return readDocument(inputStream);
     }
 
-    public String writeDocument2String(Document document) {
+    public static String writeDocument2String(Document document) {
         try {
             DOMSource source = new DOMSource(document);
             return writeDOMSource2String(source);
@@ -207,7 +207,7 @@
      * @throws TransformerConfigurationException
      * @throws TransformerException
      */
-    private String writeDOMSource2String(DOMSource source)
+    private static String writeDOMSource2String(DOMSource source)
                                                           throws TransformerFactoryConfigurationError,
                                                           TransformerConfigurationException,
                                                           TransformerException {
--- a/gnv/src/main/resources/applicationMessages.properties	Thu Mar 04 14:27:26 2010 +0000
+++ b/gnv/src/main/resources/applicationMessages.properties	Fri Mar 05 09:33:30 2010 +0000
@@ -65,6 +65,9 @@
 # diagram options dialog
 gnviewer.diagram.options.header.title=Diagrammoptionen
 
+# wms
+gnviewer.wms.server.path=URL des WMS
+gnviewer.wms.server.layer=Name des Layers
 
 # attachedOutputOptions
 gnviewer.output.options.diagramm.alt=Diagramm
--- a/gnv/src/main/resources/applicationMessages_en.properties	Thu Mar 04 14:27:26 2010 +0000
+++ b/gnv/src/main/resources/applicationMessages_en.properties	Fri Mar 05 09:33:30 2010 +0000
@@ -65,6 +65,9 @@
 # diagram options dialog
 gnviewer.diagram.options.header.title=Diagram options
 
+# wms
+gnviewer.wms.server.path=WMS URL
+gnviewer.wms.server.layer=Layername
 
 # attachedOutputOptions
 gnviewer.output.options.diagramm.alt=Diagram
--- a/gnv/src/main/webapp/WEB-INF/jsp/wmslayout.jsp	Thu Mar 04 14:27:26 2010 +0000
+++ b/gnv/src/main/webapp/WEB-INF/jsp/wmslayout.jsp	Fri Mar 05 09:33:30 2010 +0000
@@ -1,6 +1,12 @@
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
+<%
+    String serverPath  = (String) request.getAttribute("mapserver");
+    String mapfilePath = (String) request.getAttribute("mapfile");
+    String layerName   = (String) request.getAttribute("layer");
+%>
+
 <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
         <title>
@@ -23,43 +29,22 @@
             var map, layer;
 
             function init() {
-                if (getURLParam("target") == "wms") {
-                    map   = new OpenLayers.Map('map');
-                    layer = new OpenLayers.Layer.WMS(
-                        "MyWMS",
-                        "http://denmark.atlas/cgi-bin/mapserv-gp?MAP=/opt/artifacts/mapfiles/mapfile.map",
-                        {
-                            layers: getURLParam("layer"),
-                            format: 'image/png'
-                        },
-                        {
-                            singleTile: 'true'
-                        }
-                    );
+                map        = new OpenLayers.Map('map');
+                var server = '<%=serverPath%>?MAP=<%=mapfilePath%>';
+                layer      = new OpenLayers.Layer.WMS(
+                    "MyWMS",
+                    server,
+                    {
+                        layers: '<%=layerName%>',
+                        format: 'image/png'
+                    },
+                    {
+                        singleTile: 'true'
+                    }
+                );
 
-                    map.addLayer(layer);
-                    map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
-                }
-            }
-
-            function getURLParam(strParamName){
-                var strReturn = "";
-                var strHref = window.location.href;
-
-                if ( strHref.indexOf("?") > -1 ){
-                    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
-                    var aQueryString = strQueryString.split("&");
-
-                    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
-                        if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ) {
-                            var aParam = aQueryString[iParam].split("=");
-                            strReturn = aParam[1];
-                            break;
-                        }
-                    }
-                }
-
-                return strReturn;
+                map.addLayer(layer);
+                map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
             }
         </script>
     </head>
@@ -78,7 +63,21 @@
          <jsp:include page="index.jsp" />
         <jsp:include page="footer.jsp" />
 
-        <div id="map"></div>
+        <div class="outerMap">
+            <div id="wms">
+                <table>
+                    <tr>
+                        <td class="parameter"><bean:message key="gnviewer.wms.server.path"/>:</td>
+                        <td class="wmsvalue"><%=serverPath%>?MAP=<%=mapfilePath%></td>
+                    </tr>
+                    <tr>
+                        <td class="parameter"><bean:message key="gnviewer.wms.server.layer"/>:</td>
+                        <td class="wmsvalue"><%=layerName%></td>
+                    </tr>
+                </table>
+            </div>
+            <div id="map"></div>
+        </div>
     </div>
     </body>
 </html>
--- a/gnv/src/main/webapp/styles/default.css	Thu Mar 04 14:27:26 2010 +0000
+++ b/gnv/src/main/webapp/styles/default.css	Fri Mar 05 09:33:30 2010 +0000
@@ -100,6 +100,11 @@
     width:         293px;
 }
 
+table.wms {
+    font-size: 0.8em;
+    margin: 0 0 0 0;
+}
+
 table, th, td {
     margin: 0;
     padding: 0;
@@ -128,13 +133,16 @@
     padding-left:   5px;
     text-align:     left;
     vertical-align: top;
-    width:          100px;
+    width:          110px;
 }
 
 .matrixHeader {
     padding-left: 5px;
 }
 
+.wmsvalue {
+}
+
 .value {
     font-size: 1.2em;
 }
@@ -265,12 +273,30 @@
     left: 350px;
 }
 
-div#map {
+div.outerMap {
     position: absolute;
     top: 62px;
     left: 350px;
     width: 555px;
     height: 436px;
+    margin: 0 0 0 0;
+    padding: 0 0 0 0;
+}
+
+div.wms {
+    position: relative;
+    top: 0px;
+    left: 0px;
+    height: 30px;
+    border: 1px solid red;
+}
+
+div#map {
+    position: absolute;
+    top: 55px;
+    left: 0px;
+    width: 555px;
+    height: 381px;
     border: 1px solid #CCD5DE;
 }
 

http://dive4elements.wald.intevation.org