# HG changeset patch # User Ingo Weinzierl # Date 1321909203 0 # Node ID 63be3137abac595834d82df087fc7e0c43ce1465 # Parent 6bb2c1ffab2b5b370a74186f4433f1d11fa8c182 Parse and display WMS layers supported by a user specified WMS service. flys-client/trunk@3298 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 6bb2c1ffab2b -r 63be3137abac flys-client/ChangeLog --- a/flys-client/ChangeLog Mon Nov 21 19:38:26 2011 +0000 +++ b/flys-client/ChangeLog Mon Nov 21 21:00:03 2011 +0000 @@ -1,3 +1,23 @@ +2011-11-21 Ingo Weinzierl + + * src/main/java/de/intevation/flys/client/shared/model/WMSLayer.java: New. + This class stores layer information provided by capabilities document. + Note, that a WMSLayer can have further sublayers. + + * src/main/java/de/intevation/flys/client/server/GCServiceImpl.java: Parse + layers from capabilities document. + + * src/main/java/de/intevation/flys/client/client/ui/map/WMSLayersTree.java: + New. This tree displays WMSLayers. + + * src/main/java/de/intevation/flys/client/shared/model/Capabilities.java: + Now, the list of layers is from type List instead of + List. + + * src/main/java/de/intevation/flys/client/client/ui/map/ExternalWMSWindow.java: + Use the WMSLayersTree to display the layers provided by the given WMS + service. + 2011-11-21 Ingo Weinzierl * src/main/java/de/intevation/flys/client/client/ui/map/ExternalWMSWindow.java: diff -r 6bb2c1ffab2b -r 63be3137abac flys-client/src/main/java/de/intevation/flys/client/client/ui/map/ExternalWMSWindow.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/ExternalWMSWindow.java Mon Nov 21 19:38:26 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/ExternalWMSWindow.java Mon Nov 21 21:00:03 2011 +0000 @@ -7,7 +7,6 @@ import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Button; import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.Window; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; @@ -234,12 +233,13 @@ } }; - VLayout root = new VLayout(); + VLayout root = new VLayout(); + WMSLayersTree tree = new WMSLayersTree(capabilites); - root.addMember(new Label("STEP 3")); + root.setLayoutMargin(10); + tree.setHeight(420); - // TODO IMPLEMENT ME - + root.addMember(tree); root.addMember(createButtonPanel(backHandler, goHandler, cancelHandler)); return root; diff -r 6bb2c1ffab2b -r 63be3137abac flys-client/src/main/java/de/intevation/flys/client/client/ui/map/WMSLayersTree.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/WMSLayersTree.java Mon Nov 21 21:00:03 2011 +0000 @@ -0,0 +1,75 @@ +package de.intevation.flys.client.client.ui.map; + +import java.util.ArrayList; +import java.util.List; + +import com.smartgwt.client.types.TreeModelType; +import com.smartgwt.client.widgets.tree.Tree; +import com.smartgwt.client.widgets.tree.TreeGrid; +import com.smartgwt.client.widgets.tree.TreeNode; + +import de.intevation.flys.client.shared.model.Capabilities; +import de.intevation.flys.client.shared.model.WMSLayer; + + +public class WMSLayersTree extends TreeGrid { + + protected Capabilities capabilites; + + public WMSLayersTree(Capabilities capabilites) { + super(); + this.capabilites = capabilites; + + initTree(); + } + + + protected void initTree() { + setLoadDataOnDemand(false); + setWidth100(); + setHeight100(); + setShowRoot(false); + setShowConnectors(true); + setNodeIcon("[SKIN]/images/blank.gif"); + + Tree tree = new Tree(); + tree.setChildrenProperty("children-nodes"); + tree.setNameProperty("title"); + tree.setIdField("title"); + tree.setModelType(TreeModelType.CHILDREN); + tree.setShowRoot(false); + + TreeNode root = new TreeNode("Root"); + TreeNode[] layers = buildTree(capabilites.getLayers()); + + root.setAttribute("children-nodes", layers); + tree.setRoot(root); + + setData(tree); + + if (layers != null && layers.length == 1) { + tree.openFolder(layers[0]); + } + } + + + protected TreeNode[] buildTree(List layers) { + List layerNodes = new ArrayList(); + + for (WMSLayer layer: layers) { + TreeNode tn = new TreeNode(); + tn.setAttribute("name", layer.getName()); + tn.setAttribute("title", layer.getTitle()); + + TreeNode[] tns = buildTree(layer.getLayers()); + + if (tns != null && tns.length > 0) { + tn.setAttribute("children-nodes", tns); + } + + layerNodes.add(tn); + } + + return (TreeNode[]) layerNodes.toArray(new TreeNode[layerNodes.size()]); + } +} diff -r 6bb2c1ffab2b -r 63be3137abac flys-client/src/main/java/de/intevation/flys/client/server/GCServiceImpl.java --- a/flys-client/src/main/java/de/intevation/flys/client/server/GCServiceImpl.java Mon Nov 21 19:38:26 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/GCServiceImpl.java Mon Nov 21 21:00:03 2011 +0000 @@ -5,6 +5,8 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; +import java.util.ArrayList; +import java.util.List; import javax.xml.xpath.XPathConstants; @@ -12,6 +14,7 @@ import org.w3c.dom.Document; import org.w3c.dom.Node; +import org.w3c.dom.NodeList; import org.apache.log4j.Logger; @@ -20,6 +23,7 @@ import de.intevation.flys.client.shared.exceptions.ServerException; import de.intevation.flys.client.shared.model.Capabilities; import de.intevation.flys.client.shared.model.ContactInformation; +import de.intevation.flys.client.shared.model.WMSLayer; import de.intevation.flys.client.client.services.GCService; @@ -75,6 +79,9 @@ public static final String XPATH_ACCESS_CONSTRAINTS = "/WMS_Capabilities/Service/AccessConstraints/text()"; + public static final String XPATH_LAYERS = + "/WMS_Capabilities/Capability/Layer"; + private Logger logger = Logger.getLogger(GCServiceImpl.class); @@ -149,7 +156,12 @@ logger.debug("Found fees: " + fees); logger.debug("Found access constraints: " + accessConstraints); - // TODO PARSE LAYERS + NodeList layerNodes = (NodeList) XMLUtils.xpath( + doc, + XPATH_LAYERS, + XPathConstants.NODESET); + + List layers = parseLayers(layerNodes); return new Capabilities( title, @@ -157,7 +169,7 @@ ci, fees, accessConstraints, - null); + layers); } @@ -208,5 +220,44 @@ return ci; } + + + protected List parseLayers(NodeList layersNode) { + int len = layersNode != null ? layersNode.getLength() : 0; + + logger.debug("Node has " + len + " layers."); + + List layers = new ArrayList(len); + + for (int i = 0; i < len; i++) { + layers.add(parseLayer(layersNode.item(i))); + } + + return layers; + } + + + protected WMSLayer parseLayer(Node layerNode) { + String title = (String) XMLUtils.xpath( + layerNode, + "Title/text()", + XPathConstants.STRING); + + String name = (String) XMLUtils.xpath( + layerNode, + "Name/text()", + XPathConstants.STRING); + + logger.debug("Found layers: " + title + "(" + name + ")"); + + NodeList layersNodes = (NodeList) XMLUtils.xpath( + layerNode, + "Layer", + XPathConstants.NODESET); + + List layers = parseLayers(layersNodes); + + return new WMSLayer(title, name, layers); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 6bb2c1ffab2b -r 63be3137abac flys-client/src/main/java/de/intevation/flys/client/shared/model/Capabilities.java --- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/Capabilities.java Mon Nov 21 19:38:26 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/Capabilities.java Mon Nov 21 21:00:03 2011 +0000 @@ -14,11 +14,11 @@ protected ContactInformation contactInformation; - protected List layers; + protected List layers; public Capabilities() { - layers = new ArrayList(); + layers = new ArrayList(); } @@ -33,7 +33,7 @@ ContactInformation contactInformation, String fees, String accessConstraints, - List layers + List layers ) { this.title = title; this.onlineResource = onlineResource; @@ -69,7 +69,7 @@ } - public List getLayers() { + public List getLayers() { return layers; } } diff -r 6bb2c1ffab2b -r 63be3137abac flys-client/src/main/java/de/intevation/flys/client/shared/model/WMSLayer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/WMSLayer.java Mon Nov 21 21:00:03 2011 +0000 @@ -0,0 +1,42 @@ +package de.intevation.flys.client.shared.model; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + + +public class WMSLayer implements Serializable { + + protected String name; + protected String title; + + protected List layers; + + + public WMSLayer() { + layers = new ArrayList(); + } + + + public WMSLayer(String title, String name, List layers) { + this.title = title; + this.name = name; + this.layers = layers; + } + + + public String getName() { + return name; + } + + + public String getTitle() { + return title; + } + + + public List getLayers() { + return layers; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :