annotate gnv/src/main/java/de/intevation/gnv/util/XMLUtils.java @ 683:d49e8695786c

Ordered imports. Removed needless imports. Removed empty headers. gnv/trunk@855 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 29 Mar 2010 09:10:25 +0000
parents 15ac78a91d1b
children e7fda0ae8b92
rev   line source
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
1 package de.intevation.gnv.util;
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
3 import java.io.IOException;
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
4 import java.io.InputStream;
670
b89b31293772 Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 585
diff changeset
5 import java.io.OutputStream;
11
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
6 import java.io.StringBufferInputStream;
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
7 import java.io.StringWriter;
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
8
35
4405f31bbc30 CodeCleanUP
Tim Englich <tim.englich@intevation.de>
parents: 11
diff changeset
9 import javax.xml.namespace.NamespaceContext;
4405f31bbc30 CodeCleanUP
Tim Englich <tim.englich@intevation.de>
parents: 11
diff changeset
10 import javax.xml.namespace.QName;
683
d49e8695786c Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 681
diff changeset
11
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
12 import javax.xml.parsers.DocumentBuilder;
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
13 import javax.xml.parsers.DocumentBuilderFactory;
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
14 import javax.xml.parsers.ParserConfigurationException;
683
d49e8695786c Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 681
diff changeset
15
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
16 import javax.xml.transform.Transformer;
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
17 import javax.xml.transform.TransformerConfigurationException;
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
18 import javax.xml.transform.TransformerException;
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
19 import javax.xml.transform.TransformerFactory;
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
20 import javax.xml.transform.TransformerFactoryConfigurationError;
683
d49e8695786c Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 681
diff changeset
21
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
22 import javax.xml.transform.dom.DOMSource;
683
d49e8695786c Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 681
diff changeset
23
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
24 import javax.xml.transform.stream.StreamResult;
683
d49e8695786c Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 681
diff changeset
25
35
4405f31bbc30 CodeCleanUP
Tim Englich <tim.englich@intevation.de>
parents: 11
diff changeset
26 import javax.xml.xpath.XPath;
4405f31bbc30 CodeCleanUP
Tim Englich <tim.englich@intevation.de>
parents: 11
diff changeset
27 import javax.xml.xpath.XPathConstants;
4405f31bbc30 CodeCleanUP
Tim Englich <tim.englich@intevation.de>
parents: 11
diff changeset
28 import javax.xml.xpath.XPathExpressionException;
4405f31bbc30 CodeCleanUP
Tim Englich <tim.englich@intevation.de>
parents: 11
diff changeset
29 import javax.xml.xpath.XPathFactory;
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
30
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
31 import org.apache.log4j.Logger;
683
d49e8695786c Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 681
diff changeset
32
35
4405f31bbc30 CodeCleanUP
Tim Englich <tim.englich@intevation.de>
parents: 11
diff changeset
33 import org.w3c.dom.Attr;
4405f31bbc30 CodeCleanUP
Tim Englich <tim.englich@intevation.de>
parents: 11
diff changeset
34 import org.w3c.dom.Document;
4405f31bbc30 CodeCleanUP
Tim Englich <tim.englich@intevation.de>
parents: 11
diff changeset
35 import org.w3c.dom.Element;
4405f31bbc30 CodeCleanUP
Tim Englich <tim.englich@intevation.de>
parents: 11
diff changeset
36 import org.w3c.dom.Node;
4405f31bbc30 CodeCleanUP
Tim Englich <tim.englich@intevation.de>
parents: 11
diff changeset
37 import org.w3c.dom.NodeList;
683
d49e8695786c Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 681
diff changeset
38
35
4405f31bbc30 CodeCleanUP
Tim Englich <tim.englich@intevation.de>
parents: 11
diff changeset
39 import org.xml.sax.SAXException;
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
40
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
41 /**
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
42 * @author Sascha L. Teichmann
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
43 */
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
44 public class XMLUtils {
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
45 private static Logger logger = Logger.getLogger(XMLUtils.class);
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
46
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
47 public XMLUtils() {
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
48 }
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
49
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
50 public static class ElementCreator {
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
51 protected Document document;
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
52 protected String ns;
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
53 protected String prefix;
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
54
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
55 public ElementCreator(Document document, String ns, String prefix) {
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
56 this.document = document;
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
57 this.ns = ns;
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
58 this.prefix = prefix;
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
59 }
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
60
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
61 public Element create(String name) {
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
62 Element element = document.createElementNS(ns, name);
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
63 element.setPrefix(prefix);
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
64 return element;
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
65 }
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
66
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
67 public void addAttr(Element element, String name, String value) {
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
68 Attr attr = document.createAttributeNS(ns, name);
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
69 attr.setValue(value);
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
70 attr.setPrefix(prefix);
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
71 element.setAttributeNode(attr);
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
72 }
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
73 } // class ElementCreator
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
74
585
2e690cb2247c Show information about MapServer path and layer name after publishing calculated shapefiles as wms. Use MapServer settings configured in conf.xml to feed OpenLayers client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 570
diff changeset
75 public static Document newDocument() {
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
76 try {
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
77 return DocumentBuilderFactory.newInstance().newDocumentBuilder()
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
78 .newDocument();
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
79 } catch (ParserConfigurationException pce) {
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
80 logger.error(pce.getLocalizedMessage(), pce);
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
81 }
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
82 return null;
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
83 }
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
84
585
2e690cb2247c Show information about MapServer path and layer name after publishing calculated shapefiles as wms. Use MapServer settings configured in conf.xml to feed OpenLayers client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 570
diff changeset
85 public static XPath newXPath() {
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
86 return newXPath(null);
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
87 }
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
88
585
2e690cb2247c Show information about MapServer path and layer name after publishing calculated shapefiles as wms. Use MapServer settings configured in conf.xml to feed OpenLayers client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 570
diff changeset
89 public static XPath newXPath(NamespaceContext namespaceContext) {
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
90 XPathFactory factory = XPathFactory.newInstance();
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
91 XPath xpath = factory.newXPath();
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
92 if (namespaceContext != null) {
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
93 xpath.setNamespaceContext(namespaceContext);
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
94 }
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
95 return xpath;
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
96 }
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
97
585
2e690cb2247c Show information about MapServer path and layer name after publishing calculated shapefiles as wms. Use MapServer settings configured in conf.xml to feed OpenLayers client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 570
diff changeset
98 public static Object xpath(Object root, String query, QName returnTyp) {
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
99 return xpath(root, query, returnTyp, null);
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
100 }
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
101
585
2e690cb2247c Show information about MapServer path and layer name after publishing calculated shapefiles as wms. Use MapServer settings configured in conf.xml to feed OpenLayers client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 570
diff changeset
102 public static final String xpathString(Object root, String query,
38
fccf90761825 Format Code to max 80 Chars per Row better Formatter choosen
Tim Englich <tim.englich@intevation.de>
parents: 36
diff changeset
103 NamespaceContext namespaceContext) {
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
104 return (String) xpath(root, query, XPathConstants.STRING,
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
105 namespaceContext);
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
106 }
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
107
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
108 public static final Object xpath(Object root, String query,
38
fccf90761825 Format Code to max 80 Chars per Row better Formatter choosen
Tim Englich <tim.englich@intevation.de>
parents: 36
diff changeset
109 QName returnType,
fccf90761825 Format Code to max 80 Chars per Row better Formatter choosen
Tim Englich <tim.englich@intevation.de>
parents: 36
diff changeset
110 NamespaceContext namespaceContext) {
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
111 if (root == null) {
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
112 return null;
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
113 }
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
114
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
115 try {
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
116 XPath xpath = new XMLUtils().newXPath(namespaceContext);
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
117 if (xpath != null) {
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
118 return xpath.evaluate(query, root, returnType);
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
119 }
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
120 } catch (XPathExpressionException xpee) {
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
121 logger.error(xpee.getLocalizedMessage(), xpee);
35
4405f31bbc30 CodeCleanUP
Tim Englich <tim.englich@intevation.de>
parents: 11
diff changeset
122 }
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
123
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
124 return null;
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
125 }
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
126
585
2e690cb2247c Show information about MapServer path and layer name after publishing calculated shapefiles as wms. Use MapServer settings configured in conf.xml to feed OpenLayers client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 570
diff changeset
127 public static Object getXPath(Object root, String query, QName returnType) {
389
416ff31f6273 Removed local-name() method from xsl stylesheet and adjusted xpathes while reading xml documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 38
diff changeset
128 return getXPath(root,query,returnType,ArtifactNamespaceContext.INSTANCE);
416ff31f6273 Removed local-name() method from xsl stylesheet and adjusted xpathes while reading xml documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 38
diff changeset
129 }
416ff31f6273 Removed local-name() method from xsl stylesheet and adjusted xpathes while reading xml documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 38
diff changeset
130
585
2e690cb2247c Show information about MapServer path and layer name after publishing calculated shapefiles as wms. Use MapServer settings configured in conf.xml to feed OpenLayers client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 570
diff changeset
131 public static Object getXPath(
389
416ff31f6273 Removed local-name() method from xsl stylesheet and adjusted xpathes while reading xml documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 38
diff changeset
132 Object root, String query, QName returnType, NamespaceContext context
416ff31f6273 Removed local-name() method from xsl stylesheet and adjusted xpathes while reading xml documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 38
diff changeset
133 ) {
416ff31f6273 Removed local-name() method from xsl stylesheet and adjusted xpathes while reading xml documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 38
diff changeset
134 return xpath(root, query, returnType, context);
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
135 }
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
136
585
2e690cb2247c Show information about MapServer path and layer name after publishing calculated shapefiles as wms. Use MapServer settings configured in conf.xml to feed OpenLayers client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 570
diff changeset
137 public static String getStringXPath(String xpath) {
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
138 return getStringXPath(xpath, null);
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
139 }
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
140
585
2e690cb2247c Show information about MapServer path and layer name after publishing calculated shapefiles as wms. Use MapServer settings configured in conf.xml to feed OpenLayers client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 570
diff changeset
141 public static NodeList getNodeSetXPath(Object root, String query) {
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
142 return (NodeList) getXPath(root, query, XPathConstants.NODESET);
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
143 }
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
144
585
2e690cb2247c Show information about MapServer path and layer name after publishing calculated shapefiles as wms. Use MapServer settings configured in conf.xml to feed OpenLayers client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 570
diff changeset
145 public static Node getNodeXPath(Object root, String query) {
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
146 return (Node) getXPath(root, query, XPathConstants.NODE);
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
147 }
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
148
585
2e690cb2247c Show information about MapServer path and layer name after publishing calculated shapefiles as wms. Use MapServer settings configured in conf.xml to feed OpenLayers client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 570
diff changeset
149 public static String getStringXPath(Object root, String xpath) {
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
150 return getStringXPath(root, xpath, null);
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
151 }
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
152
585
2e690cb2247c Show information about MapServer path and layer name after publishing calculated shapefiles as wms. Use MapServer settings configured in conf.xml to feed OpenLayers client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 570
diff changeset
153 public static String getStringXPath(Object root, String query, String def) {
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
154 String s = (String) getXPath(root, query, XPathConstants.STRING);
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
155 return s == null || s.length() == 0 ? def : s;
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
156 }
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
157
570
cbd397712ecf Render an OpenLayers map with the layer even published after triggering shapefile and mapfile creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 389
diff changeset
158 public static Document readDocument(InputStream inputStream) {
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
159 Document returnValue = null;
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
160 try {
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
161 DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
162 .newInstance();
389
416ff31f6273 Removed local-name() method from xsl stylesheet and adjusted xpathes while reading xml documents.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 38
diff changeset
163 docBuilderFactory.setNamespaceAware(true);
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
164 DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
165 returnValue = docBuilder.parse(inputStream);
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
166 } catch (ParserConfigurationException e) {
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
167 logger.error(e, e);
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
168 } catch (SAXException e) {
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
169 logger.error(e, e);
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
170 } catch (IOException e) {
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
171 logger.error(e, e);
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
172 }
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
173 return returnValue;
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
174 }
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
175
585
2e690cb2247c Show information about MapServer path and layer name after publishing calculated shapefiles as wms. Use MapServer settings configured in conf.xml to feed OpenLayers client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 570
diff changeset
176 public static String writeNode2String(Node node) {
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
177 try {
11
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
178 DOMSource source = new DOMSource(node);
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
179 return writeDOMSource2String(source);
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
180 } catch (TransformerConfigurationException e) {
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
181 logger.error(e, e);
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
182 } catch (TransformerFactoryConfigurationError e) {
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
183 logger.error(e, e);
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
184 } catch (TransformerException e) {
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
185 logger.error(e, e);
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
186 }
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
187 return null;
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
188 }
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
189
585
2e690cb2247c Show information about MapServer path and layer name after publishing calculated shapefiles as wms. Use MapServer settings configured in conf.xml to feed OpenLayers client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 570
diff changeset
190 public static Document reInitDocument(Document document) {
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
191
585
2e690cb2247c Show information about MapServer path and layer name after publishing calculated shapefiles as wms. Use MapServer settings configured in conf.xml to feed OpenLayers client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 570
diff changeset
192 StringBufferInputStream inputStream = new StringBufferInputStream(
2e690cb2247c Show information about MapServer path and layer name after publishing calculated shapefiles as wms. Use MapServer settings configured in conf.xml to feed OpenLayers client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 570
diff changeset
193 writeDocument2String(document));
2e690cb2247c Show information about MapServer path and layer name after publishing calculated shapefiles as wms. Use MapServer settings configured in conf.xml to feed OpenLayers client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 570
diff changeset
194 return readDocument(inputStream);
11
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
195 }
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
196
585
2e690cb2247c Show information about MapServer path and layer name after publishing calculated shapefiles as wms. Use MapServer settings configured in conf.xml to feed OpenLayers client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 570
diff changeset
197 public static String writeDocument2String(Document document) {
11
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
198 try {
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
199 DOMSource source = new DOMSource(document);
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
200 return writeDOMSource2String(source);
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
201 } catch (TransformerConfigurationException e) {
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
202 logger.error(e, e);
11
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
203 } catch (TransformerFactoryConfigurationError e) {
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
204 logger.error(e, e);
11
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
205 } catch (TransformerException e) {
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
206 logger.error(e, e);
11
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
207 }
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
208 return null;
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
209 }
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
210
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
211 /**
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
212 * @param source
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
213 * @return
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
214 * @throws TransformerFactoryConfigurationError
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
215 * @throws TransformerConfigurationException
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
216 * @throws TransformerException
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
217 */
585
2e690cb2247c Show information about MapServer path and layer name after publishing calculated shapefiles as wms. Use MapServer settings configured in conf.xml to feed OpenLayers client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 570
diff changeset
218 private static String writeDOMSource2String(DOMSource source)
38
fccf90761825 Format Code to max 80 Chars per Row better Formatter choosen
Tim Englich <tim.englich@intevation.de>
parents: 36
diff changeset
219 throws TransformerFactoryConfigurationError,
fccf90761825 Format Code to max 80 Chars per Row better Formatter choosen
Tim Englich <tim.englich@intevation.de>
parents: 36
diff changeset
220 TransformerConfigurationException,
fccf90761825 Format Code to max 80 Chars per Row better Formatter choosen
Tim Englich <tim.englich@intevation.de>
parents: 36
diff changeset
221 TransformerException {
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
222 TransformerFactory transformerFactory = TransformerFactory
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
223 .newInstance();
11
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
224 Transformer transformer = transformerFactory.newTransformer();
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
225 StringWriter sw = new StringWriter();
36
ad381cc47217 Format Code to max 80 Chars per Row
Tim Englich <tim.englich@intevation.de>
parents: 35
diff changeset
226 StreamResult result = new StreamResult(sw);
11
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
227 transformer.transform(source, result);
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
228 return sw.getBuffer().toString();
3cb753564552 Integration of the required XSL-Transformation of the Describe-Response of the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents: 2
diff changeset
229 }
670
b89b31293772 Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 585
diff changeset
230
b89b31293772 Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 585
diff changeset
231 public static boolean toStream(Document document, OutputStream out) {
b89b31293772 Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 585
diff changeset
232 try {
b89b31293772 Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 585
diff changeset
233 Transformer transformer =
b89b31293772 Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 585
diff changeset
234 TransformerFactory.newInstance().newTransformer();
b89b31293772 Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 585
diff changeset
235 DOMSource source = new DOMSource(document);
b89b31293772 Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 585
diff changeset
236 StreamResult result = new StreamResult(out);
b89b31293772 Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 585
diff changeset
237 transformer.transform(source, result);
b89b31293772 Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 585
diff changeset
238 return true;
b89b31293772 Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 585
diff changeset
239 }
b89b31293772 Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 585
diff changeset
240 catch (TransformerConfigurationException tce) {
b89b31293772 Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 585
diff changeset
241 logger.error(tce.getLocalizedMessage(), tce);
b89b31293772 Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 585
diff changeset
242 }
b89b31293772 Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 585
diff changeset
243 catch (TransformerFactoryConfigurationError tfce) {
b89b31293772 Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 585
diff changeset
244 logger.error(tfce.getLocalizedMessage(), tfce);
b89b31293772 Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 585
diff changeset
245 }
b89b31293772 Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 585
diff changeset
246 catch (TransformerException te) {
b89b31293772 Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 585
diff changeset
247 logger.error(te.getLocalizedMessage(), te);
b89b31293772 Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 585
diff changeset
248 }
b89b31293772 Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 585
diff changeset
249
b89b31293772 Implemented first things to store/load projects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 585
diff changeset
250 return false;
681
15ac78a91d1b Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 670
diff changeset
251 }
2
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
252 }
5e94403971af infrastructur for Communicationg with the ArtifactDatabase added.
Tim Englich <tim.englich@intevation.de>
parents:
diff changeset
253 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org