Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/GCServiceImpl.java @ 1411:63be3137abac
Parse and display WMS layers supported by a user specified WMS service.
flys-client/trunk@3298 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 21 Nov 2011 21:00:03 +0000 |
parents | ec6e4dad1279 |
children | 3484cbfaf369 |
comparison
equal
deleted
inserted
replaced
1410:6bb2c1ffab2b | 1411:63be3137abac |
---|---|
3 import java.io.InputStream; | 3 import java.io.InputStream; |
4 import java.io.IOException; | 4 import java.io.IOException; |
5 import java.net.MalformedURLException; | 5 import java.net.MalformedURLException; |
6 import java.net.URL; | 6 import java.net.URL; |
7 import java.net.URLConnection; | 7 import java.net.URLConnection; |
8 import java.util.ArrayList; | |
9 import java.util.List; | |
8 | 10 |
9 import javax.xml.xpath.XPathConstants; | 11 import javax.xml.xpath.XPathConstants; |
10 | 12 |
11 import com.google.gwt.user.server.rpc.RemoteServiceServlet; | 13 import com.google.gwt.user.server.rpc.RemoteServiceServlet; |
12 | 14 |
13 import org.w3c.dom.Document; | 15 import org.w3c.dom.Document; |
14 import org.w3c.dom.Node; | 16 import org.w3c.dom.Node; |
17 import org.w3c.dom.NodeList; | |
15 | 18 |
16 import org.apache.log4j.Logger; | 19 import org.apache.log4j.Logger; |
17 | 20 |
18 import de.intevation.artifacts.common.utils.XMLUtils; | 21 import de.intevation.artifacts.common.utils.XMLUtils; |
19 | 22 |
20 import de.intevation.flys.client.shared.exceptions.ServerException; | 23 import de.intevation.flys.client.shared.exceptions.ServerException; |
21 import de.intevation.flys.client.shared.model.Capabilities; | 24 import de.intevation.flys.client.shared.model.Capabilities; |
22 import de.intevation.flys.client.shared.model.ContactInformation; | 25 import de.intevation.flys.client.shared.model.ContactInformation; |
26 import de.intevation.flys.client.shared.model.WMSLayer; | |
23 import de.intevation.flys.client.client.services.GCService; | 27 import de.intevation.flys.client.client.services.GCService; |
24 | 28 |
25 | 29 |
26 /** | 30 /** |
27 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 31 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
73 "/WMS_Capabilities/Service/Fees/text()"; | 77 "/WMS_Capabilities/Service/Fees/text()"; |
74 | 78 |
75 public static final String XPATH_ACCESS_CONSTRAINTS = | 79 public static final String XPATH_ACCESS_CONSTRAINTS = |
76 "/WMS_Capabilities/Service/AccessConstraints/text()"; | 80 "/WMS_Capabilities/Service/AccessConstraints/text()"; |
77 | 81 |
82 public static final String XPATH_LAYERS = | |
83 "/WMS_Capabilities/Capability/Layer"; | |
84 | |
78 | 85 |
79 private Logger logger = Logger.getLogger(GCServiceImpl.class); | 86 private Logger logger = Logger.getLogger(GCServiceImpl.class); |
80 | 87 |
81 | 88 |
82 public Capabilities query(String path) | 89 public Capabilities query(String path) |
147 ContactInformation ci = parseContactInformation(contactInformation); | 154 ContactInformation ci = parseContactInformation(contactInformation); |
148 | 155 |
149 logger.debug("Found fees: " + fees); | 156 logger.debug("Found fees: " + fees); |
150 logger.debug("Found access constraints: " + accessConstraints); | 157 logger.debug("Found access constraints: " + accessConstraints); |
151 | 158 |
152 // TODO PARSE LAYERS | 159 NodeList layerNodes = (NodeList) XMLUtils.xpath( |
160 doc, | |
161 XPATH_LAYERS, | |
162 XPathConstants.NODESET); | |
163 | |
164 List<WMSLayer> layers = parseLayers(layerNodes); | |
153 | 165 |
154 return new Capabilities( | 166 return new Capabilities( |
155 title, | 167 title, |
156 onlineResource, | 168 onlineResource, |
157 ci, | 169 ci, |
158 fees, | 170 fees, |
159 accessConstraints, | 171 accessConstraints, |
160 null); | 172 layers); |
161 } | 173 } |
162 | 174 |
163 | 175 |
164 protected ContactInformation parseContactInformation(Node node) { | 176 protected ContactInformation parseContactInformation(Node node) { |
165 String person = (String) XMLUtils.xpath( | 177 String person = (String) XMLUtils.xpath( |
206 ci.setPhone(phone); | 218 ci.setPhone(phone); |
207 ci.setEmail(email); | 219 ci.setEmail(email); |
208 | 220 |
209 return ci; | 221 return ci; |
210 } | 222 } |
223 | |
224 | |
225 protected List<WMSLayer> parseLayers(NodeList layersNode) { | |
226 int len = layersNode != null ? layersNode.getLength() : 0; | |
227 | |
228 logger.debug("Node has " + len + " layers."); | |
229 | |
230 List<WMSLayer> layers = new ArrayList<WMSLayer>(len); | |
231 | |
232 for (int i = 0; i < len; i++) { | |
233 layers.add(parseLayer(layersNode.item(i))); | |
234 } | |
235 | |
236 return layers; | |
237 } | |
238 | |
239 | |
240 protected WMSLayer parseLayer(Node layerNode) { | |
241 String title = (String) XMLUtils.xpath( | |
242 layerNode, | |
243 "Title/text()", | |
244 XPathConstants.STRING); | |
245 | |
246 String name = (String) XMLUtils.xpath( | |
247 layerNode, | |
248 "Name/text()", | |
249 XPathConstants.STRING); | |
250 | |
251 logger.debug("Found layers: " + title + "(" + name + ")"); | |
252 | |
253 NodeList layersNodes = (NodeList) XMLUtils.xpath( | |
254 layerNode, | |
255 "Layer", | |
256 XPathConstants.NODESET); | |
257 | |
258 List<WMSLayer> layers = parseLayers(layersNodes); | |
259 | |
260 return new WMSLayer(title, name, layers); | |
261 } | |
211 } | 262 } |
212 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 263 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |