changeset 1057:04967dc9c83f

The title of a layer can be changed by the user. Product 'Layer' and 'Horizontalschnitt' now use the same code path to write the meta information file. (issue198) gnv-artifacts/trunk@1134 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 27 May 2010 16:43:00 +0000
parents 0318fda0001e
children 2b4f1c095468
files gnv-artifacts/ChangeLog gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_flow-velocity.vm gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_flow-velocity_isolines.vm gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_salinity.vm gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_salinity_isolines.vm gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_water-levels.vm gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_water-levels_isolines.vm gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_water-temperature.vm gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_water-temperature_isolines.vm gnv-artifacts/doc/conf/maptemplates/layer_linestring.vm gnv-artifacts/doc/conf/maptemplates/layer_point.vm gnv-artifacts/doc/conf/maptemplates/layer_polygon.vm gnv-artifacts/doc/conf/queries.properties gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerMetaData.java gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/utils/MetaWriter.java
diffstat 17 files changed, 375 insertions(+), 318 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Thu May 27 08:48:16 2010 +0000
+++ b/gnv-artifacts/ChangeLog	Thu May 27 16:43:00 2010 +0000
@@ -1,3 +1,44 @@
+2010-05-27  Ingo Weinzierl <ingo.weinzierl@intevation.de>
+
+	  Issue198
+
+	* src/main/java/de/intevation/gnv/utils/MetaWriter.java: Product 'Layer' and 
+	  'Horizontalschnitt' use the same code to write meta files. To create a
+	  meta file, it is now necessary to use four methods:
+	  - initMeta(): creates a new xml document and inserts the root node 'meta'
+	  - insertAbstractMeta(.): adds meta information into the meta file
+	  - insertLayer(.): adds layer specific information into the meta file
+	  - writeMetaFile(.): writes the meta information file to disk.
+
+	* src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java,
+	  src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java: Make
+	  use of the new methods of MetaWriter. Both classes use the same methods
+	  now!
+
+	* doc/conf/queries.properties: Fetch the layername from database while
+	  requesting wms data.
+
+	* src/main/java/de/intevation/gnv/state/layer/LayerMetaData.java: Added the
+	  title of a layer. The title is used while creating the meta information
+	  file for wms layers.
+
+	* doc/conf/maptemplates/horizontalcrosssection_salinity.vm,
+	  doc/conf/maptemplates/horizontalcrosssection_salinity_isolines.vm,
+	  doc/conf/maptemplates/layer_linestring.vm,
+	  doc/conf/maptemplates/horizontalcrosssection_flow-velocity.vm,
+	  doc/conf/maptemplates/horizontalcrosssection_flow-velocity_isolines.vm,
+	  doc/conf/maptemplates/horizontalcrosssection_water-levels.vm,
+	  doc/conf/maptemplates/layer_polygon.vm,
+	  doc/conf/maptemplates/horizontalcrosssection_water-temperature.vm,
+	  doc/conf/maptemplates/layer_point.vm,
+	  doc/conf/maptemplates/horizontalcrosssection_water-levels_isolines.vm,
+	  doc/conf/maptemplates/horizontalcrosssection_water-temperature_isolines.vm:
+	  Adjusted the templates regarding the changes in meta file. Each parameter
+	  that is necessary in these templates is contained in the LayerInfo object.
+	  So there is no need to concatenate parameters as it was the case before
+	  these changes. Furthermore, there is a new section that contains the title
+	  of a layer - the title is adjustable by the user.
+
 2010-05-27  Ingo Weinzierl <ingo.weinzierl@intevation.de>
 
 	* src/main/java/de/intevation/gnv/exports/ChartExportHelper.java: Fixed a
--- a/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_flow-velocity.vm	Thu May 27 08:48:16 2010 +0000
+++ b/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_flow-velocity.vm	Thu May 27 16:43:00 2010 +0000
@@ -1,8 +1,12 @@
 LAYER
-    NAME "$info.getTitle()"
-    GROUP "$info.getTitle()"
+    NAME "$info.getName()"
     TYPE $info.getType()
-    DATA "${info.getName()}/${info.getData()}"
+    DATA "${info.getData()}"
     STATUS $info.getStatus()
+
+    METADATA
+        "wms_title" "$info.getTitle()"
+    END
+
     #include("flow-velocity_polygons.class.vm")
 END
--- a/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_flow-velocity_isolines.vm	Thu May 27 08:48:16 2010 +0000
+++ b/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_flow-velocity_isolines.vm	Thu May 27 16:43:00 2010 +0000
@@ -1,9 +1,13 @@
 LAYER
-    NAME "$info.getTitle()_isolines"
-    GROUP "$info.getTitle()"
-    DATA "${info.getName()}/${info.getData()}"
+    NAME "$info.getName()"
+    DATA "$info.getData()"
     TYPE $info.getType()
     STATUS $info.getStatus()
     LABELITEM DESC
+
+    METADATA
+        "wms_title" "$info.getTitle()"
+    END
+
     #include("flow-velocity_isolines.class.vm")
 END
--- a/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_salinity.vm	Thu May 27 08:48:16 2010 +0000
+++ b/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_salinity.vm	Thu May 27 16:43:00 2010 +0000
@@ -1,8 +1,12 @@
 LAYER
-    NAME "$info.getTitle()"
-    GROUP "$info.getTitle()"
+    NAME "$info.getName()"
     TYPE $info.getType()
-    DATA "${info.getName()}/${info.getData()}"
+    DATA "$info.getData()"
     STATUS $info.getStatus()
+
+    METADATA
+        "wms_title" "$info.getTitle()"
+    END
+
     #include("salinity_polygons.class.vm")
 END
--- a/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_salinity_isolines.vm	Thu May 27 08:48:16 2010 +0000
+++ b/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_salinity_isolines.vm	Thu May 27 16:43:00 2010 +0000
@@ -1,9 +1,13 @@
 LAYER
-    NAME "$info.getTitle()_isolines"
-    GROUP "$info.getTitle()"
-    DATA "${info.getName()}/${info.getData()}"
+    NAME "$info.getName()"
+    DATA "$info.getData()"
     TYPE $info.getType()
     STATUS $info.getStatus()
     LABELITEM DESC
+
+    METADATA
+        "wms_title" "$info.getTitle()"
+    END
+
     #include("salinity_isolines.class.vm")
 END
--- a/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_water-levels.vm	Thu May 27 08:48:16 2010 +0000
+++ b/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_water-levels.vm	Thu May 27 16:43:00 2010 +0000
@@ -1,8 +1,12 @@
 LAYER
-    NAME "$info.getTitle()"
-    GROUP "$info.getTitle()"
+    NAME "$info.getName()"
     TYPE $info.getType()
-    DATA "${info.getName()}/${info.getData()}"
+    DATA "$info.getData()"
     STATUS $info.getStatus()
+
+    METADATA
+        "wms_title" "$info.getTitle()"
+    END
+
     #include("water-levels_polygons.class.vm")
 END
--- a/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_water-levels_isolines.vm	Thu May 27 08:48:16 2010 +0000
+++ b/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_water-levels_isolines.vm	Thu May 27 16:43:00 2010 +0000
@@ -1,9 +1,13 @@
 LAYER
-    NAME "$info.getTitle()_isolines"
-    GROUP "$info.getTitle()"
-    DATA "${info.getName()}/${info.getData()}"
+    NAME "$info.getName()"
+    DATA "$info.getData()"
     TYPE $info.getType()
     STATUS $info.getStatus()
     LABELITEM DESC
+
+    METADATA
+        "wms_title" "$info.getTitle()"
+    END
+
     #include("water-levels_isolines.class.vm")
 END
--- a/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_water-temperature.vm	Thu May 27 08:48:16 2010 +0000
+++ b/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_water-temperature.vm	Thu May 27 16:43:00 2010 +0000
@@ -1,8 +1,12 @@
 LAYER
-    NAME "$info.getTitle()"
-    GROUP "$info.getTitle()"
+    NAME "$info.getName()"
     TYPE $info.getType()
-    DATA "${info.getName()}/${info.getData()}"
+    DATA "$info.getData()"
     STATUS $info.getStatus()
+
+    METADATA
+        "wms_title" "$info.getTitle()"
+    END
+
     #include("water-temperature_polygons.class.vm")
 END
--- a/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_water-temperature_isolines.vm	Thu May 27 08:48:16 2010 +0000
+++ b/gnv-artifacts/doc/conf/maptemplates/horizontalcrosssection_water-temperature_isolines.vm	Thu May 27 16:43:00 2010 +0000
@@ -1,9 +1,13 @@
 LAYER
-    NAME "$info.getTitle()_isolines"
-    GROUP "$info.getTitle()"
-    DATA "${info.getName()}/${info.getData()}"
+    NAME "$info.getName()"
+    DATA "$info.getData()"
     TYPE $info.getType()
     STATUS $info.getStatus()
     LABELITEM DESC
+
+    METADATA
+        "wms_title" "$info.getTitle()"
+    END
+
     #include("water-temperature_isolines.class.vm")
 END
--- a/gnv-artifacts/doc/conf/maptemplates/layer_linestring.vm	Thu May 27 08:48:16 2010 +0000
+++ b/gnv-artifacts/doc/conf/maptemplates/layer_linestring.vm	Thu May 27 16:43:00 2010 +0000
@@ -1,9 +1,13 @@
 LAYER
-    NAME "$info.getTitle()"
+    NAME "$info.getName()"
     TYPE $info.getType()
-    DATA "${info.getName()}/${info.getData()}"
+    DATA "$info.getData()"
     STATUS $info.getStatus()
-    
+
+    METADATA
+        "wms_title" "$info.getTitle()"
+    END
+
     CLASS
         NAME "Layer"
         STYLE
--- a/gnv-artifacts/doc/conf/maptemplates/layer_point.vm	Thu May 27 08:48:16 2010 +0000
+++ b/gnv-artifacts/doc/conf/maptemplates/layer_point.vm	Thu May 27 16:43:00 2010 +0000
@@ -1,9 +1,13 @@
 LAYER
-    NAME "$info.getTitle()"
+    NAME "$info.getName()"
     TYPE $info.getType()
-    DATA "${info.getName()}/${info.getData()}"
+    DATA "$info.getData()"
     STATUS $info.getStatus()
 
+    METADATA
+        "wms_title" "$info.getTitle()"
+    END
+
     CLASS
         NAME "Layer"
         STYLE
--- a/gnv-artifacts/doc/conf/maptemplates/layer_polygon.vm	Thu May 27 08:48:16 2010 +0000
+++ b/gnv-artifacts/doc/conf/maptemplates/layer_polygon.vm	Thu May 27 16:43:00 2010 +0000
@@ -1,9 +1,13 @@
 LAYER
-    NAME "$info.getTitle()"
+    NAME "$info.getName()"
     TYPE $info.getType()
-    DATA "${info.getName()}/${info.getData()}"
+    DATA "$info.getData()"
     STATUS $info.getStatus()
 
+    METADATA
+        "wms_title" "$info.getTitle()"
+    END
+
     CLASS
         NAME "Layer"
         STYLE
--- a/gnv-artifacts/doc/conf/queries.properties	Thu May 27 08:48:16 2010 +0000
+++ b/gnv-artifacts/doc/conf/queries.properties	Thu May 27 16:43:00 2010 +0000
@@ -1830,7 +1830,8 @@
     
 layer_request_data = SELECT ID_FEATURECLASS, \
         QUERY_STRING, \
-        ID_MAPSERVICE || '_' ||ID_LAYER \
+        ID_MAPSERVICE || '_' ||ID_LAYER, \
+        TITLE || '-' || LAYER_NAME || '-' || BAND VALUE \
     FROM MEDIAN.LAYER_HAS_SUBTYPES \
     WHERE ROW_ID IN (?)
 
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerMetaData.java	Thu May 27 08:48:16 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerMetaData.java	Thu May 27 16:43:00 2010 +0000
@@ -17,6 +17,7 @@
     private String templateID = null;
     private String[] queryValues = null;
     private String geometryWKT = null;
+    private String layertitle = null;
 
     /**
      * Constructor
@@ -32,15 +33,17 @@
      */
     public LayerMetaData(String table, String geometryType, String where,
                          String columns, String templateID,
-                         String[] queryValues,String geometryWKT) {
+                         String[] queryValues,String geometryWKT,
+                         String layertitle) {
         super();
-        this.table = table;
+        this.table        = table;
         this.geometryType = geometryType;
-        this.where = where;
-        this.columns = columns;
-        this.templateID = templateID;
-        this.queryValues = queryValues;
-        this.geometryWKT = geometryWKT;
+        this.where        = where;
+        this.columns      = columns;
+        this.templateID   = templateID;
+        this.queryValues  = queryValues;
+        this.geometryWKT  = geometryWKT;
+        this.layertitle    = layertitle;
     }
 
     /**
@@ -103,4 +106,12 @@
         return queryValues;
     }
 
+    /**
+     * Returns the layer title.
+     * @return the layer title.
+     */
+    public String getLayertitle() {
+        return layertitle;
+    }
+
 }
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java	Thu May 27 08:48:16 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java	Thu May 27 16:43:00 2010 +0000
@@ -170,6 +170,7 @@
                 String where = resultValue.getString(1);
                 String columns = this.fetchColumns(table);
                 String templateID = resultValue.getString(2);
+                String layername = resultValue.getString(3);
                 String[] queryValues = null;
                 String geometryWKT = null;
                 if (this.geometryID != null){
@@ -221,10 +222,9 @@
                         queryValues = new String[]{columns,table,where};
                     }
                 }
-                returnValue.add(new LayerMetaData(table, geometryType,
-                                  where, columns,
-                                  templateID, queryValues,
-                                  geometryWKT));
+                returnValue.add(new LayerMetaData(
+                    table, geometryType, where, columns,
+                    templateID, queryValues, geometryWKT, layername));
             }
         }
         return returnValue;
@@ -618,42 +618,54 @@
 
             // process data
             Iterator<LayerMetaData> it = layerMetaData.iterator();
-            Node meta = null;
+            
+            // create meta file
+            Document meta   = MetaWriter.initMeta();
+            MetaWriter.insertAbstractMeta(callContext, meta);            
+
+            String   path   = getShapeFilePath();
+            String   prefix = getLayerPrefix(inputData);
+
+            if (prefix == null) {
+                prefix = uuid;
+            }
+
             int layerNumber = 0;
             while (it.hasNext()){
                 LayerMetaData lmd = it.next();
                 layerNumber ++;
+
                 String geometryType = lmd.getGeometryType();
-                String templateId = lmd.getTemplateID();
+                String templateId   = lmd.getTemplateID();
+
                 ExclusiveExec.UniqueKey key = ExclusiveExec.INSTANCE.acquire(uuid);
                 try{
-                    Collection<Result> data = this.fetchData(lmd);
-                    if (data != null &&
-                        (this.writeToShapeFile(uuid, data, callContext,
-                                                 geometryType,layerNumber)) != null) {
-                        String paramType = findParameterTitle(geometryType,templateId);
-                        String    title      = getLayerTitle(inputData);
-                        if (title == null) {
-                            title = uuid+"_"+layerNumber;
-                        }else{
-                            title = title+"_"+layerNumber;
-                        }
-                        if (meta == null){
-                            meta = MetaWriter.writeLayerMeta(callContext,document);
-                        }
-                        MetaWriter.writeLayerMeta(callContext, document,
-                                                  meta, uuid, paramType,
-                                                  this.determineGeometryType(geometryType),
-                                                  createShapeFileName(layerNumber),
-                                                  title);
+                    Collection<Result> results = this.fetchData(lmd);
+                    if (results != null && writeToShapeFile(uuid, results,
+                                                         callContext,
+                                                         geometryType,
+                                                         layerNumber) != null) {
+                        String name   = getLayerName(uuid, layerNumber);
+                        String base   = lmd.getLayertitle();
+                        String title  = getLayerTitle(prefix, base);
+                        String data   = getLayerData(
+                            uuid, createShapeFileName(layerNumber));
+                        String type   = determineGeometryType(geometryType);
+                        String status = "OFF";
+                        String model  = findParameterTitle(
+                            geometryType, templateId);
+
+                        MetaWriter.insertLayer(
+                            callContext, meta, name, title,
+                            data, model, type, status);
                     }
 
                     success = true;
 
                     if (meta != null && !it.hasNext()) {
-                        MetaWriter.writeMetaFile(getShapeFilePath(),document);
+                        MetaWriter.writeMetaFile(path, meta);
                         MapfileGenerator.getInstance().update();
-                        return document;
+                        return meta;
                     }
                 }finally{
                     ExclusiveExec.INSTANCE.release(key);
@@ -678,6 +690,23 @@
     }
 
 
+    protected String getLayerName(String uuid, int idx) {
+        return uuid + "_" + idx;
+    }
+
+
+    protected String getLayerTitle(String prefix, String base) {
+        return prefix + "_" + base;
+    }
+
+
+    protected String getLayerData(String shapeDir, String filename) {
+        File path = new File(shapeDir, filename);
+
+        return path.toString();
+    }
+
+
     /**
      * Returns the parameterType for the Layer.
      * @param geometryType
@@ -699,7 +728,7 @@
      * @param inputData A collection with InputData objects.
      * @return the title.
      */
-    protected String getLayerTitle(Collection<InputData> inputData) {
+    protected String getLayerPrefix(Collection<InputData> inputData) {
         for (InputData data: inputData) {
             String name = data.getName();
             if (name != null && name.equals("title")) {
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java	Thu May 27 08:48:16 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java	Thu May 27 16:43:00 2010 +0000
@@ -306,24 +306,35 @@
         String path  = getShapeFilePath();
 
         if (path != null && new File(path).isDirectory()) {
-            String title = getLayerTitle(inputData);
-            if (title == null) {
-                title = uuid;
+            Document meta = MetaWriter.initMeta();
+            MetaWriter.insertAbstractMeta(callContext, meta);
+
+            String prefix = getLayerPrefix(inputData);
+            if (prefix == null) {
+                prefix = uuid;
             }
 
-            callContext.putContextValue(
-                MetaWriter.CONTEXT_LAYER_TITLE, title);
-
-            String paramType = findParameterType(callContext);
+            // append polygon meta
+            String model  = findParameterType(callContext);
+            String type   = "POLYGON";
+            String name   = getLayerName(uuid, type);
+            String title  = getLayerTitle(prefix, type);
+            String data   = getLayerData(uuid, POLYGON_NAME);
+            String status = "OFF";
+            MetaWriter.insertLayer(
+                callContext, meta, name, title, data, model, type, status);
 
-            if (log.isDebugEnabled()) {
-                log.debug("Layer title: " + title);
-                log.debug("Layer type: " + paramType);
-            }
+            // append isoline meta
+            model += "_isolines";
+            type  = "LINE";
+            name  = getLayerName(uuid, type);
+            title = getLayerTitle(prefix, type);
+            data  = getLayerData(uuid, ISOLINES_NAME);
+            MetaWriter.insertLayer(
+                callContext, meta, name, title, data, model, type, status);
 
-            Document meta = MetaWriter.writeHorizontalcrosssectionMeta(
-                callContext, uuid, path, paramType);
             if (meta != null) {
+                MetaWriter.writeMetaFile(path, meta);
                 MapfileGenerator.getInstance().update();
                 return meta;
             }
@@ -336,25 +347,35 @@
             try{
             if (result != null
             && (path = writeToShapeFile(uuid, result, callContext)) != null) {
-
-                String paramType = findParameterType(callContext);
+                Document meta = MetaWriter.initMeta();
+                MetaWriter.insertAbstractMeta(callContext, meta);
 
-                String    title      = getLayerTitle(inputData);
-                if (title == null) {
-                    title = uuid;
-                }
-                callContext.putContextValue(
-                    MetaWriter.CONTEXT_LAYER_TITLE, title);
-
-                if (log.isDebugEnabled()) {
-                    log.debug("Parameter type: " + paramType);
-                    log.debug("Layer title: " + title);
+                String prefix = getLayerPrefix(inputData);
+                if (prefix == null) {
+                    prefix = uuid;
                 }
 
-                Document meta = MetaWriter.writeHorizontalcrosssectionMeta(
-                    callContext, uuid, path, paramType);
+                // append polygon meta
+                String model  = findParameterType(callContext);
+                String type   = "POLYGON";
+                String name   = getLayerName(uuid, type);
+                String title  = getLayerTitle(prefix, type);
+                String data   = getLayerData(uuid, POLYGON_NAME);
+                String status = "OFF";
+                MetaWriter.insertLayer(
+                    callContext, meta, name, title, data, model, type, status);
+
+                // append isoline meta
+                model += "_isolines";
+                type   = "LINE";
+                name   = getLayerName(uuid, type);
+                title  = getLayerTitle(prefix, type);
+                data   = getLayerData(uuid, ISOLINES_NAME);
+                MetaWriter.insertLayer(
+                    callContext, meta, name, title, data, model, type, status);
 
                 if (meta != null) {
+                    MetaWriter.writeMetaFile(path, meta);
                     MapfileGenerator.getInstance().update();
                     return meta;
                 }
@@ -400,7 +421,7 @@
      * @param inputData A collection with InputData objects.
      * @return the title.
      */
-    protected String getLayerTitle(Collection<InputData> inputData) {
+    protected String getLayerPrefix(Collection<InputData> inputData) {
         for (InputData data: inputData) {
             String name = data.getName();
             if (name != null && name.equals("title")) {
@@ -411,6 +432,44 @@
         return null;
     }
 
+
+    /**
+     * Returns the name of the layer.
+     *
+     * @param uuid The uuid the the current session. It is the base part of the
+     * layername.
+     * @param type The type of the layer ('POLYGON' or 'LINE').
+     * @return the name of the layer.
+     */
+    protected String getLayerName(String uuid, String type) {
+        return uuid + "-" + type;
+    }
+
+    /**
+     * Returns the layer title.
+     *
+     * @param prefix A prefix (null not permitted).
+     * @param type The layer type.
+     * @return the title of the layer.
+     */
+    protected String getLayerTitle(String prefix, String type) {
+        return "" + prefix + "-" + type;
+    }
+
+
+    /**
+     * Returns the path to the shapefile that serves the layer data.
+     *
+     * @param shapeDir The shapefile directory.
+     * @param filename The name of the shapefile.
+     * @return the relative path to the shapefile.
+     */
+    protected String getLayerData(String shapeDir, String filename) {
+        File path = new File(shapeDir, filename);
+
+        return path.toString();
+    }
+
     /**
      * Write the resulting data to shapefiles.
      *
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/MetaWriter.java	Thu May 27 08:48:16 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/MetaWriter.java	Thu May 27 16:43:00 2010 +0000
@@ -7,7 +7,10 @@
 import java.io.OutputStream;
 import java.util.Date;
 
+import javax.xml.xpath.XPathConstants;
+
 import org.apache.log4j.Logger;
+
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -34,11 +37,8 @@
     public static final String NODE_TTL       = "ttl";
 
     public static final String META_FILE_NAME = "meta.xml";
-    public static final String ISOLINES_NAME  = "isolines.shp";
-    public static final String POLYGON_NAME   = "polygons.shp";
 
-
-    public static final String CONTEXT_LAYER_TITLE = "wms.title";
+    public static final String XPATH_META = "/art:meta";
 
     /**
      * Constructor.
@@ -46,41 +46,13 @@
     private MetaWriter() {
     }
 
-    /**
-     * Writes a meta information file for product type 'Layer'.
-     *
-     * @param context CallContext object.
-     * @param meta the document where the information should be placed in.
-     * @return the meta document.
-     */
-    public static Node writeLayerMeta(CallContext context, Document meta){
-        XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
-            meta,
-            ArtifactNamespaceContext.NAMESPACE_URI,
-            ArtifactNamespaceContext.NAMESPACE_PREFIX);
-        Element root = creator.create("meta");
-        meta.appendChild(root);
-
-        writeAbstractMeta(context, meta, root);
-        return root;
-    }
-
 
     /**
-     * Writes a meta information file for product type 'Horizontalschnitt'.
+     * Just create a new document and insert the root node.
      *
-     * @param context The CallContext object.
-     * @param uuid The UUID of the current artifact.
-     * @param path The destination of the meta file.
-     * @param paramType The parameter type.
-     * @return the meta document.
+     * @return the meta document with necessary root node.
      */
-    public static Document writeHorizontalcrosssectionMeta(
-        CallContext context,
-        String      uuid,
-        String      path,
-        String      paramType)
-    {
+    public static Document initMeta() {
         Document meta = XMLUtils.newDocument();
         XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
             meta,
@@ -90,19 +62,78 @@
         Element root = creator.create("meta");
         meta.appendChild(root);
 
-        writeAbstractMeta(context, meta, root);
-        writePolygonMeta(context, meta, root, uuid, paramType);
-        writeIsolineMeta(context, meta, root, uuid, paramType);
-
-        boolean success = writeMetaFile(path, meta);
+        return meta;
+    }
 
-        if (success){
-            return meta;
-        }else{
-            return null;
+    public static boolean insertLayer(
+        CallContext context,
+        Document    document,
+        String      name,
+        String      title,
+        String      data,
+        String      model,
+        String      type,
+        String      status
+    ) {
+        if (document == null) {
+            document = initMeta();
         }
+
+        Node meta = (Node) XMLUtils.xpath(
+            document,
+            XPATH_META,
+            XPathConstants.NODE,
+            ArtifactNamespaceContext.INSTANCE);
+
+        if (meta == null) {
+            logger.error("No meta node was found in the given document. "
+                + "Cannot insert layer!");
+            return false;
+        }
+
+        XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
+            document,
+            ArtifactNamespaceContext.NAMESPACE_URI,
+            ArtifactNamespaceContext.NAMESPACE_PREFIX);
+
+        Element layerEl  = creator.create(LayerInfo.LAYER);
+        Element nameEl   = creator.create(LayerInfo.LAYER_NAME);
+        Element titleEl  = creator.create(LayerInfo.LAYER_TITLE);
+        Element dataEl   = creator.create(LayerInfo.LAYER_DATA);
+        Element modelEl  = creator.create(LayerInfo.LAYER_MODEL);
+        Element typeEl   = creator.create(LayerInfo.LAYER_TYPE);
+        Element statusEl = creator.create(LayerInfo.LAYER_STATUS);
+
+        modelEl.setTextContent(model);
+        nameEl.setTextContent(name);
+        titleEl.setTextContent(title);
+        typeEl.setTextContent(type);
+        statusEl.setTextContent(status);
+        dataEl.setTextContent(data);
+
+        layerEl.appendChild(modelEl);
+        layerEl.appendChild(nameEl);
+        layerEl.appendChild(titleEl);
+        layerEl.appendChild(dataEl);
+        layerEl.appendChild(typeEl);
+        layerEl.appendChild(statusEl);
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("--------------- WMS LAYER PARAMS ---------------");
+            logger.debug("Name  : " + name);
+            logger.debug("Title : " + title);
+            logger.debug("Data  : " + data);
+            logger.debug("Type  : " + type);
+            logger.debug("Model : " + model);
+            logger.debug("Status: " + status);
+        }
+
+        meta.appendChild(layerEl);
+
+        return true;
     }
 
+
     /**
      * Method to write the <i>meta</i> document down to a file.
      *
@@ -160,11 +191,20 @@
      * @param document The meta information document.
      * @param meta The element where the new information need to be appended to.
      */
-    public static void writeAbstractMeta(
+    public static void insertAbstractMeta(
         CallContext callContext,
-        Document    document,
-        Element     meta
+        Document    document
     ) {
+        if (document == null) {
+            document = initMeta();
+        }
+
+        Node meta = (Node) XMLUtils.xpath(
+            document,
+            XPATH_META,
+            XPathConstants.NODE,
+            ArtifactNamespaceContext.INSTANCE);
+
         XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
             document,
             ArtifactNamespaceContext.NAMESPACE_URI,
@@ -179,197 +219,29 @@
         String map = (String)
             context.get(GNVArtifactContext.MAPSERVER_MAP_PATH_KEY);
 
+        Long time  = callContext.getTimeToLive();
+        time       = time != null ? time + new Date().getTime() : null;
+        String ttl = time != null ? time.toString() : null;
+
         if (logger.isDebugEnabled()) {
             logger.debug("MAPSERVER PATH: " + server);
             logger.debug("MAP PATH: " + map);
+            logger.debug("TTL: " + ttl);
         }
 
         Element mapserver  = creator.create(NODE_MAPSERVER);
         Element serverPath = creator.create(NODE_SERVER);
         Element mapPath    = creator.create(NODE_MAP);
+        Element timetolive = creator.create(NODE_TTL);
 
         mapPath.setTextContent(map);
         serverPath.setTextContent(server);
+        timetolive.setTextContent(ttl);
 
         mapserver.appendChild(serverPath);
         mapserver.appendChild(mapPath);
+        mapserver.appendChild(timetolive);
         meta.appendChild(mapserver);
     }
-
-    /**
-     * Append layer information to the meta document.
-     *
-     * @param callContext The CallContext object.
-     * @param document The meta document.
-     * @param root The element where the new information need to be appended to.
-     * @param uuid The UUID of the current artifact.
-     * @param paramType The parameter type (e.g. salinity).
-     * @param layerType The layer type.
-     * @param shapefileName the name of the Shapefile
-     * @param shapefileName the Title of the Layer
-     */
-    public static void writeLayerMeta(
-        CallContext callContext,
-        Document    document,
-        Node        root,
-        String      uuid,
-        String      paramType,
-        String      layerType,
-        String      shapefileName,
-        String      layerTitle
-    ) {
-        XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
-            document,
-            ArtifactNamespaceContext.NAMESPACE_URI,
-            ArtifactNamespaceContext.NAMESPACE_PREFIX);
-
-        Long time  = callContext.getTimeToLive();
-        time       = time != null ? time + new Date().getTime() : null;
-        String ttl = time != null ? time.toString() : null;
-
-        logger.debug("Artifacts time to live: " + ttl);
-
-        Element layer      = creator.create(LayerInfo.LAYER);
-        Element model      = creator.create(LayerInfo.LAYER_MODEL);
-        Element name       = creator.create(LayerInfo.LAYER_NAME);
-        Element title  = creator.create(LayerInfo.LAYER_TITLE);
-        Element type       = creator.create(LayerInfo.LAYER_TYPE);
-        Element status     = creator.create(LayerInfo.LAYER_STATUS);
-        Element data       = creator.create(LayerInfo.LAYER_DATA);
-        Element timeToLive = creator.create(NODE_TTL);
-
-        model.setTextContent(paramType);
-        name.setTextContent(uuid);
-        type.setTextContent(layerType);
-        status.setTextContent("OFF");
-        data.setTextContent(shapefileName);
-        timeToLive.setTextContent(ttl);
-
-        title.setTextContent(layerTitle);
-
-        layer.appendChild(model);
-        layer.appendChild(name);
-        layer.appendChild(title);
-        layer.appendChild(type);
-        layer.appendChild(status);
-        layer.appendChild(data);
-        layer.appendChild(timeToLive);
-
-        root.appendChild(layer);
-    }
-
-
-    /**
-     * Append polygon layer information to meta document.
-     *
-     * @param context
-     * @param document The meta document.
-     * @param meta The element where the new information need to be appended to.
-     * @param uuid The UUID of the current artifact.
-     * @param paramType The parameter type (e.g. salinity).
-     */
-    public static void writePolygonMeta(
-        CallContext context,
-        Document    document,
-        Element     meta,
-        String      uuid,
-        String      paramType
-    ) {
-        XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
-            document,
-            ArtifactNamespaceContext.NAMESPACE_URI,
-            ArtifactNamespaceContext.NAMESPACE_PREFIX);
-
-        Long time  = context.getTimeToLive();
-        time       = time != null ? time + new Date().getTime() : null;
-        String ttl = time != null ? time.toString() : null;
-
-        logger.debug("Artifacts time to live: " + ttl);
-
-        Element layer  = creator.create(LayerInfo.LAYER);
-        Element model  = creator.create(LayerInfo.LAYER_MODEL);
-        Element name   = creator.create(LayerInfo.LAYER_NAME);
-        Element title  = creator.create(LayerInfo.LAYER_TITLE);
-        Element type   = creator.create(LayerInfo.LAYER_TYPE);
-        Element status = creator.create(LayerInfo.LAYER_STATUS);
-        Element data   = creator.create(LayerInfo.LAYER_DATA);
-        Element timeToLive = creator.create(NODE_TTL);
-
-        model.setTextContent(paramType);
-        name.setTextContent(uuid);
-        title.setTextContent(
-            (String) context.getContextValue(CONTEXT_LAYER_TITLE));
-        type.setTextContent("POLYGON");
-        status.setTextContent("OFF");
-        data.setTextContent(POLYGON_NAME);
-        timeToLive.setTextContent(ttl);
-
-        layer.appendChild(model);
-        layer.appendChild(name);
-        layer.appendChild(title);
-        layer.appendChild(type);
-        layer.appendChild(status);
-        layer.appendChild(data);
-        layer.appendChild(timeToLive);
-
-        meta.appendChild(layer);
-    }
-
-
-    /**
-     * Append isoline layer information to meta document.
-     *
-     * @param context
-     * @param document The meta document.
-     * @param meta The element where the new information need to be appended to.
-     * @param uuid The UUID of the current artifact.
-     * @param paramType The parameter type (e.g. salinity).
-     */
-    public static void writeIsolineMeta(
-        CallContext context,
-        Document    document,
-        Element     meta,
-        String      uuid,
-        String      paramType
-    ) {
-        XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
-            document,
-            ArtifactNamespaceContext.NAMESPACE_URI,
-            ArtifactNamespaceContext.NAMESPACE_PREFIX);
-
-        Long time  = context.getTimeToLive();
-        time       = time != null ? time + new Date().getTime() : null;
-        String ttl = time != null ? time.toString() : null;
-
-        logger.debug("Artifacts time to live: " + ttl);
-
-        Element layer  = creator.create(LayerInfo.LAYER);
-        Element model  = creator.create(LayerInfo.LAYER_MODEL);
-        Element name   = creator.create(LayerInfo.LAYER_NAME);
-        Element title  = creator.create(LayerInfo.LAYER_TITLE);
-        Element type   = creator.create(LayerInfo.LAYER_TYPE);
-        Element status = creator.create(LayerInfo.LAYER_STATUS);
-        Element data   = creator.create(LayerInfo.LAYER_DATA);
-        Element timeToLive = creator.create(NODE_TTL);
-
-        model.setTextContent(paramType+"_isolines");
-        name.setTextContent(uuid);
-        title.setTextContent(
-            (String) context.getContextValue(CONTEXT_LAYER_TITLE));
-        type.setTextContent("LINE");
-        status.setTextContent("OFF");
-        data.setTextContent(ISOLINES_NAME);
-        timeToLive.setTextContent(ttl);
-
-        layer.appendChild(model);
-        layer.appendChild(name);
-        layer.appendChild(title);
-        layer.appendChild(type);
-        layer.appendChild(status);
-        layer.appendChild(data);
-        layer.appendChild(timeToLive);
-
-        meta.appendChild(layer);
-    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org