diff gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.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 4fc97074eb90
children 199982e8866e
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java	Mon Mar 08 10:51:01 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/layer/LayerOutputState.java	Mon Mar 08 14:04:28 2010 +0000
@@ -7,10 +7,13 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Map;
 
 import org.apache.log4j.Logger;
 import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
 import com.vividsolutions.jts.geom.Geometry;
@@ -26,11 +29,13 @@
 import de.intevation.gnv.geobackend.base.query.QueryExecutor;
 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory;
 import de.intevation.gnv.geobackend.base.query.exception.QueryException;
+import de.intevation.gnv.raster.PaletteManager;
 import de.intevation.gnv.state.InputData;
 import de.intevation.gnv.state.OutputStateBase;
 import de.intevation.gnv.state.exception.StateException;
 import de.intevation.gnv.utils.FileUtils;
 import de.intevation.gnv.utils.MapfileGenerator;
+import de.intevation.gnv.utils.MetaWriter;
 import de.intevation.gnv.utils.ShapeFileWriter;
 
 /**
@@ -48,6 +53,9 @@
      * The UID of this Class.
      */
     private static final long serialVersionUID = 9180957321704424049L;
+    
+    // TODO: Replace
+    public static final String LAYER_MODEL    = "layer";
 
     /**
      * The ID for the Query fetching the Layer from the DB
@@ -69,6 +77,8 @@
     
     private String shapeFilePath;
     
+    private String geometryType = null;
+    
     public static final String SHAPEFILE_NAME   = "data.shp";
     
     /**
@@ -92,7 +102,7 @@
                 format, XPATH_OUTPUT_MODE, ArtifactNamespaceContext.INSTANCE);
         if (outputMode.equalsIgnoreCase("wms")) {
             Collection<Result> data = this.fetchData();
-            // TODO USE ME
+            XMLUtils.toStream(this.getWMS(uuid, callContext, data),outputStream);
         }else if (outputMode.equalsIgnoreCase("zip")){
             Collection<Result> data = this.fetchData();
             this.writeZip(uuid, callContext, outputStream, data);
@@ -227,7 +237,7 @@
             }
 
             File shapeFile = new File(shapeDir, SHAPEFILE_NAME);
-            if (!ShapeFileWriter.writeDataToFile(shapeFile, "data", data)){
+            if ((geometryType = ShapeFileWriter.writeDataToFile(shapeFile, "data", data)) == null){
                 log.error("writing data into shapefile failed");
                 return null;
             }
@@ -333,9 +343,70 @@
         synchronized (shapeFileLock) {
             String path = shapeFilePath;
             shapeFilePath = null;
+            geometryType = null;
             return path;
         }
     }
+    protected Document getWMS(String uuid, 
+                              CallContext callContext, 
+                              Collection<Result> data) 
+    throws StateException
+    {
+        // TODO: Do the real WMS publishing here!
+        Document document = XMLUtils.newDocument();
+
+        Element pathElement = document.createElement("path");
+        document.appendChild(pathElement);
+
+        String path = getShapeFilePath();
+
+        if (path != null && new File(path).isDirectory()) {
+            pathElement.setTextContent(path);
+        }
+        else {
+            
+            if (data != null &&
+                (path = writeToShapeFile(uuid, data, callContext)) != null) {
+
+                String paramType = LAYER_MODEL+"_"+this.geometryType.toLowerCase();
+               
+                Document meta = MetaWriter.writeLayerMeta(callContext, uuid, 
+                                                          path, paramType, 
+                                                          this.determineGeometryType());
+                if (meta != null) {
+                    MapfileGenerator.getInstance().update();
+                    return meta;
+                }
+
+                pathElement.setTextContent(path);
+            }
+        }
+
+        return document;
+    }
     
+    private String determineGeometryType(){
+        
+        String returnValue = this.geometryType.toLowerCase();
+        
+        if (returnValue.equalsIgnoreCase("linestring")){
+            returnValue = "Line";
+        }
+        return returnValue;
+    }
+    
+    private static Map<Integer, PaletteManager> getPalettes(
+            CallContext callContext
+        ) {
+        //TODO: customize for product Layer
+            GNVArtifactContext context = 
+                (GNVArtifactContext)callContext.globalContext();
+            Map<Integer, PaletteManager> palettes =
+                (Map<Integer, PaletteManager>)context.get(
+                    GNVArtifactContext.PALETTES_KEY);
+            return palettes != null
+                ? palettes
+                : new HashMap<Integer, PaletteManager>();
+        }
 
 }

http://dive4elements.wald.intevation.org