changeset 6198:809c91beee54

CapabilitesParser can parse map format types now (#554).
author Christian Lins <christian.lins@intevation.de>
date Wed, 05 Jun 2013 12:56:24 +0200
parents cefad5546373
children 734ba3732bb6
files gwt-client/src/main/java/org/dive4elements/river/client/server/CapabilitiesParser.java gwt-client/src/main/java/org/dive4elements/river/client/server/GGInATrustStrategy.java gwt-client/src/main/java/org/dive4elements/river/client/shared/model/Capabilities.java
diffstat 3 files changed, 43 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/server/CapabilitiesParser.java	Wed Jun 05 11:54:24 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/CapabilitiesParser.java	Wed Jun 05 12:56:24 2013 +0200
@@ -8,8 +8,14 @@
 
 package org.dive4elements.river.client.server;
 
+import org.dive4elements.artifacts.common.utils.XMLUtils;
+import org.dive4elements.river.client.shared.exceptions.ServerException;
+import org.dive4elements.river.client.shared.model.Capabilities;
+import org.dive4elements.river.client.shared.model.ContactInformation;
+import org.dive4elements.river.client.shared.model.WMSLayer;
+
+import java.io.IOException;
 import java.io.InputStream;
-import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
@@ -20,21 +26,15 @@
 
 import javax.xml.xpath.XPathConstants;
 
+import org.apache.log4j.Logger;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
-import org.apache.log4j.Logger;
-
-import org.dive4elements.artifacts.common.utils.XMLUtils;
-
-import org.dive4elements.river.client.shared.exceptions.ServerException;
-import org.dive4elements.river.client.shared.model.Capabilities;
-import org.dive4elements.river.client.shared.model.ContactInformation;
-import org.dive4elements.river.client.shared.model.WMSLayer;
-
-
+/**
+ * Parser for GetCapabilities of a WMS.
+ */
 public class CapabilitiesParser {
 
     private static final Logger logger =
@@ -96,6 +96,9 @@
     public static final String XPATH_LAYERS =
         "Capability/Layer";
 
+    public static final String XPATH_MAP_FORMAT =
+        "Capability/Request/GetMap/Format";
+
     public static final Pattern SRS_PATTERN = Pattern.compile("(EPSG:\\d+)*");
 
 
@@ -110,9 +113,14 @@
         LoggingConfigurator.init(log4jProperties);
 
         try {
-            Capabilities caps = getCapabilities(System.getProperty("test.wms"));
+            String wmsURL = System.getProperty("test.wms");
+            if (wmsURL == null || args.length > 0) {
+                wmsURL = args[0];
+            }
+            Capabilities caps = getCapabilities(wmsURL);
 
             logger.debug(caps.toString());
+            System.out.println(caps.toString());
         }
         catch (ServerException se) {
             se.printStackTrace();
@@ -206,13 +214,22 @@
 
         List<WMSLayer> layers = parseLayers(layerNodes, onlineResource);
 
+        // Parse MIME types of supported return types, e.g. image/jpeg
+        NodeList mapFormatNodes = (NodeList)
+                XMLUtils.xpath(capabilities, XPATH_MAP_FORMAT, XPathConstants.NODESET);
+        List<String> mapFormats = new ArrayList<String>();
+        for (int n = 0; n < mapFormatNodes.getLength(); n++) {
+            mapFormats.add(mapFormatNodes.item(n).getTextContent());
+        }
+
         return new Capabilities(
             title,
             onlineResource,
             ci,
             fees,
             accessConstraints,
-            layers);
+            layers,
+            mapFormats);
     }
 
 
--- a/gwt-client/src/main/java/org/dive4elements/river/client/server/GGInATrustStrategy.java	Wed Jun 05 11:54:24 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/GGInATrustStrategy.java	Wed Jun 05 12:56:24 2013 +0200
@@ -16,7 +16,7 @@
 public class GGInATrustStrategy implements TrustStrategy {
 
     /**
-     * Tempoary class to accept all certificates for GGinA Authentication
+     * Temporary class to accept all certificates for GGinA Authentication.
      */
 
     @Override
--- a/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/Capabilities.java	Wed Jun 05 11:54:24 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/Capabilities.java	Wed Jun 05 12:56:24 2013 +0200
@@ -12,7 +12,9 @@
 import java.util.ArrayList;
 import java.util.List;
 
-
+/**
+ * Capabilities of a WMS.
+ */
 public class Capabilities implements Serializable {
 
     protected String title;
@@ -23,6 +25,7 @@
     protected ContactInformation contactInformation;
 
     protected List<WMSLayer> layers;
+    protected List<String> mapFormats;
 
 
     public Capabilities() {
@@ -41,7 +44,8 @@
         ContactInformation contactInformation,
         String             fees,
         String             accessConstraints,
-        List<WMSLayer>     layers
+        List<WMSLayer>     layers,
+        List<String>       mapFormats
     ) {
         this.title              = title;
         this.onlineResource     = onlineResource;
@@ -49,6 +53,7 @@
         this.fees               = fees;
         this.accessConstraints  = accessConstraints;
         this.layers             = layers;
+        this.mapFormats         = mapFormats;
     }
 
 
@@ -82,6 +87,11 @@
     }
 
 
+    public List<String> getMapFormats() {
+        return mapFormats;
+    }
+
+
     @Override
     public String toString() {
         StringBuilder sb = new StringBuilder();

http://dive4elements.wald.intevation.org