annotate geo-backend/src/main/java/de/intevation/gnv/geobackend/util/XMLUtils.java @ 1144:f444cfce0b3d

dummy merge for repo head
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:15:22 +0200
parents ebeb56428409
children
rev   line source
1127
ebeb56428409 Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1121
diff changeset
1 /*
ebeb56428409 Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1121
diff changeset
2 * Copyright (c) 2010 by Intevation GmbH
ebeb56428409 Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1121
diff changeset
3 *
ebeb56428409 Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1121
diff changeset
4 * This program is free software under the LGPL (>=v2.1)
ebeb56428409 Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1121
diff changeset
5 * Read the file LGPL.txt coming with the software for details
ebeb56428409 Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1121
diff changeset
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
ebeb56428409 Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1121
diff changeset
7 */
ebeb56428409 Added license headers and license file.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1121
diff changeset
8
1121
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 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
10
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import javax.xml.namespace.NamespaceContext;
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 import javax.xml.namespace.QName;
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 import javax.xml.xpath.XPath;
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 import javax.xml.xpath.XPathExpressionException;
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 import javax.xml.xpath.XPathFactory;
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 import org.apache.log4j.Logger;
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 /**
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 * @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
23 */
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 public final class XMLUtils {
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 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
27
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29 private XMLUtils() {
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
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33 public static Object xpath(
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 Object root,
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 String query,
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 QName returnType,
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37 NamespaceContext namespaceContext
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 ) {
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39 if (root == null) {
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 return null;
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
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 try {
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 XPath xpath = newXPath(namespaceContext);
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 if (xpath != null) {
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47 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
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 catch (XPathExpressionException xpee) {
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 logger.error(xpee.getLocalizedMessage(), xpee);
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 }
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 return null;
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 }
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 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
59 XPathFactory factory = XPathFactory.newInstance();
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 XPath xpath = factory.newXPath();
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62 if (namespaceContext != null) {
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63 xpath.setNamespaceContext(namespaceContext);
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 }
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 return xpath;
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 }
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 }
9d530f913729 Added a helper class to handle xml related stuff.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org