Mercurial > dive4elements > framework
changeset 23:00596a591a2f
Added possibibilty to ceate XPaths with namespace contextes.
artifacts/trunk@57 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 10 Sep 2009 08:14:03 +0000 |
parents | 72abee95fd64 |
children | d5dc2900392f |
files | Changelog artifact-database/src/main/java/de/intevation/artifactdatabase/Config.java artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java |
diffstat | 3 files changed, 28 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/Changelog Wed Sep 09 16:36:46 2009 +0000 +++ b/Changelog Thu Sep 10 08:14:03 2009 +0000 @@ -1,3 +1,11 @@ +2009-09-09 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java: + Added method newXPath() to create XPaths with namespace binding. + + * artifact-database/src/main/java/de/intevation/artifactdatabase/Config.java: + Uses new method from XMLUtils. + 2009-09-09 Sascha L. Teichmann <sascha.teichmann@intevation.de> * trunk/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/FactoriesResource.java,
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/Config.java Wed Sep 09 16:36:46 2009 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/Config.java Thu Sep 10 08:14:03 2009 +0000 @@ -15,8 +15,6 @@ import javax.xml.namespace.QName; -import javax.xml.xpath.XPathFactory; -import javax.xml.xpath.XPath; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathConstants; @@ -101,11 +99,8 @@ return null; } - XPathFactory factory = XPathFactory.newInstance(); - XPath xpath = factory.newXPath(); - try { - return xpath.evaluate(query, root, returnType); + return XMLUtils.newXPath().evaluate(query, root, returnType); } catch (XPathExpressionException xpee) { logger.error(xpee.getLocalizedMessage(), xpee);
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java Wed Sep 09 16:36:46 2009 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java Thu Sep 10 08:14:03 2009 +0000 @@ -10,6 +10,12 @@ import org.apache.log4j.Logger; +import javax.xml.xpath.XPathFactory; +import javax.xml.xpath.XPath; + +import javax.xml.namespace.NamespaceContext; + + /** * @author Sascha L. Teichmann */ @@ -58,5 +64,18 @@ } return null; } + + public static final XPath newXPath() { + return newXPath(null); + } + + public static final 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: