annotate artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java @ 203:b5e1949bc255

Implemented a new method in the ClientProtocolUtils that creates the document for a FEED operation. artifacts/trunk@1448 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 10 Mar 2011 08:26:08 +0000
parents 933bbc9fc11f
children
rev   line source
100
933bbc9fc11f Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 94
diff changeset
1 /*
933bbc9fc11f Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 94
diff changeset
2 * Copyright (c) 2010 by Intevation GmbH
933bbc9fc11f Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 94
diff changeset
3 *
933bbc9fc11f Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 94
diff changeset
4 * This program is free software under the LGPL (>=v2.1)
933bbc9fc11f Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 94
diff changeset
5 * Read the file LGPL.txt coming with the software for details
933bbc9fc11f Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 94
diff changeset
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
933bbc9fc11f Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 94
diff changeset
7 */
933bbc9fc11f Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 94
diff changeset
8
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 package de.intevation.artifactdatabase;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
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
11 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
12 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
13 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
14
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
15 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
16 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
17
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
18 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
19 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
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.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
22 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
23 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
24 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
25 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
26
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 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
28
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 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
30
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 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
32 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
33 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
34 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
35
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
36 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
37
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
38 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
39 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
40 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
41
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
42 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
43
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 /**
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
45 * 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
46 * 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
47 * @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
48 */
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 public final class XMLUtils
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 {
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
51 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
52 * W3C URL of XForms
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
53 */
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
54 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
55 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
56 * W3C prefix of XForms
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
57 */
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 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
59
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 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
61
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 private XMLUtils() {
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 }
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
65 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
66 * 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
67 * namespaces.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
68 */
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 public static class ElementCreator
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70 {
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 * 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
73 */
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 protected Document document;
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
75 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
76 * namespace to be used
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
77 */
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78 protected String ns;
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
79 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
80 * prefix to be used
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
81 */
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82 protected String prefix;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
84 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
85 * Constructor to create an element/attribute creator
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
86 * 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
87 * given owner document.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
88 * @param document The owning document
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
89 * @param ns The namespace
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
90 * @param prefix The namespace prefix
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
91 */
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 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
93 this.document = document;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94 this.ns = ns;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 this.prefix = prefix;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96 }
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
98 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
99 * 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
100 * the this creators namespace and namespace prefix.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
101 * @param name The name of the element
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
102 * @return The new element
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
103 */
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104 public Element create(String name) {
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 Element element = document.createElementNS(ns, name);
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106 element.setPrefix(prefix);
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107 return element;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108 }
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
110 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
111 * 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
112 * It does not set the namespace prefix.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
113 * @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
114 * @param name The name of the attribute
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
115 * @param value The value of the attribute
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
116 */
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
117 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
118 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
119 }
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
120
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
121 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
122 * 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
123 * 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
124 * @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
125 * @param name The name of the attribute
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
126 * @param value The value of the attribute
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
127 * @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
128 * set on the attribute.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
129 */
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 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
131 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
132 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
133 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
134 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
135 ) {
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
136 Attr attr = document.createAttributeNS(ns, name);
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
137 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
138
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
139 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
140 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
141
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
142 element.setAttributeNode(attr);
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
143 }
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
144 } // class ElementCreator
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
145
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
146 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
147 * Creates a new XML document
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
148 * @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
149 * creation.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
150 */
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
151 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
152 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
153 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
154
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
155 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
156 return factory.newDocumentBuilder().newDocument();
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
157 }
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
158 catch (ParserConfigurationException pce) {
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
159 logger.error(pce.getLocalizedMessage(), pce);
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
160 }
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
161 return null;
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162 }
23
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
163
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
164 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
165 * 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
166 * @param file The file to load.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
167 * @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
168 * during loading.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
169 */
62
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
170 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
171 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
172 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
173
62
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
174 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
175 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
176 }
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
177 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
178 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
179 }
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
180 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
181 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
182 }
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
183 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
184 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
185 }
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
186 return null;
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
diff changeset
187 }
76abf0c64d3b Added XML utils method to load XML file from file.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 47
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 without a namespace context.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
191 * @return the new XPath.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
192 */
23
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
193 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
194 return newXPath(null);
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
195 }
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
196
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
197 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
198 * 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
199 * @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
200 * if none should be used.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
201 * @return The new XPath
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
202 */
23
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
203 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
204 XPathFactory factory = XPathFactory.newInstance();
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
205 XPath xpath = factory.newXPath();
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
206 if (namespaceContext != null) {
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
207 xpath.setNamespaceContext(namespaceContext);
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
208 }
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
209 return xpath;
00596a591a2f Added possibibilty to ceate XPaths with namespace contextes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 20
diff changeset
210 }
25
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
211
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
212 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
213 * 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
214 * 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
215 * @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
216 * be searched in.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
217 * @param query The XPath query
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
218 * @param returnTyp The type of the result.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
219 * @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
220 * went wrong during XPath evaluation.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
221 */
94
5332d956729c Brought all line lengths of non Javadoc lines below 80.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 92
diff changeset
222 public static final Object xpath(
5332d956729c Brought all line lengths of non Javadoc lines below 80.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 92
diff changeset
223 Object root,
5332d956729c Brought all line lengths of non Javadoc lines below 80.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 92
diff changeset
224 String query,
5332d956729c Brought all line lengths of non Javadoc lines below 80.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 92
diff changeset
225 QName returnTyp
5332d956729c Brought all line lengths of non Javadoc lines below 80.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 92
diff changeset
226 ) {
25
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
227 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
228 }
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
229
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
230 /**
92
73d0ebae81d7 Last bunch of javadoc
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 91
diff changeset
231 * Evaluates an XPath query on a given object and returns the result
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
232 * 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
233 * @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
234 * be searched in.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
235 * @param query The XPath query
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
236 * @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
237 * if none should be used.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
238 * @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
239 * during XPath evaluation.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
240 */
26
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 25
diff changeset
241 public static final String xpathString(
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 25
diff changeset
242 Object root, String query, NamespaceContext namespaceContext
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 25
diff changeset
243 ) {
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
244 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
245 root, query, XPathConstants.STRING, namespaceContext);
26
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 25
diff changeset
246 }
83a059c204f8 Connected /create with artifact db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 25
diff changeset
247
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
248 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
249 * 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
250 * 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
251 * @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
252 * be searched in.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
253 * @param query The XPath query
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
254 * @param returnType The type of the result.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
255 * @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
256 * if none should be used.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
257 * @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
258 * went wrong during XPath evaluation.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
259 */
25
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
260 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
261 Object root,
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
262 String query,
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
263 QName returnType,
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
264 NamespaceContext namespaceContext
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
265 ) {
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
266 if (root == null) {
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
267 return null;
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
268 }
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
269
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
270 try {
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
271 XPath xpath = newXPath(namespaceContext);
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
272 if (xpath != null) {
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
273 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
274 }
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
275 }
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
276 catch (XPathExpressionException xpee) {
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
277 logger.error(xpee.getLocalizedMessage(), xpee);
47
4ae4dc99127d Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 26
diff changeset
278 }
25
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
279
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
280 return null;
ccc6aae25585 Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 23
diff changeset
281 }
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
282
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
283 /**
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
284 * 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
285 * @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
286 * @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
287 * @return true if operation succeeded else false.
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
288 */
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
289 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
290 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
291 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
292 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
293 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
294 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
295 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
296 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
297 }
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
298 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
299 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
300 }
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
301 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
302 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
303 }
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
304 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
305 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
306 }
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
307
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
308 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
309 }
20
ff666592c1c3 Added factory listing '/factories' to web app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
310 }
91
730ff077a58c More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 77
diff changeset
311 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org