diff gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java @ 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 c07d9f9a738c
children cc4ec127d666
line wrap: on
line diff
--- 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.
      *

http://dive4elements.wald.intevation.org