Mercurial > dive4elements > gnv-client
annotate geo-backend/src/main/java/de/intevation/gnv/geobackend/util/XMLUtils.java @ 1125:959618206b8a
Write svn revision to MANIFEST file while packaging.
geo-backend/trunk@1212 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 14 Jun 2010 21:14:12 +0000 |
parents | 9d530f913729 |
children | ebeb56428409 |
rev | line source |
---|---|
1121
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.gnv.geobackend.util; |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import javax.xml.namespace.NamespaceContext; |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 import javax.xml.namespace.QName; |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 import javax.xml.xpath.XPath; |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 import javax.xml.xpath.XPathExpressionException; |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 import javax.xml.xpath.XPathFactory; |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 import org.apache.log4j.Logger; |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 /** |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 */ |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 public final class XMLUtils { |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 private static Logger logger = Logger.getLogger(XMLUtils.class); |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 private XMLUtils() { |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 } |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 public static Object xpath( |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 Object root, |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 String query, |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 QName returnType, |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 NamespaceContext namespaceContext |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 ) { |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 if (root == null) { |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 return null; |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 } |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 try { |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 XPath xpath = newXPath(namespaceContext); |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 if (xpath != null) { |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 return xpath.evaluate(query, root, returnType); |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 } |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 } |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 catch (XPathExpressionException xpee) { |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 logger.error(xpee.getLocalizedMessage(), xpee); |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 } |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 return null; |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 } |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 public static XPath newXPath(NamespaceContext namespaceContext) { |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 XPathFactory factory = XPathFactory.newInstance(); |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 XPath xpath = factory.newXPath(); |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 if (namespaceContext != null) { |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 xpath.setNamespaceContext(namespaceContext); |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 } |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 return xpath; |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 } |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 } |
9d530f913729
Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |