Mercurial > dive4elements > river
annotate flys-aft/src/main/java/de/intevation/utils/XML.java @ 5779:ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
XML DOM is not thread safe. Therefore the old implementation only allowed one thread
to use the builder at a time. As the complexity of the configuration
has increased over time this has become a bottleneck of the whole application
because it took quiet some time to build a result. Furthermore the builder code path
is visited very frequent. So many concurrent requests were piled up
resulting in long waits for the users.
To mitigate this problem a round robin pool of builders is used now.
Each of the pooled builders has an independent copy of the XML template
and can be run in parallel.
The number of builders is determined by the system property
'flys.datacage.pool.size'. It defaults to 4.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Sun, 21 Apr 2013 12:48:09 +0200 |
parents | f939e1e6cfa4 |
children |
rev | line source |
---|---|
4070
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.utils; |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import java.io.BufferedInputStream; |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 import java.io.File; |
4772
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
5 import java.io.FileInputStream; |
4070
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 import java.io.IOException; |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 import java.io.InputStream; |
4095
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
8 import java.io.OutputStream; |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
9 import java.io.StringWriter; |
4070
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 import java.util.HashMap; |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 import java.util.Map; |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 import javax.xml.namespace.NamespaceContext; |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 import javax.xml.namespace.QName; |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 |
4772
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
17 import javax.xml.parsers.DocumentBuilderFactory; |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
18 import javax.xml.parsers.ParserConfigurationException; |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
19 |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
20 import javax.xml.transform.Transformer; |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
21 import javax.xml.transform.TransformerConfigurationException; |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
22 import javax.xml.transform.TransformerException; |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
23 import javax.xml.transform.TransformerFactory; |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
24 import javax.xml.transform.TransformerFactoryConfigurationError; |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
25 |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
26 import javax.xml.transform.dom.DOMResult; |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
27 import javax.xml.transform.dom.DOMSource; |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
28 |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
29 import javax.xml.transform.stream.StreamResult; |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
30 import javax.xml.transform.stream.StreamSource; |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
31 |
4070
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 import javax.xml.xpath.XPath; |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 import javax.xml.xpath.XPathExpressionException; |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 import javax.xml.xpath.XPathFactory; |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 import javax.xml.xpath.XPathVariableResolver; |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 |
4772
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
37 import org.apache.log4j.Logger; |
4083
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
38 |
4772
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
39 import org.w3c.dom.Document; |
4083
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
40 |
4772
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
41 import org.xml.sax.SAXException; |
4083
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
42 |
4070
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 public final class XML |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 /** Logger for this class. */ |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 private static Logger log = Logger.getLogger(XML.class); |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 public static class MapXPathVariableResolver |
4736
b195fede1c3b
Remove trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4095
diff
changeset
|
49 implements XPathVariableResolver |
4070
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 protected Map<String, String> variables; |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 public MapXPathVariableResolver() { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 this.variables = new HashMap<String, String>(); |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 public MapXPathVariableResolver(Map<String, String> variables) { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 this.variables = variables; |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 public void addVariable(String name, String value) { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 variables.put(name, value); |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 @Override |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 public Object resolveVariable(QName variableName) { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 String key = variableName.getLocalPart(); |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 return variables.get(key); |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 } // class MapXPathVariableResolver |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 private XML() { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 |
4095
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
79 /** |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
80 * Creates a new XML document |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
81 * @return the new XML document ot null if something went wrong during |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
82 * creation. |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
83 */ |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
84 public static final Document newDocument() { |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
85 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
86 factory.setNamespaceAware(true); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
87 |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
88 try { |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
89 return factory.newDocumentBuilder().newDocument(); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
90 } |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
91 catch (ParserConfigurationException pce) { |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
92 log.error(pce.getLocalizedMessage(), pce); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
93 } |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
94 return null; |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
95 } |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
96 |
4070
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 /** |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 * Loads a XML document namespace aware from a file |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 * @param file The file to load. |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 * @return the XML document or null if something went wrong |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 * during loading. |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 */ |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 public static final Document parseDocument(File file) { |
4072
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4070
diff
changeset
|
104 return parseDocument(file, Boolean.TRUE); |
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4070
diff
changeset
|
105 } |
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4070
diff
changeset
|
106 |
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4070
diff
changeset
|
107 public static final Document parseDocument(File file, Boolean namespaceAware) { |
4070
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 InputStream inputStream = null; |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 try { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 inputStream = new BufferedInputStream(new FileInputStream(file)); |
4072
88f801888d85
load configuration an setup db connections.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4070
diff
changeset
|
111 return parseDocument(inputStream, namespaceAware); |
4070
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 catch (IOException ioe) { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 log.error(ioe.getLocalizedMessage(), ioe); |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 finally { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 if (inputStream != null) { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 try { inputStream.close(); } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 catch (IOException ioe) {} |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 return null; |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 public static final Document parseDocument(InputStream inputStream) { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 return parseDocument(inputStream, Boolean.TRUE); |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 public static final Document parseDocument( |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 InputStream inputStream, |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 Boolean namespaceAware |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 ) { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 if (namespaceAware != null) { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 factory.setNamespaceAware(namespaceAware.booleanValue()); |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 try { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 return factory.newDocumentBuilder().parse(inputStream); |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 catch (ParserConfigurationException pce) { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 log.error(pce.getLocalizedMessage(), pce); |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 catch (SAXException se) { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 log.error(se.getLocalizedMessage(), se); |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 catch (IOException ioe) { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 log.error(ioe.getLocalizedMessage(), ioe); |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 return null; |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 /** |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 * Creates a new XPath without a namespace context. |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 * @return the new XPath. |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 */ |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 public static final XPath newXPath() { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 return newXPath(null, null); |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 /** |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 * Creates a new XPath with a given namespace context. |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 * @param namespaceContext The namespace context to be used or null |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 * if none should be used. |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 * @return The new XPath |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 */ |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 public static final XPath newXPath( |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 NamespaceContext namespaceContext, |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 XPathVariableResolver resolver) |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 XPathFactory factory = XPathFactory.newInstance(); |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 XPath xpath = factory.newXPath(); |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 if (namespaceContext != null) { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 xpath.setNamespaceContext(namespaceContext); |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
178 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
179 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 if (resolver != null) { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 xpath.setXPathVariableResolver(resolver); |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 return xpath; |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
184 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
185 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 /** |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
187 * Evaluates an XPath query on a given object and returns the result |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
188 * as a given type. No namespace context is used. |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
189 * @param root The object which is used as the root of the tree to |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
190 * be searched in. |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
191 * @param query The XPath query |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 * @param returnTyp The type of the result. |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
193 * @return The result of type 'returnTyp' or null if something |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
194 * went wrong during XPath evaluation. |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
195 */ |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
196 public static final Object xpath( |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 Object root, |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
198 String query, |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
199 QName returnTyp |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
200 ) { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
201 return xpath(root, query, returnTyp, null); |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
202 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
203 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
204 /** |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
205 * Evaluates an XPath query on a given object and returns the result |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
206 * as a given type. Optionally a namespace context is used. |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
207 * @param root The object which is used as the root of the tree to |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
208 * be searched in. |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
209 * @param query The XPath query |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
210 * @param returnType The type of the result. |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
211 * @param namespaceContext The namespace context to be used or null |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
212 * if none should be used. |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
213 * @return The result of type 'returnTyp' or null if something |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
214 * went wrong during XPath evaluation. |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
215 */ |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
216 public static final Object xpath( |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
217 Object root, |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
218 String query, |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
219 QName returnType, |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
220 NamespaceContext namespaceContext |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
221 ) { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
222 return xpath(root, query, returnType, namespaceContext, null); |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
223 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
224 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
225 public static final Object xpath( |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
226 Object root, |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
227 String query, |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
228 QName returnType, |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
229 NamespaceContext namespaceContext, |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
230 Map<String, String> variables) |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
231 { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
232 if (root == null) { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
233 return null; |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
234 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
235 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
236 XPathVariableResolver resolver = variables != null |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
237 ? new MapXPathVariableResolver(variables) |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
238 : null; |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
239 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
240 try { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
241 XPath xpath = newXPath(namespaceContext, resolver); |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
242 if (xpath != null) { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
243 return xpath.evaluate(query, root, returnType); |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
244 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
245 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
246 catch (XPathExpressionException xpee) { |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
247 log.error(xpee.getLocalizedMessage(), xpee); |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
248 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
249 |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
250 return null; |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
251 } |
4083
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
252 |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
253 public static Document transform( |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
254 Document document, |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
255 File xformFile |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
256 ) { |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
257 try { |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
258 Transformer transformer = |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
259 TransformerFactory |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
260 .newInstance() |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
261 .newTransformer( |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
262 new StreamSource(xformFile)); |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
263 |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
264 DOMResult result = new DOMResult(); |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
265 |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
266 transformer.transform(new DOMSource(document), result); |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
267 |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
268 return (Document)result.getNode(); |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
269 } |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
270 catch (TransformerConfigurationException tce) { |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
271 log.error(tce, tce); |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
272 } |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
273 catch (TransformerException te) { |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
274 log.error(te, te); |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
275 } |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
276 |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
277 return null; |
44dc38ca8492
Added an optional XSL transformation to fix the raw DIPS files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4072
diff
changeset
|
278 } |
4095
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
279 |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
280 /** |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
281 * Streams out an XML document to a given output stream. |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
282 * @param document The document to be streamed out. |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
283 * @param out The output stream to be used. |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
284 * @return true if operation succeeded else false. |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
285 */ |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
286 public static boolean toStream(Document document, OutputStream out) { |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
287 try { |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
288 Transformer transformer = |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
289 TransformerFactory.newInstance().newTransformer(); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
290 DOMSource source = new DOMSource(document); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
291 StreamResult result = new StreamResult(out); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
292 transformer.transform(source, result); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
293 return true; |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
294 } |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
295 catch (TransformerConfigurationException tce) { |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
296 log.error(tce.getLocalizedMessage(), tce); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
297 } |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
298 catch (TransformerFactoryConfigurationError tfce) { |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
299 log.error(tfce.getLocalizedMessage(), tfce); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
300 } |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
301 catch (TransformerException te) { |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
302 log.error(te.getLocalizedMessage(), te); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
303 } |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
304 |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
305 return false; |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
306 } |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
307 |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
308 public static String toString(Document document) { |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
309 try { |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
310 Transformer transformer = |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
311 TransformerFactory.newInstance().newTransformer(); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
312 DOMSource source = new DOMSource(document); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
313 StringWriter out = new StringWriter(); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
314 StreamResult result = new StreamResult(out); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
315 transformer.transform(source, result); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
316 out.flush(); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
317 return out.toString(); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
318 } |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
319 catch (TransformerConfigurationException tce) { |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
320 log.error(tce.getLocalizedMessage(), tce); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
321 } |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
322 catch (TransformerFactoryConfigurationError tfce) { |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
323 log.error(tfce.getLocalizedMessage(), tfce); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
324 } |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
325 catch (TransformerException te) { |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
326 log.error(te.getLocalizedMessage(), te); |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
327 } |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
328 |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
329 return null; |
da9df3641578
Send XML messages via HTTP POST around if the FLYS database has changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4083
diff
changeset
|
330 } |
4070
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
331 } |
d09adfa90942
Added XML/XPath support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
332 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |