Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/utils/MetaWriter.java @ 647:bb0aa1f81280
Added missing class MetaWriter from last commit.
gnv-artifacts/trunk@734 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 05 Mar 2010 07:18:52 +0000 |
parents | |
children | 6eccb68a8b99 |
comparison
equal
deleted
inserted
replaced
646:c8749d83d9b6 | 647:bb0aa1f81280 |
---|---|
1 package de.intevation.gnv.utils; | |
2 | |
3 import de.intevation.artifacts.ArtifactNamespaceContext; | |
4 import de.intevation.artifacts.CallContext; | |
5 | |
6 import de.intevation.artifactdatabase.XMLUtils; | |
7 | |
8 import de.intevation.gnv.artifacts.context.GNVArtifactContext; | |
9 import de.intevation.gnv.wms.LayerInfo; | |
10 | |
11 import java.io.File; | |
12 import java.io.FileNotFoundException; | |
13 import java.io.FileOutputStream; | |
14 import java.io.IOException; | |
15 import java.io.OutputStream; | |
16 | |
17 import org.apache.log4j.Logger; | |
18 | |
19 import org.w3c.dom.Document; | |
20 import org.w3c.dom.Element; | |
21 | |
22 /** | |
23 * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) | |
24 */ | |
25 public class MetaWriter { | |
26 | |
27 private static Logger logger = Logger.getLogger(MetaWriter.class); | |
28 | |
29 public static final String NODE_MAPSERVER = "mapserver"; | |
30 public static final String NODE_SERVER = "server"; | |
31 public static final String NODE_MAP = "map"; | |
32 | |
33 public static final String META_FILE_NAME = "meta.xml"; | |
34 public static final String ISOLINES_NAME = "isolines.shp"; | |
35 public static final String POLYGON_NAME = "polygons.shp"; | |
36 | |
37 private MetaWriter() { | |
38 } | |
39 | |
40 public static Document writeHorizontalcrosssectionMeta( | |
41 CallContext context, | |
42 String uuid, | |
43 String path, | |
44 String paramType) | |
45 { | |
46 Document meta = XMLUtils.newDocument(); | |
47 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( | |
48 meta, | |
49 ArtifactNamespaceContext.NAMESPACE_URI, | |
50 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
51 | |
52 Element root = creator.create("meta"); | |
53 meta.appendChild(root); | |
54 | |
55 writeAbstractMeta(context, meta, root); | |
56 writePolygonMeta(context, meta, root, uuid, path, paramType); | |
57 writeIsolineMeta(context, meta, root, uuid, path, paramType); | |
58 | |
59 try { | |
60 File metaFile = new File(path, META_FILE_NAME); | |
61 | |
62 if (!metaFile.createNewFile() || !metaFile.canWrite()) { | |
63 logger.error("Error while writing meta file: "+metaFile.toString()); | |
64 return null; | |
65 } | |
66 | |
67 OutputStream out = null; | |
68 boolean success = false; | |
69 try { | |
70 out = new FileOutputStream(metaFile); | |
71 success = XMLUtils.toStream(meta, out); | |
72 } | |
73 finally { | |
74 if (out != null) { | |
75 try { out.close(); } | |
76 catch (IOException ioe) {} | |
77 } | |
78 } | |
79 | |
80 if (!success && metaFile.exists()) { | |
81 metaFile.delete(); | |
82 } | |
83 | |
84 return success ? meta : null; | |
85 } | |
86 catch (FileNotFoundException fnfe) { | |
87 logger.error(fnfe); | |
88 } | |
89 catch (IOException ioe) { | |
90 logger.error(ioe, ioe); | |
91 } | |
92 | |
93 return meta; | |
94 } | |
95 | |
96 | |
97 public static void writeAbstractMeta( | |
98 CallContext callContext, | |
99 Document document, | |
100 Element meta | |
101 ) { | |
102 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( | |
103 document, | |
104 ArtifactNamespaceContext.NAMESPACE_URI, | |
105 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
106 | |
107 GNVArtifactContext context = | |
108 (GNVArtifactContext) callContext.globalContext(); | |
109 | |
110 String server = (String) | |
111 context.get(GNVArtifactContext.MAPSERVER_SERVER_PATH_KEY); | |
112 | |
113 String map = (String) | |
114 context.get(GNVArtifactContext.MAPSERVER_MAP_PATH_KEY); | |
115 | |
116 logger.debug("MAPSERVER PATH: " + server); | |
117 logger.debug("MAP PATH: " + map); | |
118 | |
119 Element mapserver = creator.create(NODE_MAPSERVER); | |
120 Element serverPath = creator.create(NODE_SERVER); | |
121 Element mapPath = creator.create(NODE_MAP); | |
122 | |
123 mapPath.setTextContent(map); | |
124 serverPath.setTextContent(server); | |
125 | |
126 mapserver.appendChild(serverPath); | |
127 mapserver.appendChild(mapPath); | |
128 meta.appendChild(mapserver); | |
129 } | |
130 | |
131 | |
132 public static void writePolygonMeta( | |
133 CallContext context, | |
134 Document document, | |
135 Element meta, | |
136 String uuid, | |
137 String path, | |
138 String paramType | |
139 ) { | |
140 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( | |
141 document, | |
142 ArtifactNamespaceContext.NAMESPACE_URI, | |
143 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
144 | |
145 Element layer = creator.create(LayerInfo.LAYER); | |
146 Element model = creator.create(LayerInfo.LAYER_MODEL); | |
147 Element name = creator.create(LayerInfo.LAYER_NAME); | |
148 Element type = creator.create(LayerInfo.LAYER_TYPE); | |
149 Element status = creator.create(LayerInfo.LAYER_STATUS); | |
150 Element data = creator.create(LayerInfo.LAYER_DATA); | |
151 | |
152 model.setTextContent(paramType); | |
153 name.setTextContent(uuid); | |
154 type.setTextContent("POLYGON"); | |
155 status.setTextContent("DEFAULT"); | |
156 data.setTextContent(POLYGON_NAME); | |
157 | |
158 layer.appendChild(model); | |
159 layer.appendChild(name); | |
160 layer.appendChild(type); | |
161 layer.appendChild(status); | |
162 layer.appendChild(data); | |
163 | |
164 meta.appendChild(layer); | |
165 } | |
166 | |
167 | |
168 public static void writeIsolineMeta( | |
169 CallContext context, | |
170 Document document, | |
171 Element meta, | |
172 String uuid, | |
173 String path, | |
174 String paramType | |
175 ) { | |
176 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( | |
177 document, | |
178 ArtifactNamespaceContext.NAMESPACE_URI, | |
179 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
180 | |
181 Element layer = creator.create(LayerInfo.LAYER); | |
182 Element model = creator.create(LayerInfo.LAYER_MODEL); | |
183 Element name = creator.create(LayerInfo.LAYER_NAME); | |
184 Element type = creator.create(LayerInfo.LAYER_TYPE); | |
185 Element status = creator.create(LayerInfo.LAYER_STATUS); | |
186 Element data = creator.create(LayerInfo.LAYER_DATA); | |
187 | |
188 model.setTextContent(paramType+"_isolines"); | |
189 name.setTextContent(uuid); | |
190 type.setTextContent("LINE"); | |
191 status.setTextContent("DEFAULT"); | |
192 data.setTextContent(ISOLINES_NAME); | |
193 | |
194 layer.appendChild(model); | |
195 layer.appendChild(name); | |
196 layer.appendChild(type); | |
197 layer.appendChild(status); | |
198 layer.appendChild(data); | |
199 | |
200 meta.appendChild(layer); | |
201 } | |
202 } | |
203 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |