Mercurial > dive4elements > gnv-client
changeset 1121:9d530f913729
Added a helper class to handle xml related stuff.
geo-backend/trunk@1148 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 03 Jun 2010 12:35:35 +0000 (2010-06-03) |
parents | d387a97807a3 |
children | 1985d5db0feb |
files | geo-backend/ChangeLog geo-backend/src/main/java/de/intevation/gnv/geobackend/util/XMLUtils.java |
diffstat | 2 files changed, 66 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/geo-backend/ChangeLog Mon May 31 07:23:21 2010 +0000 +++ b/geo-backend/ChangeLog Thu Jun 03 12:35:35 2010 +0000 @@ -1,3 +1,8 @@ +2010-06-03 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + * src/main/java/de/intevation/gnv/geobackend/util/XMLUtils.java: Some + functions to handle xml stuff. + 2010-05-31 Ingo Weinzierl <ingo.weinzierl@intevation.de> * src/main/java/de/intevation/gnv/geobackend/base/query/DefaultQueryExceutor.java:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/util/XMLUtils.java Thu Jun 03 12:35:35 2010 +0000 @@ -0,0 +1,61 @@ +package de.intevation.gnv.geobackend.util; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; + +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.apache.log4j.Logger; + + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public final class XMLUtils { + + private static Logger logger = Logger.getLogger(XMLUtils.class); + + + private XMLUtils() { + } + + + public static Object xpath( + Object root, + String query, + QName returnType, + NamespaceContext namespaceContext + ) { + if (root == null) { + return null; + } + + try { + XPath xpath = newXPath(namespaceContext); + + if (xpath != null) { + return xpath.evaluate(query, root, returnType); + } + } + catch (XPathExpressionException xpee) { + logger.error(xpee.getLocalizedMessage(), xpee); + } + + return null; + } + + + public static XPath newXPath(NamespaceContext namespaceContext) { + XPathFactory factory = XPathFactory.newInstance(); + XPath xpath = factory.newXPath(); + + if (namespaceContext != null) { + xpath.setNamespaceContext(namespaceContext); + } + + return xpath; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :