Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/server/CapabilitiesParser.java @ 8203:238fc722f87a
sed 's/logger/log/g' src/**/*.java
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Fri, 05 Sep 2014 13:19:22 +0200 |
parents | 8c7433b8656d |
children | fc54202a4b1e |
comparison
equal
deleted
inserted
replaced
8202:e4606eae8ea5 | 8203:238fc722f87a |
---|---|
35 /** | 35 /** |
36 * Parser for GetCapabilities of a WMS. | 36 * Parser for GetCapabilities of a WMS. |
37 */ | 37 */ |
38 public class CapabilitiesParser { | 38 public class CapabilitiesParser { |
39 | 39 |
40 private static final Logger logger = | 40 private static final Logger log = |
41 Logger.getLogger(CapabilitiesParser.class); | 41 Logger.getLogger(CapabilitiesParser.class); |
42 | 42 |
43 | 43 |
44 public static final String ERR_GC_REQUEST_FAILED = | 44 public static final String ERR_GC_REQUEST_FAILED = |
45 "error_gc_req_failed"; | 45 "error_gc_req_failed"; |
108 private CapabilitiesParser() { | 108 private CapabilitiesParser() { |
109 } | 109 } |
110 | 110 |
111 | 111 |
112 public static void main(String[] args) { | 112 public static void main(String[] args) { |
113 logger.info("Do static Capabilities request/parsing."); | 113 log.info("Do static Capabilities request/parsing."); |
114 | 114 |
115 String log4jProperties = System.getenv(BaseServletContextListener.LOG4J_PROPERTIES); | 115 String log4jProperties = System.getenv(BaseServletContextListener.LOG4J_PROPERTIES); |
116 LoggingConfigurator.init(log4jProperties); | 116 LoggingConfigurator.init(log4jProperties); |
117 | 117 |
118 try { | 118 try { |
120 if (wmsURL == null || args.length > 0) { | 120 if (wmsURL == null || args.length > 0) { |
121 wmsURL = args[0]; | 121 wmsURL = args[0]; |
122 } | 122 } |
123 Capabilities caps = getCapabilities(wmsURL); | 123 Capabilities caps = getCapabilities(wmsURL); |
124 | 124 |
125 logger.debug(caps.toString()); | 125 log.debug(caps.toString()); |
126 System.out.println(caps.toString()); | 126 System.out.println(caps.toString()); |
127 } | 127 } |
128 catch (ServerException se) { | 128 catch (ServerException se) { |
129 se.printStackTrace(); | 129 se.printStackTrace(); |
130 } | 130 } |
131 | 131 |
132 logger.info("Finished fetching capabiltiies."); | 132 log.info("Finished fetching capabiltiies."); |
133 } | 133 } |
134 | 134 |
135 | 135 |
136 public static Capabilities getCapabilities(String urlStr) | 136 public static Capabilities getCapabilities(String urlStr) |
137 throws ServerException | 137 throws ServerException |
138 { | 138 { |
139 try { | 139 try { |
140 URL url = new URL(urlStr); | 140 URL url = new URL(urlStr); |
141 | 141 |
142 logger.debug("Open connection to url: " + urlStr); | 142 log.debug("Open connection to url: " + urlStr); |
143 | 143 |
144 URLConnection conn = url.openConnection(); | 144 URLConnection conn = url.openConnection(); |
145 conn.connect(); | 145 conn.connect(); |
146 | 146 |
147 InputStream is = conn.getInputStream(); | 147 InputStream is = conn.getInputStream(); |
148 | 148 |
149 return parse(is); | 149 return parse(is); |
150 } | 150 } |
151 catch (MalformedURLException mue) { | 151 catch (MalformedURLException mue) { |
152 logger.warn(mue, mue); | 152 log.warn(mue, mue); |
153 throw new ServerException(ERR_MALFORMED_URL); | 153 throw new ServerException(ERR_MALFORMED_URL); |
154 } | 154 } |
155 catch (IOException ioe) { | 155 catch (IOException ioe) { |
156 logger.warn(ioe, ioe); | 156 log.warn(ioe, ioe); |
157 } | 157 } |
158 | 158 |
159 throw new ServerException(ERR_GC_REQUEST_FAILED); | 159 throw new ServerException(ERR_GC_REQUEST_FAILED); |
160 } | 160 } |
161 | 161 |
162 | 162 |
163 protected static Capabilities parse(InputStream is) | 163 protected static Capabilities parse(InputStream is) |
164 throws ServerException | 164 throws ServerException |
165 { | 165 { |
166 logger.debug("GCServiceImpl.parseCapabilitiesResponse"); | 166 log.debug("GCServiceImpl.parseCapabilitiesResponse"); |
167 | 167 |
168 Document doc = XMLUtils.parseDocument(is, false); | 168 Document doc = XMLUtils.parseDocument(is, false); |
169 | 169 |
170 if (doc == null) { | 170 if (doc == null) { |
171 throw new ServerException(ERR_GC_DOC_NOT_VALID); | 171 throw new ServerException(ERR_GC_DOC_NOT_VALID); |
205 XPATH_CONTACT_INFORMATION, | 205 XPATH_CONTACT_INFORMATION, |
206 XPathConstants.NODE); | 206 XPathConstants.NODE); |
207 | 207 |
208 ContactInformation ci = parseContactInformation(contactInformation); | 208 ContactInformation ci = parseContactInformation(contactInformation); |
209 | 209 |
210 logger.debug("Found fees: " + fees); | 210 log.debug("Found fees: " + fees); |
211 logger.debug("Found access constraints: " + accessConstraints); | 211 log.debug("Found access constraints: " + accessConstraints); |
212 | 212 |
213 NodeList layerNodes = (NodeList) XMLUtils.xpath( | 213 NodeList layerNodes = (NodeList) XMLUtils.xpath( |
214 capabilities, | 214 capabilities, |
215 XPATH_LAYERS, | 215 XPATH_LAYERS, |
216 XPathConstants.NODESET); | 216 XPathConstants.NODESET); |
247 doc, | 247 doc, |
248 XPATH_WMS_CAPS, | 248 XPATH_WMS_CAPS, |
249 XPathConstants.NODE); | 249 XPathConstants.NODE); |
250 | 250 |
251 if (capabilities == null) { | 251 if (capabilities == null) { |
252 logger.info("No '/WMS_Capabilities' node found."); | 252 log.info("No '/WMS_Capabilities' node found."); |
253 logger.info("Try to find a '/WMT_MS_Capabilities' node."); | 253 log.info("Try to find a '/WMT_MS_Capabilities' node."); |
254 | 254 |
255 capabilities = (Node) XMLUtils.xpath( | 255 capabilities = (Node) XMLUtils.xpath( |
256 doc, | 256 doc, |
257 XPATH_WMT_CAPS, | 257 XPATH_WMT_CAPS, |
258 XPathConstants.NODE); | 258 XPathConstants.NODE); |
325 NodeList layersNode, | 325 NodeList layersNode, |
326 String onlineResource | 326 String onlineResource |
327 ) { | 327 ) { |
328 int len = layersNode != null ? layersNode.getLength() : 0; | 328 int len = layersNode != null ? layersNode.getLength() : 0; |
329 | 329 |
330 logger.debug("Node has " + len + " layers."); | 330 log.debug("Node has " + len + " layers."); |
331 | 331 |
332 List<WMSLayer> layers = new ArrayList<WMSLayer>(len); | 332 List<WMSLayer> layers = new ArrayList<WMSLayer>(len); |
333 | 333 |
334 for (int i = 0; i < len; i++) { | 334 for (int i = 0; i < len; i++) { |
335 layers.add(parseLayer(layersNode.item(i), onlineResource)); | 335 layers.add(parseLayer(layersNode.item(i), onlineResource)); |
348 String name = (String) XMLUtils.xpath( | 348 String name = (String) XMLUtils.xpath( |
349 layerNode, | 349 layerNode, |
350 "Name/text()", | 350 "Name/text()", |
351 XPathConstants.STRING); | 351 XPathConstants.STRING); |
352 | 352 |
353 logger.debug("Found layer: " + title + "(" + name + ")"); | 353 log.debug("Found layer: " + title + "(" + name + ")"); |
354 | 354 |
355 boolean queryable = true; | 355 boolean queryable = true; |
356 Node queryableAttr = layerNode.getAttributes().getNamedItem("queryable"); | 356 Node queryableAttr = layerNode.getAttributes().getNamedItem("queryable"); |
357 if (queryableAttr != null && queryableAttr.getNodeValue().equals("0")) { | 357 if (queryableAttr != null && queryableAttr.getNodeValue().equals("0")) { |
358 queryable = false; | 358 queryable = false; |
376 | 376 |
377 if (srsNodes.getLength() == 0) { | 377 if (srsNodes.getLength() == 0) { |
378 srsNodes = ((Element) layerNode).getElementsByTagName("CRS"); | 378 srsNodes = ((Element) layerNode).getElementsByTagName("CRS"); |
379 | 379 |
380 if (srsNodes.getLength() == 0) { | 380 if (srsNodes.getLength() == 0) { |
381 logger.debug("No explicit SRS for this layer specified."); | 381 log.debug("No explicit SRS for this layer specified."); |
382 return null; | 382 return null; |
383 } | 383 } |
384 } | 384 } |
385 | 385 |
386 List<String> allSRS = new ArrayList<String>(); | 386 List<String> allSRS = new ArrayList<String>(); |
428 | 428 |
429 protected static String getSRSFromString(String singleSrs) { | 429 protected static String getSRSFromString(String singleSrs) { |
430 Matcher m = SRS_PATTERN.matcher(singleSrs); | 430 Matcher m = SRS_PATTERN.matcher(singleSrs); |
431 | 431 |
432 if (m.matches()) { | 432 if (m.matches()) { |
433 logger.debug("Found SRS '" + m.group(1) + "'"); | 433 log.debug("Found SRS '" + m.group(1) + "'"); |
434 return m.group(1); | 434 return m.group(1); |
435 } | 435 } |
436 | 436 |
437 return null; | 437 return null; |
438 } | 438 } |