comparison artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java @ 25:ccc6aae25585

Moved some XPath stuff from Config into XMLUtils. artifacts/trunk@59 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 10 Sep 2009 09:23:53 +0000
parents 00596a591a2f
children 83a059c204f8
comparison
equal deleted inserted replaced
24:d5dc2900392f 25:ccc6aae25585
10 10
11 import org.apache.log4j.Logger; 11 import org.apache.log4j.Logger;
12 12
13 import javax.xml.xpath.XPathFactory; 13 import javax.xml.xpath.XPathFactory;
14 import javax.xml.xpath.XPath; 14 import javax.xml.xpath.XPath;
15 import javax.xml.xpath.XPathExpressionException;
15 16
16 import javax.xml.namespace.NamespaceContext; 17 import javax.xml.namespace.NamespaceContext;
17 18 import javax.xml.namespace.QName;
18 19
19 /** 20 /**
20 * @author Sascha L. Teichmann 21 * @author Sascha L. Teichmann
21 */ 22 */
22 public final class XMLUtils 23 public final class XMLUtils
75 if (namespaceContext != null) { 76 if (namespaceContext != null) {
76 xpath.setNamespaceContext(namespaceContext); 77 xpath.setNamespaceContext(namespaceContext);
77 } 78 }
78 return xpath; 79 return xpath;
79 } 80 }
81
82 public static final Object xpath(Object root, String query, QName returnTyp) {
83 return xpath(root, query, returnTyp, null);
84 }
85
86 public static final Object xpath(
87 Object root,
88 String query,
89 QName returnType,
90 NamespaceContext namespaceContext
91 ) {
92 if (root == null) {
93 return null;
94 }
95
96 try {
97 XPath xpath = newXPath(namespaceContext);
98 if (xpath != null) {
99 return xpath.evaluate(query, root, returnType);
100 }
101 }
102 catch (XPathExpressionException xpee) {
103 logger.error(xpee.getLocalizedMessage(), xpee);
104 }
105
106 return null;
107 }
80 } 108 }
81 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: 109 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org