comparison gnv-artifacts/src/main/java/de/intevation/gnv/utils/MetaWriter.java @ 853:164d102b0af5

Fixed Bug in renaming a Layer in Product Layer. gnv-artifacts/trunk@971 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Fri, 23 Apr 2010 10:12:43 +0000
parents a645bd23c1c8
children 3fbabd4803d7
comparison
equal deleted inserted replaced
852:b5f4b6073cde 853:164d102b0af5
1 package de.intevation.gnv.utils; 1 package de.intevation.gnv.utils;
2
3 import de.intevation.artifactdatabase.XMLUtils;
4
5 import de.intevation.artifacts.ArtifactNamespaceContext;
6 import de.intevation.artifacts.CallContext;
7
8 import de.intevation.gnv.artifacts.context.GNVArtifactContext;
9
10 import de.intevation.gnv.wms.LayerInfo;
11 2
12 import java.io.File; 3 import java.io.File;
13 import java.io.FileNotFoundException; 4 import java.io.FileNotFoundException;
14 import java.io.FileOutputStream; 5 import java.io.FileOutputStream;
15 import java.io.IOException; 6 import java.io.IOException;
16 import java.io.OutputStream; 7 import java.io.OutputStream;
17
18 import java.util.Date; 8 import java.util.Date;
19 9
20 import org.apache.log4j.Logger; 10 import org.apache.log4j.Logger;
21
22 import org.w3c.dom.Document; 11 import org.w3c.dom.Document;
23 import org.w3c.dom.Element; 12 import org.w3c.dom.Element;
13
14 import de.intevation.artifactdatabase.XMLUtils;
15 import de.intevation.artifacts.ArtifactNamespaceContext;
16 import de.intevation.artifacts.CallContext;
17 import de.intevation.gnv.artifacts.context.GNVArtifactContext;
18 import de.intevation.gnv.wms.LayerInfo;
24 19
25 /** 20 /**
26 * This class provides some methods to create files storing meta information 21 * This class provides some methods to create files storing meta information
27 * about wms layers and a map service which serves these layers. 22 * about wms layers and a map service which serves these layers.
28 * 23 *
38 public static final String NODE_TTL = "ttl"; 33 public static final String NODE_TTL = "ttl";
39 34
40 public static final String META_FILE_NAME = "meta.xml"; 35 public static final String META_FILE_NAME = "meta.xml";
41 public static final String ISOLINES_NAME = "isolines.shp"; 36 public static final String ISOLINES_NAME = "isolines.shp";
42 public static final String POLYGON_NAME = "polygons.shp"; 37 public static final String POLYGON_NAME = "polygons.shp";
43 public static final String LAYER_DATA_NAME = "data.shp"; 38
44 39
45 public static final String CONTEXT_LAYER_TITLE = "wms.title"; 40 public static final String CONTEXT_LAYER_TITLE = "wms.title";
46 41
47 /** 42 /**
48 * Constructor. 43 * Constructor.
62 */ 57 */
63 public static Document writeLayerMeta(CallContext context, 58 public static Document writeLayerMeta(CallContext context,
64 String uuid, 59 String uuid,
65 String path, 60 String path,
66 String paramType, 61 String paramType,
67 String layerType){ 62 String layerType,
63 String shapefileName,
64 String title){
68 Document meta = XMLUtils.newDocument(); 65 Document meta = XMLUtils.newDocument();
69 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( 66 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
70 meta, 67 meta,
71 ArtifactNamespaceContext.NAMESPACE_URI, 68 ArtifactNamespaceContext.NAMESPACE_URI,
72 ArtifactNamespaceContext.NAMESPACE_PREFIX); 69 ArtifactNamespaceContext.NAMESPACE_PREFIX);
73 Element root = creator.create("meta"); 70 Element root = creator.create("meta");
74 meta.appendChild(root); 71 meta.appendChild(root);
75 72
76 writeAbstractMeta(context, meta, root); 73 writeAbstractMeta(context, meta, root);
77 writeLayerMeta(context, meta, root, uuid, paramType,layerType); 74 writeLayerMeta(context, meta, root, uuid, paramType,layerType,shapefileName,title);
78 boolean success = writeMetaFile(path, meta); 75 boolean success = writeMetaFile(path, meta);
79 76
80 if (success){ 77 if (success){
81 return meta; 78 return meta;
82 }else{ 79 }else{
229 CallContext callContext, 226 CallContext callContext,
230 Document document, 227 Document document,
231 Element meta, 228 Element meta,
232 String uuid, 229 String uuid,
233 String paramType, 230 String paramType,
234 String layerType 231 String layerType,
232 String shapefileName,
233 String layerTitle
235 ) { 234 ) {
236 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( 235 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
237 document, 236 document,
238 ArtifactNamespaceContext.NAMESPACE_URI, 237 ArtifactNamespaceContext.NAMESPACE_URI,
239 ArtifactNamespaceContext.NAMESPACE_PREFIX); 238 ArtifactNamespaceContext.NAMESPACE_PREFIX);
245 logger.debug("Artifacts time to live: " + ttl); 244 logger.debug("Artifacts time to live: " + ttl);
246 245
247 Element layer = creator.create(LayerInfo.LAYER); 246 Element layer = creator.create(LayerInfo.LAYER);
248 Element model = creator.create(LayerInfo.LAYER_MODEL); 247 Element model = creator.create(LayerInfo.LAYER_MODEL);
249 Element name = creator.create(LayerInfo.LAYER_NAME); 248 Element name = creator.create(LayerInfo.LAYER_NAME);
249 Element title = creator.create(LayerInfo.LAYER_TITLE);
250 Element type = creator.create(LayerInfo.LAYER_TYPE); 250 Element type = creator.create(LayerInfo.LAYER_TYPE);
251 Element status = creator.create(LayerInfo.LAYER_STATUS); 251 Element status = creator.create(LayerInfo.LAYER_STATUS);
252 Element data = creator.create(LayerInfo.LAYER_DATA); 252 Element data = creator.create(LayerInfo.LAYER_DATA);
253 Element timeToLive = creator.create(NODE_TTL); 253 Element timeToLive = creator.create(NODE_TTL);
254 254
255 model.setTextContent(paramType); 255 model.setTextContent(paramType);
256 name.setTextContent(uuid); 256 name.setTextContent(uuid);
257 type.setTextContent(layerType); 257 type.setTextContent(layerType);
258 status.setTextContent("OFF"); 258 status.setTextContent("OFF");
259 data.setTextContent(LAYER_DATA_NAME); 259 data.setTextContent(shapefileName);
260 timeToLive.setTextContent(ttl); 260 timeToLive.setTextContent(ttl);
261
262 title.setTextContent(layerTitle);
261 263
262 layer.appendChild(model); 264 layer.appendChild(model);
263 layer.appendChild(name); 265 layer.appendChild(name);
266 layer.appendChild(title);
264 layer.appendChild(type); 267 layer.appendChild(type);
265 layer.appendChild(status); 268 layer.appendChild(status);
266 layer.appendChild(data); 269 layer.appendChild(data);
267 layer.appendChild(timeToLive); 270 layer.appendChild(timeToLive);
268 271

http://dive4elements.wald.intevation.org