annotate artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java @ 64:8b72676698b5

Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action. artifacts/trunk@523 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Sat, 09 Jan 2010 16:59:00 +0000
parents 76abf0c64d3b
children ed03cc0e5800
rev   line source
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.artifactdatabase;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import org.w3c.dom.Document;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 import org.w3c.dom.Element;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 import org.w3c.dom.Attr;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6
62
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
7 import org.xml.sax.SAXException;
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
8
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 import javax.xml.parsers.DocumentBuilderFactory;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 import javax.xml.parsers.ParserConfigurationException;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 import org.apache.log4j.Logger;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14
23
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
15 import javax.xml.xpath.XPathFactory;
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
16 import javax.xml.xpath.XPath;
25
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
17 import javax.xml.xpath.XPathExpressionException;
26
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 25
diff changeset
18 import javax.xml.xpath.XPathConstants;
23
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
19
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
20 import javax.xml.namespace.NamespaceContext;
25
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
21 import javax.xml.namespace.QName;
23
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
22
62
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
23 import java.io.File;
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
24 import java.io.IOException;
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
25
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 /**
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 * @author Sascha L. Teichmann
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 */
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 public final class XMLUtils
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 {
64
8b72676698b5 Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 62
diff changeset
31 public static final String XFORM_URL = "http://www.w3.org/2002/xforms";
8b72676698b5 Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 62
diff changeset
32 public static final String XFORM_PREFIX = "xform";
8b72676698b5 Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 62
diff changeset
33
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 private static Logger logger = Logger.getLogger(XMLUtils.class);
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 private XMLUtils() {
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 }
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 public static class ElementCreator
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 {
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 protected Document document;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 protected String ns;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 protected String prefix;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 public ElementCreator(Document document, String ns, String prefix) {
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 this.document = document;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 this.ns = ns;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 this.prefix = prefix;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 }
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 public Element create(String name) {
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 Element element = document.createElementNS(ns, name);
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 element.setPrefix(prefix);
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 return element;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 }
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 public void addAttr(Element element, String name, String value) {
64
8b72676698b5 Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 62
diff changeset
58 addAttr(element, name, value, false);
8b72676698b5 Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 62
diff changeset
59 }
8b72676698b5 Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 62
diff changeset
60
8b72676698b5 Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 62
diff changeset
61 public void addAttr(
8b72676698b5 Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 62
diff changeset
62 Element element,
8b72676698b5 Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 62
diff changeset
63 String name,
8b72676698b5 Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 62
diff changeset
64 String value,
8b72676698b5 Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 62
diff changeset
65 boolean addPrefix
8b72676698b5 Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 62
diff changeset
66 ) {
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 Attr attr = document.createAttributeNS(ns, name);
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68 attr.setValue(value);
64
8b72676698b5 Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 62
diff changeset
69
8b72676698b5 Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 62
diff changeset
70 if (addPrefix)
8b72676698b5 Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 62
diff changeset
71 attr.setPrefix(prefix);
8b72676698b5 Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 62
diff changeset
72
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 element.setAttributeNode(attr);
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 }
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 } // class ElementCreator
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 public static final Document newDocument() {
64
8b72676698b5 Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 62
diff changeset
78 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
8b72676698b5 Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 62
diff changeset
79 factory.setNamespaceAware(true);
8b72676698b5 Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 62
diff changeset
80
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81 try {
64
8b72676698b5 Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 62
diff changeset
82 return factory.newDocumentBuilder().newDocument();
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83 }
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84 catch (ParserConfigurationException pce) {
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 logger.error(pce.getLocalizedMessage(), pce);
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86 }
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 return null;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88 }
23
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
89
62
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
90 public static final Document parseDocument(File file) {
64
8b72676698b5 Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 62
diff changeset
91 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
8b72676698b5 Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 62
diff changeset
92 factory.setNamespaceAware(true);
8b72676698b5 Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 62
diff changeset
93
62
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
94 try {
64
8b72676698b5 Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 62
diff changeset
95 return factory.newDocumentBuilder().parse(file);
62
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
96 }
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
97 catch (ParserConfigurationException pce) {
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
98 logger.error(pce.getLocalizedMessage(), pce);
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
99 }
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
100 catch (SAXException se) {
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
101 logger.error(se.getLocalizedMessage(), se);
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
102 }
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
103 catch (IOException ioe) {
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
104 logger.error(ioe.getLocalizedMessage(), ioe);
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
105 }
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
106 return null;
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
107 }
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
108
23
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
109 public static final XPath newXPath() {
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
110 return newXPath(null);
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
111 }
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
112
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
113 public static final XPath newXPath(NamespaceContext namespaceContext) {
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
114 XPathFactory factory = XPathFactory.newInstance();
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
115 XPath xpath = factory.newXPath();
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
116 if (namespaceContext != null) {
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
117 xpath.setNamespaceContext(namespaceContext);
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
118 }
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
119 return xpath;
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
120 }
25
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
121
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
122 public static final Object xpath(Object root, String query, QName returnTyp) {
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
123 return xpath(root, query, returnTyp, null);
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
124 }
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
125
26
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 25
diff changeset
126 public static final String xpathString(
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 25
diff changeset
127 Object root, String query, NamespaceContext namespaceContext
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 25
diff changeset
128 ) {
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 25
diff changeset
129 return (String)xpath(root, query, XPathConstants.STRING, namespaceContext);
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 25
diff changeset
130 }
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 25
diff changeset
131
25
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
132 public static final Object xpath(
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
133 Object root,
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
134 String query,
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
135 QName returnType,
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
136 NamespaceContext namespaceContext
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
137 ) {
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
138 if (root == null) {
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
139 return null;
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
140 }
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
141
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
142 try {
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
143 XPath xpath = newXPath(namespaceContext);
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
144 if (xpath != null) {
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
145 return xpath.evaluate(query, root, returnType);
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
146 }
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
147 }
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
148 catch (XPathExpressionException xpee) {
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
149 logger.error(xpee.getLocalizedMessage(), xpee);
47
4ae4dc99127d Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 26
diff changeset
150 }
25
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
151
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
152 return null;
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
153 }
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
154 }
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
155 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org