Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/server/CapabilitiesParser.java @ 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 | ea9eef426962 |
children | 734ba3732bb6 |
comparison
equal
deleted
inserted
replaced
6197:cefad5546373 | 6198:809c91beee54 |
---|---|
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.client.server; | 9 package org.dive4elements.river.client.server; |
10 | 10 |
11 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
12 import org.dive4elements.river.client.shared.exceptions.ServerException; | |
13 import org.dive4elements.river.client.shared.model.Capabilities; | |
14 import org.dive4elements.river.client.shared.model.ContactInformation; | |
15 import org.dive4elements.river.client.shared.model.WMSLayer; | |
16 | |
17 import java.io.IOException; | |
11 import java.io.InputStream; | 18 import java.io.InputStream; |
12 import java.io.IOException; | |
13 import java.net.MalformedURLException; | 19 import java.net.MalformedURLException; |
14 import java.net.URL; | 20 import java.net.URL; |
15 import java.net.URLConnection; | 21 import java.net.URLConnection; |
16 import java.util.ArrayList; | 22 import java.util.ArrayList; |
17 import java.util.List; | 23 import java.util.List; |
18 import java.util.regex.Matcher; | 24 import java.util.regex.Matcher; |
19 import java.util.regex.Pattern; | 25 import java.util.regex.Pattern; |
20 | 26 |
21 import javax.xml.xpath.XPathConstants; | 27 import javax.xml.xpath.XPathConstants; |
22 | 28 |
29 import org.apache.log4j.Logger; | |
23 import org.w3c.dom.Document; | 30 import org.w3c.dom.Document; |
24 import org.w3c.dom.Element; | 31 import org.w3c.dom.Element; |
25 import org.w3c.dom.Node; | 32 import org.w3c.dom.Node; |
26 import org.w3c.dom.NodeList; | 33 import org.w3c.dom.NodeList; |
27 | 34 |
28 import org.apache.log4j.Logger; | 35 /** |
29 | 36 * Parser for GetCapabilities of a WMS. |
30 import org.dive4elements.artifacts.common.utils.XMLUtils; | 37 */ |
31 | |
32 import org.dive4elements.river.client.shared.exceptions.ServerException; | |
33 import org.dive4elements.river.client.shared.model.Capabilities; | |
34 import org.dive4elements.river.client.shared.model.ContactInformation; | |
35 import org.dive4elements.river.client.shared.model.WMSLayer; | |
36 | |
37 | |
38 public class CapabilitiesParser { | 38 public class CapabilitiesParser { |
39 | 39 |
40 private static final Logger logger = | 40 private static final Logger logger = |
41 Logger.getLogger(CapabilitiesParser.class); | 41 Logger.getLogger(CapabilitiesParser.class); |
42 | 42 |
94 "Service/AccessConstraints/text()"; | 94 "Service/AccessConstraints/text()"; |
95 | 95 |
96 public static final String XPATH_LAYERS = | 96 public static final String XPATH_LAYERS = |
97 "Capability/Layer"; | 97 "Capability/Layer"; |
98 | 98 |
99 public static final String XPATH_MAP_FORMAT = | |
100 "Capability/Request/GetMap/Format"; | |
101 | |
99 public static final Pattern SRS_PATTERN = Pattern.compile("(EPSG:\\d+)*"); | 102 public static final Pattern SRS_PATTERN = Pattern.compile("(EPSG:\\d+)*"); |
100 | 103 |
101 | 104 |
102 private CapabilitiesParser() { | 105 private CapabilitiesParser() { |
103 } | 106 } |
108 | 111 |
109 String log4jProperties = System.getenv(BaseServletContextListener.LOG4J_PROPERTIES); | 112 String log4jProperties = System.getenv(BaseServletContextListener.LOG4J_PROPERTIES); |
110 LoggingConfigurator.init(log4jProperties); | 113 LoggingConfigurator.init(log4jProperties); |
111 | 114 |
112 try { | 115 try { |
113 Capabilities caps = getCapabilities(System.getProperty("test.wms")); | 116 String wmsURL = System.getProperty("test.wms"); |
117 if (wmsURL == null || args.length > 0) { | |
118 wmsURL = args[0]; | |
119 } | |
120 Capabilities caps = getCapabilities(wmsURL); | |
114 | 121 |
115 logger.debug(caps.toString()); | 122 logger.debug(caps.toString()); |
123 System.out.println(caps.toString()); | |
116 } | 124 } |
117 catch (ServerException se) { | 125 catch (ServerException se) { |
118 se.printStackTrace(); | 126 se.printStackTrace(); |
119 } | 127 } |
120 | 128 |
203 capabilities, | 211 capabilities, |
204 XPATH_LAYERS, | 212 XPATH_LAYERS, |
205 XPathConstants.NODESET); | 213 XPathConstants.NODESET); |
206 | 214 |
207 List<WMSLayer> layers = parseLayers(layerNodes, onlineResource); | 215 List<WMSLayer> layers = parseLayers(layerNodes, onlineResource); |
216 | |
217 // Parse MIME types of supported return types, e.g. image/jpeg | |
218 NodeList mapFormatNodes = (NodeList) | |
219 XMLUtils.xpath(capabilities, XPATH_MAP_FORMAT, XPathConstants.NODESET); | |
220 List<String> mapFormats = new ArrayList<String>(); | |
221 for (int n = 0; n < mapFormatNodes.getLength(); n++) { | |
222 mapFormats.add(mapFormatNodes.item(n).getTextContent()); | |
223 } | |
208 | 224 |
209 return new Capabilities( | 225 return new Capabilities( |
210 title, | 226 title, |
211 onlineResource, | 227 onlineResource, |
212 ci, | 228 ci, |
213 fees, | 229 fees, |
214 accessConstraints, | 230 accessConstraints, |
215 layers); | 231 layers, |
232 mapFormats); | |
216 } | 233 } |
217 | 234 |
218 | 235 |
219 protected static Node getCapabilitiesNode(Document doc) | 236 protected static Node getCapabilitiesNode(Document doc) |
220 throws ServerException { | 237 throws ServerException { |