comparison gnv-artifacts/src/main/java/de/intevation/gnv/utils/MetaWriter.java @ 655:6eccb68a8b99

Added WMS-Publishing to Product Layer gnv-artifacts/trunk@747 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Mon, 08 Mar 2010 14:04:28 +0000
parents bb0aa1f81280
children 452fad121560
comparison
equal deleted inserted replaced
654:a6081d76fa1c 655:6eccb68a8b99
1 package de.intevation.gnv.utils; 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 2
11 import java.io.File; 3 import java.io.File;
12 import java.io.FileNotFoundException; 4 import java.io.FileNotFoundException;
13 import java.io.FileOutputStream; 5 import java.io.FileOutputStream;
14 import java.io.IOException; 6 import java.io.IOException;
15 import java.io.OutputStream; 7 import java.io.OutputStream;
16 8
17 import org.apache.log4j.Logger; 9 import org.apache.log4j.Logger;
18
19 import org.w3c.dom.Document; 10 import org.w3c.dom.Document;
20 import org.w3c.dom.Element; 11 import org.w3c.dom.Element;
12
13 import de.intevation.artifactdatabase.XMLUtils;
14 import de.intevation.artifacts.ArtifactNamespaceContext;
15 import de.intevation.artifacts.CallContext;
16 import de.intevation.gnv.artifacts.context.GNVArtifactContext;
17 import de.intevation.gnv.wms.LayerInfo;
21 18
22 /** 19 /**
23 * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) 20 * @author Ingo Weinzierl (ingo.weinzierl@intevation.de)
24 */ 21 */
25 public class MetaWriter { 22 public class MetaWriter {
31 public static final String NODE_MAP = "map"; 28 public static final String NODE_MAP = "map";
32 29
33 public static final String META_FILE_NAME = "meta.xml"; 30 public static final String META_FILE_NAME = "meta.xml";
34 public static final String ISOLINES_NAME = "isolines.shp"; 31 public static final String ISOLINES_NAME = "isolines.shp";
35 public static final String POLYGON_NAME = "polygons.shp"; 32 public static final String POLYGON_NAME = "polygons.shp";
33 public static final String LAYER_DATA_NAME = "data.shp";
36 34
37 private MetaWriter() { 35 private MetaWriter() {
36 }
37
38 public static Document writeLayerMeta(CallContext context,
39 String uuid,
40 String path,
41 String paramType,
42 String layerType){
43 Document meta = XMLUtils.newDocument();
44 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
45 meta,
46 ArtifactNamespaceContext.NAMESPACE_URI,
47 ArtifactNamespaceContext.NAMESPACE_PREFIX);
48 Element root = creator.create("meta");
49 meta.appendChild(root);
50
51 writeAbstractMeta(context, meta, root);
52 writeLayerMeta(context, meta, root, uuid, paramType,layerType);
53 boolean success = writeMetaFile(path, meta);
54
55 if (success){
56 return meta;
57 }else{
58 return null;
59 }
38 } 60 }
39 61
40 public static Document writeHorizontalcrosssectionMeta( 62 public static Document writeHorizontalcrosssectionMeta(
41 CallContext context, 63 CallContext context,
42 String uuid, 64 String uuid,
54 76
55 writeAbstractMeta(context, meta, root); 77 writeAbstractMeta(context, meta, root);
56 writePolygonMeta(context, meta, root, uuid, path, paramType); 78 writePolygonMeta(context, meta, root, uuid, path, paramType);
57 writeIsolineMeta(context, meta, root, uuid, path, paramType); 79 writeIsolineMeta(context, meta, root, uuid, path, paramType);
58 80
81 boolean success = writeMetaFile(path, meta);
82
83 if (success){
84 return meta;
85 }else{
86 return null;
87 }
88 }
89
90 /**
91 * @param path
92 * @param meta
93 */
94 private static boolean writeMetaFile(String path, Document meta) {
59 try { 95 try {
60 File metaFile = new File(path, META_FILE_NAME); 96 File metaFile = new File(path, META_FILE_NAME);
61 97
62 if (!metaFile.createNewFile() || !metaFile.canWrite()) { 98 if (!metaFile.createNewFile() || !metaFile.canWrite()) {
63 logger.error("Error while writing meta file: "+metaFile.toString()); 99 logger.error("Error while writing meta file: "+metaFile.toString());
64 return null; 100 return false;
65 } 101 }
66 102
67 OutputStream out = null; 103 OutputStream out = null;
68 boolean success = false; 104 boolean success = false;
69 try { 105 try {
79 115
80 if (!success && metaFile.exists()) { 116 if (!success && metaFile.exists()) {
81 metaFile.delete(); 117 metaFile.delete();
82 } 118 }
83 119
84 return success ? meta : null; 120 return success;
85 } 121 }
86 catch (FileNotFoundException fnfe) { 122 catch (FileNotFoundException fnfe) {
87 logger.error(fnfe); 123 logger.error(fnfe);
124 return false;
88 } 125 }
89 catch (IOException ioe) { 126 catch (IOException ioe) {
90 logger.error(ioe, ioe); 127 logger.error(ioe, ioe);
91 } 128 return false;
92 129 }
93 return meta;
94 } 130 }
95 131
96 132
97 public static void writeAbstractMeta( 133 public static void writeAbstractMeta(
98 CallContext callContext, 134 CallContext callContext,
126 mapserver.appendChild(serverPath); 162 mapserver.appendChild(serverPath);
127 mapserver.appendChild(mapPath); 163 mapserver.appendChild(mapPath);
128 meta.appendChild(mapserver); 164 meta.appendChild(mapserver);
129 } 165 }
130 166
131 167 protected static void writeLayerMeta(
132 public static void writePolygonMeta(
133 CallContext context, 168 CallContext context,
134 Document document, 169 Document document,
135 Element meta, 170 Element meta,
136 String uuid, 171 String uuid,
137 String path, 172 String paramType,
138 String paramType 173 String layerType
139 ) { 174 ) {
140 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( 175 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
141 document, 176 document,
142 ArtifactNamespaceContext.NAMESPACE_URI, 177 ArtifactNamespaceContext.NAMESPACE_URI,
143 ArtifactNamespaceContext.NAMESPACE_PREFIX); 178 ArtifactNamespaceContext.NAMESPACE_PREFIX);
149 Element status = creator.create(LayerInfo.LAYER_STATUS); 184 Element status = creator.create(LayerInfo.LAYER_STATUS);
150 Element data = creator.create(LayerInfo.LAYER_DATA); 185 Element data = creator.create(LayerInfo.LAYER_DATA);
151 186
152 model.setTextContent(paramType); 187 model.setTextContent(paramType);
153 name.setTextContent(uuid); 188 name.setTextContent(uuid);
154 type.setTextContent("POLYGON"); 189 type.setTextContent(layerType);
155 status.setTextContent("DEFAULT"); 190 status.setTextContent("OFF");
156 data.setTextContent(POLYGON_NAME); 191 data.setTextContent(LAYER_DATA_NAME);
157 192
158 layer.appendChild(model); 193 layer.appendChild(model);
159 layer.appendChild(name); 194 layer.appendChild(name);
160 layer.appendChild(type); 195 layer.appendChild(type);
161 layer.appendChild(status); 196 layer.appendChild(status);
162 layer.appendChild(data); 197 layer.appendChild(data);
163 198
164 meta.appendChild(layer); 199 meta.appendChild(layer);
165 } 200 }
166 201
167 202
168 public static void writeIsolineMeta( 203
204
205 public static void writePolygonMeta(
169 CallContext context, 206 CallContext context,
170 Document document, 207 Document document,
171 Element meta, 208 Element meta,
172 String uuid, 209 String uuid,
173 String path, 210 String path,
183 Element name = creator.create(LayerInfo.LAYER_NAME); 220 Element name = creator.create(LayerInfo.LAYER_NAME);
184 Element type = creator.create(LayerInfo.LAYER_TYPE); 221 Element type = creator.create(LayerInfo.LAYER_TYPE);
185 Element status = creator.create(LayerInfo.LAYER_STATUS); 222 Element status = creator.create(LayerInfo.LAYER_STATUS);
186 Element data = creator.create(LayerInfo.LAYER_DATA); 223 Element data = creator.create(LayerInfo.LAYER_DATA);
187 224
188 model.setTextContent(paramType+"_isolines"); 225 model.setTextContent(paramType);
189 name.setTextContent(uuid); 226 name.setTextContent(uuid);
190 type.setTextContent("LINE"); 227 type.setTextContent("POLYGON");
191 status.setTextContent("DEFAULT"); 228 status.setTextContent("OFF");
192 data.setTextContent(ISOLINES_NAME); 229 data.setTextContent(POLYGON_NAME);
193 230
194 layer.appendChild(model); 231 layer.appendChild(model);
195 layer.appendChild(name); 232 layer.appendChild(name);
196 layer.appendChild(type); 233 layer.appendChild(type);
197 layer.appendChild(status); 234 layer.appendChild(status);
198 layer.appendChild(data); 235 layer.appendChild(data);
199 236
200 meta.appendChild(layer); 237 meta.appendChild(layer);
201 } 238 }
239
240
241 public static void writeIsolineMeta(
242 CallContext context,
243 Document document,
244 Element meta,
245 String uuid,
246 String path,
247 String paramType
248 ) {
249 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
250 document,
251 ArtifactNamespaceContext.NAMESPACE_URI,
252 ArtifactNamespaceContext.NAMESPACE_PREFIX);
253
254 Element layer = creator.create(LayerInfo.LAYER);
255 Element model = creator.create(LayerInfo.LAYER_MODEL);
256 Element name = creator.create(LayerInfo.LAYER_NAME);
257 Element type = creator.create(LayerInfo.LAYER_TYPE);
258 Element status = creator.create(LayerInfo.LAYER_STATUS);
259 Element data = creator.create(LayerInfo.LAYER_DATA);
260
261 model.setTextContent(paramType+"_isolines");
262 name.setTextContent(uuid);
263 type.setTextContent("LINE");
264 status.setTextContent("OFF");
265 data.setTextContent(ISOLINES_NAME);
266
267 layer.appendChild(model);
268 layer.appendChild(name);
269 layer.appendChild(type);
270 layer.appendChild(status);
271 layer.appendChild(data);
272
273 meta.appendChild(layer);
274 }
202 } 275 }
203 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 276 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org