changeset 1408:5b5a20e4c4e5

Added a service that loads the Capabilities of a specified WMS - display those information in the ExternalWMSWindow. flys-client/trunk@3295 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 21 Nov 2011 12:00:48 +0000
parents ee2875510c12
children ec6e4dad1279
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties flys-client/src/main/java/de/intevation/flys/client/client/services/GCService.java flys-client/src/main/java/de/intevation/flys/client/client/services/GCServiceAsync.java flys-client/src/main/java/de/intevation/flys/client/client/ui/map/CapabilitiesPanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/map/ExternalWMSWindow.java flys-client/src/main/java/de/intevation/flys/client/server/GCServiceImpl.java flys-client/src/main/java/de/intevation/flys/client/shared/model/Capabilities.java flys-client/src/main/webapp/WEB-INF/web.xml
diffstat 12 files changed, 382 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Mon Nov 21 09:29:57 2011 +0000
+++ b/flys-client/ChangeLog	Mon Nov 21 12:00:48 2011 +0000
@@ -1,3 +1,32 @@
+2011-11-21  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/shared/model/Capabilities.java:
+	  New. This class is used to store information of a document returned by a
+	  WMS GetCapabilities request.
+
+	* src/main/java/de/intevation/flys/client/server/GCServiceImpl.java,
+	  src/main/java/de/intevation/flys/client/client/services/GCServiceAsync.java,
+	  src/main/java/de/intevation/flys/client/client/services/GCService.java:
+	  A new service that fetches a GetCapabilities document of a given server.
+	  It returns a Capabilities object that stores the information of the
+	  response.
+
+	* src/main/java/de/intevation/flys/client/client/ui/map/CapabilitiesPanel.java:
+	  New. This VLayout is used to display FLYS relevant information of a
+	  Capabilities object. TODO: I18N.
+
+	* src/main/java/de/intevation/flys/client/client/ui/map/ExternalWMSWindow.java:
+	  Make use of GCService to query the Capabilities of the user specified
+	  WMS.
+
+	* src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants.java: Added
+	  error strings used in the GCServiceImpl.
+
+	* src/main/webapp/WEB-INF/web.xml: Registered the GCService.
+
 2011-11-21  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/webapp/images/addWMS.png: Replaced by the same icon but with
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Mon Nov 21 09:29:57 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Mon Nov 21 12:00:48 2011 +0000
@@ -422,6 +422,12 @@
 
     String error_gfi_parsing_failed();
 
+    String error_gc_req_failed();
+
+    String error_gc_doc_not_valid();
+
+    String error_malformed_url();
+
 
 
     String bottom_edge();
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Mon Nov 21 09:29:57 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Mon Nov 21 12:00:48 2011 +0000
@@ -220,6 +220,9 @@
 error_no_valid_gfi_url = No valid GetFeatureInfo response found.
 error_gfi_req_failed = GetFeatureInfo request failed.
 error_gfi_parsing_failed = Failed to read GetFeatureInfo response.
+error_gc_req_failed = Error while loading Capabilities document.
+error_gc_doc_not_valid = Capabilities document is not valid.
+error_malformed_url = The URL you have entered is not valid.
 
 ## map related strings
 digitize = images/digitize.png
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Mon Nov 21 09:29:57 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Mon Nov 21 12:00:48 2011 +0000
@@ -220,6 +220,9 @@
 error_no_valid_gfi_url = Ung\u00fcltige GetFeatureInfo URL.
 error_gfi_req_failed = Die GetFeatureInfo Anfrage ist fehlgeschlagen.
 error_gfi_parsing_failed = Fehler beim Lesen der GetFeatureInfo Antwort.
+error_gc_req_failed = Fehler beim Laden des Capabilities Dokuments.
+error_gc_doc_not_valid = Das Capabilities Dokument ist nicht valide.
+error_malformed_url = Die eingegebene URL ist ung\u00fcltig.
 
 ## map related strings
 digitize = images/digitize.png
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Mon Nov 21 09:29:57 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Mon Nov 21 12:00:48 2011 +0000
@@ -220,6 +220,9 @@
 error_no_valid_gfi_url = No valid GetFeatureInfo response found.
 error_gfi_req_failed = GetFeatureInfo request failed.
 error_gfi_parsing_failed = Failed to read GetFeatureInfo response.
+error_gc_req_failed = Error while loading Capabilities document.
+error_gc_doc_not_valid = Capabilities document is not valid.
+error_malformed_url = The URL you have entered is not valid.
 
 ## map related strings
 digitize = images/digitize.png
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/services/GCService.java	Mon Nov 21 12:00:48 2011 +0000
@@ -0,0 +1,16 @@
+package de.intevation.flys.client.client.services;
+
+import com.google.gwt.user.client.rpc.RemoteService;
+import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
+
+import de.intevation.flys.client.shared.exceptions.ServerException;
+import de.intevation.flys.client.shared.model.Capabilities;
+
+
+@RemoteServiceRelativePath("getcapabilities")
+public interface GCService extends RemoteService {
+
+    public Capabilities query(String path)
+    throws ServerException;
+}
+// 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/client/services/GCServiceAsync.java	Mon Nov 21 12:00:48 2011 +0000
@@ -0,0 +1,15 @@
+package de.intevation.flys.client.client.services;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+
+import de.intevation.flys.client.shared.model.Capabilities;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public interface GCServiceAsync {
+
+    void query(String path, AsyncCallback<Capabilities> callback);
+}
+// 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/client/ui/map/CapabilitiesPanel.java	Mon Nov 21 12:00:48 2011 +0000
@@ -0,0 +1,86 @@
+package de.intevation.flys.client.client.ui.map;
+
+import com.google.gwt.user.client.ui.Grid;
+
+import com.smartgwt.client.widgets.Label;
+import com.smartgwt.client.widgets.layout.HLayout;
+import com.smartgwt.client.widgets.layout.Layout;
+import com.smartgwt.client.widgets.layout.VLayout;
+
+import de.intevation.flys.client.shared.model.Capabilities;
+
+
+public class CapabilitiesPanel extends VLayout {
+
+    protected Capabilities capabilites;
+
+
+    public CapabilitiesPanel(Capabilities capabilites) {
+        super();
+        this.capabilites = capabilites;
+
+        initLayout();
+    }
+
+
+    protected void initLayout() {
+        setMargin(10);
+        initContent();
+    }
+
+
+    protected void initContent() {
+        Grid grid = new Grid(5, 2);
+        grid.setCellPadding(10);
+
+        grid.setText(0, 0, "Titel:");
+        grid.setText(0, 1, "TODO:");
+        grid.setText(1, 0, "URL:");
+        grid.setText(1, 1, "TODO");
+        grid.setText(2, 0, "Nutzungsbedingungen:");
+        grid.setText(2, 1, capabilites.getAccessConstraints());
+        grid.setText(3, 0, "Gebühren:");
+        grid.setText(3, 1, capabilites.getFees());
+        grid.setText(4, 0, "Weitere Informationen:");
+        grid.setText(4, 1, "TODO");
+
+        Label title = new Label("Bitte beachten Sie folgende Informationen des WMS-Dienstes:");
+        title.setHeight(25);
+
+        addMember(title);
+        addMember(grid);
+    }
+
+
+    //private void initLayout() {
+    //    Label title   = new Label("Titel:");
+    //    Label url     = new Label("URL:");
+    //    Label access  = new Label("Nutzungsbedingungen:");
+    //    Label fees    = new Label("Gebühren:");
+    //    Label contact = new Label("Weitere Informationen:");
+
+    //    Label titleContent   = new Label("TODO");
+    //    Label urlContent     = new Label("TODO");
+    //    Label accessContent  = new Label(capabilites.getAccessConstraints());
+    //    Label feesContent    = new Label(capabilites.getFees());
+    //    Label contactContent = new Label("TODO");
+
+    //    addMember(createRow(title, titleContent));
+    //    addMember(createRow(url, urlContent));
+    //    addMember(createRow(access, accessContent));
+    //    addMember(createRow(fees, feesContent));
+    //    addMember(createRow(contact, contactContent));
+    //}
+
+
+    protected Layout createRow(Label title, Label content) {
+        title.setWidth(100);
+
+        HLayout layout = new HLayout();
+        layout.addMember(title);
+        layout.addMember(content);
+
+        return layout;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/ExternalWMSWindow.java	Mon Nov 21 09:29:57 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/ExternalWMSWindow.java	Mon Nov 21 12:00:48 2011 +0000
@@ -1,5 +1,7 @@
 package de.intevation.flys.client.client.ui.map;
 
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.rpc.AsyncCallback;
 import com.google.gwt.user.client.ui.TextBox;
 
 import com.smartgwt.client.util.SC;
@@ -13,13 +15,23 @@
 import com.smartgwt.client.widgets.layout.Layout;
 import com.smartgwt.client.widgets.layout.VLayout;
 
+import de.intevation.flys.client.shared.model.Capabilities;
+import de.intevation.flys.client.client.FLYSConstants;
+import de.intevation.flys.client.client.services.GCService;
+import de.intevation.flys.client.client.services.GCServiceAsync;
+
 
 public class ExternalWMSWindow extends Window {
 
+    protected GCServiceAsync gcService = GWT.create(GCService.class);
+    protected FLYSConstants  MSG       = GWT.create(FLYSConstants.class);
+
     protected Layout inputPanel;
     protected Layout infoPanel;
     protected Layout layersPanel;
 
+    protected Capabilities capabilites;
+
     protected String url;
 
 
@@ -38,6 +50,25 @@
     }
 
 
+    protected String getCapabilitiesUrl() {
+        String cUrl = url;
+
+        if (url.indexOf("?") >= 0) {
+            cUrl += "&SERVICE=WMS&REQUEST=GetCapabilities";
+        }
+        else {
+            cUrl += "?SERVICE=WMS&REQUEST=GetCapabilities";
+        }
+
+        return cUrl;
+    }
+
+
+    protected void setCapabilites(Capabilities capabilites) {
+        this.capabilites = capabilites;
+    }
+
+
     public void start() {
         show();
         centerInPage();
@@ -118,7 +149,8 @@
                 }
 
                 setUrl(url.getValue());
-                goToInfoPanel();
+
+                doCapabilitesRequest();
             }
         };
 
@@ -166,12 +198,13 @@
             }
         };
 
-        VLayout root = new VLayout();
+        VLayout root  = new VLayout();
+        VLayout panel = new CapabilitiesPanel(capabilites);
 
-        root.addMember(new Label("STEP 2: " + getUrl()));
+        root.setLayoutMargin(10);
+        panel.setHeight(420);
 
-        // TODO IMPLEMENT ME
-
+        root.addMember(panel);
         root.addMember(createButtonPanel(backHandler, goHandler, cancelHandler));
 
         return root;
@@ -273,5 +306,19 @@
     protected void quit() {
         destroy();
     }
+
+
+    protected void doCapabilitesRequest() {
+        gcService.query(getCapabilitiesUrl(),new AsyncCallback<Capabilities>() {
+            public void onFailure(Throwable e) {
+                SC.warn(MSG.getString(e.getMessage()));
+            }
+
+            public void onSuccess(Capabilities capabilites) {
+                setCapabilites(capabilites);
+                goToInfoPanel();
+            }
+        });
+    }
 }
 // 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/GCServiceImpl.java	Mon Nov 21 12:00:48 2011 +0000
@@ -0,0 +1,108 @@
+package de.intevation.flys.client.server;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+
+import javax.xml.xpath.XPathConstants;
+
+import com.google.gwt.user.server.rpc.RemoteServiceServlet;
+
+import org.w3c.dom.Document;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.artifacts.common.utils.XMLUtils;
+
+import de.intevation.flys.client.shared.exceptions.ServerException;
+import de.intevation.flys.client.shared.model.Capabilities;
+import de.intevation.flys.client.client.services.GCService;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class GCServiceImpl
+extends      RemoteServiceServlet
+implements   GCService
+{
+    public static final String ERR_GC_REQUEST_FAILED =
+        "error_gc_req_failed";
+
+    public static final String ERR_GC_DOC_NOT_VALID =
+        "error_gc_doc_not_valid";
+
+    public static final String ERR_MALFORMED_URL =
+        "error_malformed_url";
+
+    public static final String XPATH_FEES =
+        "/WMS_Capabilities/Service/Fees/text()";
+
+    public static final String XPATH_ACCESS_CONSTRAINTS =
+        "/WMS_Capabilities/Service/AccessConstraints/text()";
+
+
+    private Logger logger = Logger.getLogger(GCServiceImpl.class);
+
+
+    public Capabilities query(String path)
+    throws ServerException
+    {
+        logger.info("GCServiceImpl.query");
+
+        try {
+            URL url = new URL(path);
+
+            logger.debug("Open connection to url: " + path);
+
+            URLConnection conn = url.openConnection();
+            conn.connect();
+
+            InputStream is = conn.getInputStream();
+
+            return parseCapabilitiesResponse(is);
+        }
+        catch (MalformedURLException mue) {
+            logger.warn(mue, mue);
+            throw new ServerException(ERR_MALFORMED_URL);
+        }
+        catch (IOException ioe) {
+            logger.warn(ioe, ioe);
+        }
+
+        throw new ServerException(ERR_GC_REQUEST_FAILED);
+    }
+
+
+    protected Capabilities parseCapabilitiesResponse(InputStream is)
+    throws ServerException
+    {
+        logger.debug("GCServiceImpl.parseCapabilitiesResponse");
+
+        Document doc = XMLUtils.parseDocument(is, false);
+
+        if (doc == null) {
+            throw new ServerException(ERR_GC_DOC_NOT_VALID);
+        }
+
+        String fees = (String) XMLUtils.xpath(
+            doc,
+            XPATH_FEES,
+            XPathConstants.STRING);
+
+        String accessConstraints = (String) XMLUtils.xpath(
+            doc,
+            XPATH_ACCESS_CONSTRAINTS,
+            XPathConstants.STRING);
+
+        logger.debug("Found fees: " + fees);
+        logger.debug("Found access constraints: " + accessConstraints);
+
+        // TODO PARSE LAYERS
+
+        return new Capabilities(fees, accessConstraints, null);
+    }
+}
+// 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/shared/model/Capabilities.java	Mon Nov 21 12:00:48 2011 +0000
@@ -0,0 +1,51 @@
+package de.intevation.flys.client.shared.model;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class Capabilities implements Serializable {
+
+    protected String fees;
+    protected String accessConstraints;
+
+    protected List<String> layers;
+
+
+    public Capabilities() {
+        layers = new ArrayList<String>();
+    }
+
+
+    /**
+     * @param fees
+     * @param accessConstraints
+     * @param layers
+     */
+    public Capabilities(
+        String       fees,
+        String       accessConstraints,
+        List<String> layers
+    ) {
+        this.fees              = fees;
+        this.accessConstraints = accessConstraints;
+        this.layers            = layers;
+    }
+
+
+    public String getFees() {
+        return fees;
+    }
+
+
+    public String getAccessConstraints() {
+        return accessConstraints;
+    }
+
+
+    public List<String> getLayers() {
+        return layers;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/webapp/WEB-INF/web.xml	Mon Nov 21 09:29:57 2011 +0000
+++ b/flys-client/src/main/webapp/WEB-INF/web.xml	Mon Nov 21 12:00:48 2011 +0000
@@ -315,6 +315,16 @@
   </servlet-mapping>
 
   <servlet>
+    <servlet-name>getcapabilities</servlet-name>
+    <servlet-class>de.intevation.flys.client.server.GCServiceImpl</servlet-class>
+  </servlet>
+  
+  <servlet-mapping>
+    <servlet-name>getcapabilities</servlet-name>
+    <url-pattern>/flys/getcapabilities</url-pattern>
+  </servlet-mapping>
+
+  <servlet>
     <servlet-name>DescribeArtifactService</servlet-name>
     <servlet-class>de.intevation.flys.client.server.DescribeArtifactServiceImpl</servlet-class>
   </servlet>

http://dive4elements.wald.intevation.org