Mercurial > dive4elements > river
changeset 1416:16f19f12a962
Improved parsing of Capabilities document - parse '/WMT_MS_Capabilities' as well.
flys-client/trunk@3306 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 23 Nov 2011 09:45:22 +0000 |
parents | dfa2d4753fc0 |
children | 42d6cf6e10b7 |
files | flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/server/GCServiceImpl.java |
diffstat | 2 files changed, 51 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/ChangeLog Tue Nov 22 20:20:03 2011 +0000 +++ b/flys-client/ChangeLog Wed Nov 23 09:45:22 2011 +0000 @@ -1,3 +1,9 @@ +2011-11-23 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/client/server/GCServiceImpl.java: + Improved parsing Capabilities document - the root node of the document + can be "/WMS_Capabilities" oder "WMT_MS_Capabilities" now. + 2011-11-22 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/server/GCServiceImpl.java Tue Nov 22 20:20:03 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/GCServiceImpl.java Wed Nov 23 09:45:22 2011 +0000 @@ -43,14 +43,20 @@ public static final String ERR_MALFORMED_URL = "error_malformed_url"; + public static final String XPATH_WMS_CAPS = + "/WMS_Capabilities"; + + public static final String XPATH_WMT_CAPS = + "/WMT_MS_Capabilities"; + public static final String XPATH_TITLE = - "/WMS_Capabilities/Service/Title/text()"; + "Service/Title/text()"; public static final String XPATH_ONLINE_RESOURCE = - "/WMS_Capabilities/Service/OnlineResource/@href"; + "Service/OnlineResource/@href"; public static final String XPATH_CONTACT_INFORMATION = - "/WMS_Capabilities/Service/ContactInformation"; + "Service/ContactInformation"; public static final String XPATH_CI_PERSON = "ContactPersonPrimary/ContactPerson/text()"; @@ -74,13 +80,13 @@ "ContactElectronicMailAddress/text()"; public static final String XPATH_FEES = - "/WMS_Capabilities/Service/Fees/text()"; + "Service/Fees/text()"; public static final String XPATH_ACCESS_CONSTRAINTS = - "/WMS_Capabilities/Service/AccessConstraints/text()"; + "Service/AccessConstraints/text()"; public static final String XPATH_LAYERS = - "/WMS_Capabilities/Capability/Layer"; + "Capability/Layer"; private Logger logger = Logger.getLogger(GCServiceImpl.class); @@ -126,28 +132,30 @@ throw new ServerException(ERR_GC_DOC_NOT_VALID); } + Node capabilities = getCapabilitiesNode(doc); + String title = (String) XMLUtils.xpath( - doc, + capabilities, XPATH_TITLE, XPathConstants.STRING); String onlineResource = (String) XMLUtils.xpath( - doc, + capabilities, XPATH_ONLINE_RESOURCE, XPathConstants.STRING); String fees = (String) XMLUtils.xpath( - doc, + capabilities, XPATH_FEES, XPathConstants.STRING); String accessConstraints = (String) XMLUtils.xpath( - doc, + capabilities, XPATH_ACCESS_CONSTRAINTS, XPathConstants.STRING); Node contactInformation = (Node) XMLUtils.xpath( - doc, + capabilities, XPATH_CONTACT_INFORMATION, XPathConstants.NODE); @@ -157,7 +165,7 @@ logger.debug("Found access constraints: " + accessConstraints); NodeList layerNodes = (NodeList) XMLUtils.xpath( - doc, + capabilities, XPATH_LAYERS, XPathConstants.NODESET); @@ -173,6 +181,31 @@ } + protected Node getCapabilitiesNode(Document doc) + throws ServerException { + Node capabilities = (Node) XMLUtils.xpath( + doc, + XPATH_WMS_CAPS, + XPathConstants.NODE); + + if (capabilities == null) { + logger.info("No '/WMS_Capabilities' node found."); + logger.info("Try to find a '/WMT_MS_Capabilities' node."); + + capabilities = (Node) XMLUtils.xpath( + doc, + XPATH_WMT_CAPS, + XPathConstants.NODE); + } + + if (capabilities == null) { + throw new ServerException(ERR_GC_DOC_NOT_VALID); + } + + return capabilities; + } + + protected ContactInformation parseContactInformation(Node node) { String person = (String) XMLUtils.xpath( node,