annotate artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java @ 91:730ff077a58c

More javadoc, some code formatting. artifacts/trunk@847 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 28 Mar 2010 10:01:03 +0000
parents 48d1a9a082c2
children 73d0ebae81d7
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
67
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
3 import java.io.File;
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
4 import java.io.IOException;
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
5 import java.io.OutputStream;
23
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
6
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
7 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
8 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
9
67
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
10 import javax.xml.parsers.DocumentBuilderFactory;
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
11 import javax.xml.parsers.ParserConfigurationException;
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
12
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
13 import javax.xml.transform.Transformer;
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
14 import javax.xml.transform.TransformerConfigurationException;
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
15 import javax.xml.transform.TransformerException;
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
16 import javax.xml.transform.TransformerFactory;
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
17 import javax.xml.transform.TransformerFactoryConfigurationError;
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
18
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
19 import javax.xml.transform.dom.DOMSource;
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
20
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
21 import javax.xml.transform.stream.StreamResult;
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
22
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
23 import javax.xml.xpath.XPath;
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
24 import javax.xml.xpath.XPathConstants;
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
25 import javax.xml.xpath.XPathExpressionException;
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
26 import javax.xml.xpath.XPathFactory;
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
27
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
28 import org.apache.log4j.Logger;
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
29
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
30 import org.w3c.dom.Attr;
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
31 import org.w3c.dom.Document;
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
32 import org.w3c.dom.Element;
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
33
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
34 import org.xml.sax.SAXException;
62
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
35
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 /**
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
37 * Some helper functions to ease work with XML concering namespaces, XPATH
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
38 * and so on.
77
48d1a9a082c2 Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 67
diff changeset
39 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
20
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 public final class XMLUtils
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 {
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
43 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
44 * W3C URL of XForms
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
45 */
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
46 public static final String XFORM_URL = "http://www.w3.org/2002/xforms";
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
47 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
48 * W3C prefix of XForms
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
49 */
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
50 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
51
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 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
53
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 private XMLUtils() {
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
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
57 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
58 * Helper class to generate elements and attributes with
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
59 * namespaces.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
60 */
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 public static class ElementCreator
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 {
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
63 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
64 * owner document of the elements to be created
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
65 */
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66 protected Document document;
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
67 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
68 * namespace to be used
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
69 */
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70 protected String ns;
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
71 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
72 * prefix to be used
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
73 */
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 protected String prefix;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
76 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
77 * Constructor to create an element/attribute creator
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
78 * with a given namespace and namespace prefix using a
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
79 * given owner document.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
80 * @param document The owning document
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
81 * @param ns The namespace
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
82 * @param prefix The namespace prefix
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
83 */
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84 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
85 this.document = document;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86 this.ns = ns;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 this.prefix = prefix;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88 }
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
90 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
91 * Creates a new element using the owning document with
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
92 * the this creators namespace and namespace prefix.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
93 * @param name The name of the element
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
94 * @return The new element
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
95 */
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96 public Element create(String name) {
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 Element element = document.createElementNS(ns, name);
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98 element.setPrefix(prefix);
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99 return element;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 }
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
102 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
103 * Adds a new attribute and its value to a given element.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
104 * It does not set the namespace prefix.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
105 * @param element The element to add the attribute to
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
106 * @param name The name of the attribute
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
107 * @param value The value of the attribute
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
108 */
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109 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
110 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
111 }
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
112
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
113 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
114 * Adds a new attribute and its value to a given element.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
115 * If the namespace prefix is used is decided by the 'addPrefix' flag.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
116 * @param element The element to add the attribute to
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
117 * @param name The name of the attribute
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
118 * @param value The value of the attribute
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
119 * @param addPrefix If true the creators namespace prefix is
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
120 * set on the attribute.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
121 */
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
122 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
123 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
124 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
125 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
126 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
127 ) {
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
128 Attr attr = document.createAttributeNS(ns, name);
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
129 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
130
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
131 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
132 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
133
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
134 element.setAttributeNode(attr);
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
135 }
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
136 } // class ElementCreator
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
137
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
138 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
139 * Creates a new XML document
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
140 * @return the new XML document ot null if something went wrong during
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
141 * creation.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
142 */
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
143 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
144 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
145 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
146
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
147 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
148 return factory.newDocumentBuilder().newDocument();
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
149 }
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
150 catch (ParserConfigurationException pce) {
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
151 logger.error(pce.getLocalizedMessage(), pce);
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
152 }
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
153 return null;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
154 }
23
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
155
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
156 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
157 * Loads a XML document namespace aware from a file
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
158 * @param file The file to load.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
159 * @return the XML document or null if something went wrong
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
160 * during loading.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
161 */
62
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
162 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
163 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
164 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
165
62
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
166 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
167 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
168 }
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
169 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
170 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
171 }
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
172 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
173 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
174 }
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
175 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
176 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
177 }
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
178 return null;
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
179 }
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
180
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
181 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
182 * Creates a new XPath without a namespace context.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
183 * @return the new XPath.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
184 */
23
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
185 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
186 return newXPath(null);
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
187 }
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
188
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
189 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
190 * Creates a new XPath with a given namespace context.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
191 * @param namespaceContext The namespace context to be used or null
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
192 * if none should be used.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
193 * @return The new XPath
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
194 */
23
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
195 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
196 XPathFactory factory = XPathFactory.newInstance();
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
197 XPath xpath = factory.newXPath();
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
198 if (namespaceContext != null) {
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
199 xpath.setNamespaceContext(namespaceContext);
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
200 }
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
201 return xpath;
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
202 }
25
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
203
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
204 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
205 * Evaluates an XPath query on a given object and returns the result
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
206 * as a given type. No namespace context is used.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
207 * @param root The object which is used as the root of the tree to
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
208 * be searched in.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
209 * @param query The XPath query
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
210 * @param returnTyp The type of the result.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
211 * @return The result of type 'returnTyp' or null if something
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
212 * went wrong during XPath evaluation.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
213 */
25
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
214 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
215 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
216 }
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
217
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
218 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
219 * Evaluates an XPath query on a given objectr and returns the result
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
220 * as a string. A given namespace context is used.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
221 * @param root The object which is used as the root of the tree to
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
222 * be searched in.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
223 * @param query The XPath query
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
224 * @param namespaceContext The namespace context to be used or null
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
225 * if none should be used.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
226 * @return The result of the query or null if something went wrong
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
227 * during XPath evaluation.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
228 */
26
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 25
diff changeset
229 public static final String xpathString(
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 25
diff changeset
230 Object root, String query, NamespaceContext namespaceContext
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 25
diff changeset
231 ) {
67
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
232 return (String)xpath(
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
233 root, query, XPathConstants.STRING, namespaceContext);
26
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 25
diff changeset
234 }
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 25
diff changeset
235
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
236 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
237 * Evaluates an XPath query on a given object and returns the result
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
238 * as a given type. Optionally a namespace context is used.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
239 * @param root The object which is used as the root of the tree to
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
240 * be searched in.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
241 * @param query The XPath query
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
242 * @param returnType The type of the result.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
243 * @param namespaceContext The namespace context to be used or null
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
244 * if none should be used.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
245 * @return The result of type 'returnTyp' or null if something
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
246 * went wrong during XPath evaluation.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
247 */
25
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
248 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
249 Object root,
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
250 String query,
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
251 QName returnType,
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
252 NamespaceContext namespaceContext
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
253 ) {
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
254 if (root == null) {
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
255 return null;
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
256 }
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
257
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
258 try {
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
259 XPath xpath = newXPath(namespaceContext);
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
260 if (xpath != null) {
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
261 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
262 }
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
263 }
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
264 catch (XPathExpressionException xpee) {
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
265 logger.error(xpee.getLocalizedMessage(), xpee);
47
4ae4dc99127d Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 26
diff changeset
266 }
25
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
267
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
268 return null;
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
269 }
67
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
270
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
271 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
272 * Streams out an XML document to a given output stream.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
273 * @param document The document to be streamed out.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
274 * @param out The output stream to be used.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
275 * @return true if operation succeeded else false.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
276 */
67
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
277 public static boolean toStream(Document document, OutputStream out) {
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
278 try {
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
279 Transformer transformer =
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
280 TransformerFactory.newInstance().newTransformer();
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
281 DOMSource source = new DOMSource(document);
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
282 StreamResult result = new StreamResult(out);
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
283 transformer.transform(source, result);
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
284 return true;
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
285 }
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
286 catch (TransformerConfigurationException tce) {
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
287 logger.error(tce.getLocalizedMessage(), tce);
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
288 }
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
289 catch (TransformerFactoryConfigurationError tfce) {
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
290 logger.error(tfce.getLocalizedMessage(), tfce);
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
291 }
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
292 catch (TransformerException te) {
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
293 logger.error(te.getLocalizedMessage(), te);
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
294 }
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
295
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
296 return false;
ed03cc0e5800 Added method to XMLUtils to copy an XML document to an output stream.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 64
diff changeset
297 }
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
298 }
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
299 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org