Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/utils/ArtifactXMLUtilities.java @ 80:29a7ba731838
Databases Timeout set to Minutes
gnv-artifacts/trunk@102 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Thu, 17 Sep 2009 14:25:24 +0000 |
parents | e33c61735a4e |
children | 1b12021905b9 |
rev | line source |
---|---|
71
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
1 /** |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
2 * |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
3 */ |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
4 package de.intevation.gnv.utils; |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
5 |
79
e33c61735a4e
Implementation of the Static UI done
Tim Englich <tim.englich@intevation.de>
parents:
76
diff
changeset
|
6 import java.io.ByteArrayInputStream; |
71
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
7 import java.io.IOException; |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
8 import java.io.InputStream; |
75
9345835e2bc1
Make the Interfaces Serializable to make them usable in the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents:
71
diff
changeset
|
9 import java.io.Serializable; |
71
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
10 import java.io.StringWriter; |
79
e33c61735a4e
Implementation of the Static UI done
Tim Englich <tim.englich@intevation.de>
parents:
76
diff
changeset
|
11 import java.io.UnsupportedEncodingException; |
71
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
12 |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
13 import javax.xml.parsers.DocumentBuilder; |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
14 import javax.xml.parsers.DocumentBuilderFactory; |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
15 import javax.xml.parsers.ParserConfigurationException; |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
16 import javax.xml.transform.Transformer; |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
17 import javax.xml.transform.TransformerConfigurationException; |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
18 import javax.xml.transform.TransformerException; |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
19 import javax.xml.transform.TransformerFactory; |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
20 import javax.xml.transform.TransformerFactoryConfigurationError; |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
21 import javax.xml.transform.dom.DOMSource; |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
22 import javax.xml.transform.stream.StreamResult; |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
23 |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
24 import org.apache.log4j.Logger; |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
25 import org.w3c.dom.Document; |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
26 import org.w3c.dom.Element; |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
27 import org.xml.sax.SAXException; |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
28 |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
29 import de.intevation.artifacts.ArtifactNamespaceContext; |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
30 import de.intevation.gnv.transition.timeseries.TimeSeriesOutputTransition; |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
31 |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
32 /** |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
33 * @author Tim Englich <tim.englich@intevation.de> |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
34 * |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
35 */ |
75
9345835e2bc1
Make the Interfaces Serializable to make them usable in the Artifactdatabase
Tim Englich <tim.englich@intevation.de>
parents:
71
diff
changeset
|
36 public class ArtifactXMLUtilities implements Serializable{ |
71
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
37 /** |
79
e33c61735a4e
Implementation of the Static UI done
Tim Englich <tim.englich@intevation.de>
parents:
76
diff
changeset
|
38 * |
e33c61735a4e
Implementation of the Static UI done
Tim Englich <tim.englich@intevation.de>
parents:
76
diff
changeset
|
39 */ |
e33c61735a4e
Implementation of the Static UI done
Tim Englich <tim.englich@intevation.de>
parents:
76
diff
changeset
|
40 private static final long serialVersionUID = -6236340358303411758L; |
e33c61735a4e
Implementation of the Static UI done
Tim Englich <tim.englich@intevation.de>
parents:
76
diff
changeset
|
41 |
e33c61735a4e
Implementation of the Static UI done
Tim Englich <tim.englich@intevation.de>
parents:
76
diff
changeset
|
42 /** |
71
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
43 * the logger, used to log exceptions and additonaly information |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
44 */ |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
45 private static Logger log = Logger.getLogger(TimeSeriesOutputTransition.class); |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
46 |
76
2473440671ce
Integrate UI-Representation for Describe into the FISArtifact.
Tim Englich <tim.englich@intevation.de>
parents:
75
diff
changeset
|
47 public static final String XFORM_URL = "http://www.w3.org/2002/xforms"; |
2473440671ce
Integrate UI-Representation for Describe into the FISArtifact.
Tim Englich <tim.englich@intevation.de>
parents:
75
diff
changeset
|
48 public static final String XFORM_PREFIX = "xform"; |
2473440671ce
Integrate UI-Representation for Describe into the FISArtifact.
Tim Englich <tim.englich@intevation.de>
parents:
75
diff
changeset
|
49 |
71
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
50 /** |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
51 * Constructor |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
52 */ |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
53 public ArtifactXMLUtilities() { |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
54 } |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
55 |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
56 /** |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
57 * @param document |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
58 * @return |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
59 */ |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
60 public Element createArtifactElement(Document document, String name) { |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
61 Element node = document.createElementNS(ArtifactNamespaceContext.NAMESPACE_URI, name); |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
62 node.setPrefix(ArtifactNamespaceContext.NAMESPACE_PREFIX); |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
63 return node; |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
64 } |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
65 |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
66 public String writeDocument2String(Document document){ |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
67 try { |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
68 TransformerFactory transformerFactory = TransformerFactory.newInstance(); |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
69 Transformer transformer = transformerFactory.newTransformer(); |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
70 DOMSource source = new DOMSource(document); |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
71 StringWriter sw = new StringWriter(); |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
72 StreamResult result = new StreamResult(sw); |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
73 transformer.transform(source, result); |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
74 return sw.getBuffer().toString(); |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
75 } catch (TransformerConfigurationException e) { |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
76 log.error(e,e); |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
77 } catch (TransformerFactoryConfigurationError e) { |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
78 log.error(e,e); |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
79 } catch (TransformerException e) { |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
80 log.error(e,e); |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
81 } |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
82 return null; |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
83 } |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
84 |
79
e33c61735a4e
Implementation of the Static UI done
Tim Englich <tim.englich@intevation.de>
parents:
76
diff
changeset
|
85 |
e33c61735a4e
Implementation of the Static UI done
Tim Englich <tim.englich@intevation.de>
parents:
76
diff
changeset
|
86 |
e33c61735a4e
Implementation of the Static UI done
Tim Englich <tim.englich@intevation.de>
parents:
76
diff
changeset
|
87 |
71
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
88 public Document readDocument(InputStream inputStream){ |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
89 Document returnValue = null; |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
90 try { |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
91 DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
92 DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
93 returnValue = docBuilder.parse (inputStream); |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
94 } catch (ParserConfigurationException e) { |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
95 log.error(e,e); |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
96 } catch (SAXException e) { |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
97 log.error(e,e); |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
98 } catch (IOException e) { |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
99 log.error(e,e); |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
100 } |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
101 return returnValue; |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
102 } |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
103 |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
104 public Document reInitDocument(Document document){ |
79
e33c61735a4e
Implementation of the Static UI done
Tim Englich <tim.englich@intevation.de>
parents:
76
diff
changeset
|
105 try { |
e33c61735a4e
Implementation of the Static UI done
Tim Englich <tim.englich@intevation.de>
parents:
76
diff
changeset
|
106 byte[] barray = this.writeDocument2String(document).getBytes("UTF-8"); |
e33c61735a4e
Implementation of the Static UI done
Tim Englich <tim.englich@intevation.de>
parents:
76
diff
changeset
|
107 InputStream inputStream = new ByteArrayInputStream(barray); |
e33c61735a4e
Implementation of the Static UI done
Tim Englich <tim.englich@intevation.de>
parents:
76
diff
changeset
|
108 //StringBufferInputStream inputStream = new StringBufferInputStream(); |
e33c61735a4e
Implementation of the Static UI done
Tim Englich <tim.englich@intevation.de>
parents:
76
diff
changeset
|
109 return this.readDocument(inputStream); |
e33c61735a4e
Implementation of the Static UI done
Tim Englich <tim.englich@intevation.de>
parents:
76
diff
changeset
|
110 } catch (UnsupportedEncodingException e) { |
e33c61735a4e
Implementation of the Static UI done
Tim Englich <tim.englich@intevation.de>
parents:
76
diff
changeset
|
111 log.error(e,e); |
e33c61735a4e
Implementation of the Static UI done
Tim Englich <tim.englich@intevation.de>
parents:
76
diff
changeset
|
112 } |
e33c61735a4e
Implementation of the Static UI done
Tim Englich <tim.englich@intevation.de>
parents:
76
diff
changeset
|
113 return document; |
71
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
114 } |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
115 |
76
2473440671ce
Integrate UI-Representation for Describe into the FISArtifact.
Tim Englich <tim.englich@intevation.de>
parents:
75
diff
changeset
|
116 public Element createXFormElement(Document document, String name) { |
2473440671ce
Integrate UI-Representation for Describe into the FISArtifact.
Tim Englich <tim.englich@intevation.de>
parents:
75
diff
changeset
|
117 Element node = document.createElementNS(XFORM_URL, name); |
2473440671ce
Integrate UI-Representation for Describe into the FISArtifact.
Tim Englich <tim.englich@intevation.de>
parents:
75
diff
changeset
|
118 node.setPrefix(XFORM_PREFIX); |
2473440671ce
Integrate UI-Representation for Describe into the FISArtifact.
Tim Englich <tim.englich@intevation.de>
parents:
75
diff
changeset
|
119 return node; |
2473440671ce
Integrate UI-Representation for Describe into the FISArtifact.
Tim Englich <tim.englich@intevation.de>
parents:
75
diff
changeset
|
120 } |
71
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
121 |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
122 |
e4ecf3188bdf
Integrated FIS-Artifact
Tim Englich <tim.englich@intevation.de>
parents:
diff
changeset
|
123 } |