Mercurial > dive4elements > gnv-client
comparison geo-backend/src/main/java/de/intevation/gnv/geobackend/util/XMLUtils.java @ 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 |
parents | |
children | ebeb56428409 |
comparison
equal
deleted
inserted
replaced
1120:d387a97807a3 | 1121:9d530f913729 |
---|---|
1 package de.intevation.gnv.geobackend.util; | |
2 | |
3 import javax.xml.namespace.NamespaceContext; | |
4 import javax.xml.namespace.QName; | |
5 | |
6 import javax.xml.xpath.XPath; | |
7 import javax.xml.xpath.XPathExpressionException; | |
8 import javax.xml.xpath.XPathFactory; | |
9 | |
10 import org.apache.log4j.Logger; | |
11 | |
12 | |
13 /** | |
14 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
15 */ | |
16 public final class XMLUtils { | |
17 | |
18 private static Logger logger = Logger.getLogger(XMLUtils.class); | |
19 | |
20 | |
21 private XMLUtils() { | |
22 } | |
23 | |
24 | |
25 public static Object xpath( | |
26 Object root, | |
27 String query, | |
28 QName returnType, | |
29 NamespaceContext namespaceContext | |
30 ) { | |
31 if (root == null) { | |
32 return null; | |
33 } | |
34 | |
35 try { | |
36 XPath xpath = newXPath(namespaceContext); | |
37 | |
38 if (xpath != null) { | |
39 return xpath.evaluate(query, root, returnType); | |
40 } | |
41 } | |
42 catch (XPathExpressionException xpee) { | |
43 logger.error(xpee.getLocalizedMessage(), xpee); | |
44 } | |
45 | |
46 return null; | |
47 } | |
48 | |
49 | |
50 public static XPath newXPath(NamespaceContext namespaceContext) { | |
51 XPathFactory factory = XPathFactory.newInstance(); | |
52 XPath xpath = factory.newXPath(); | |
53 | |
54 if (namespaceContext != null) { | |
55 xpath.setNamespaceContext(namespaceContext); | |
56 } | |
57 | |
58 return xpath; | |
59 } | |
60 } | |
61 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |