diff flys-artifacts/src/main/java/de/intevation/flys/utils/MapfileGenerator.java @ 4656:442fbb290fa8

Introduce river mapfile generation (WARNING: Changes in config xml files required!). On startup the RiverMapfileGeneratorStarter is called by the server app. The starter invokes a call to RiverMapfileGenerator.generate() which reads all available rivers from the database and generates layers for each river (in theory...uncompleted) in a river.map file. The old MapfileGenerator which generates layers that have artifact dependencies is now in ArtifactMapfileGenerator.
author Christian Lins <christian.lins@intevation.de>
date Tue, 11 Dec 2012 15:24:24 +0100
parents 861c47e0a8a0
children 38ec171544de
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/MapfileGenerator.java	Tue Dec 11 09:44:04 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/MapfileGenerator.java	Tue Dec 11 15:24:24 2012 +0100
@@ -17,6 +17,7 @@
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.runtime.RuntimeConstants;
 
 /**
  * This class iterates over a bunch of directories, searches for meta
@@ -67,7 +68,7 @@
     }
 
 
-    protected abstract void generate() throws Exception;
+    public abstract void generate() throws Exception;
 
 
     /**
@@ -104,8 +105,8 @@
             "UTF-8");
 
         engine.setProperty(
-            VelocityEngine.RUNTIME_LOG,
-            FLYSUtils.getXPathString(FLYSUtils.XPATH_VELOCITY_LOGFILE));
+            RuntimeConstants.RUNTIME_LOG,
+            getVelocityLogfile());
 
         engine.setProperty(
             "resource.loader",
@@ -113,18 +114,23 @@
 
         engine.setProperty(
             "file.resource.loader.path",
-            FLYSUtils.getXPathString(FLYSUtils.XPATH_MAPSERVER_TEMPLATE_PATH));
+            getMapserverTemplatePath());
 
         engine.init();
     }
 
+    protected abstract String getVelocityLogfile();
+
+    protected abstract String getMapserverTemplatePath();
+
+    protected abstract String getMapserverUrl();
 
     protected VelocityContext getVelocityContext() {
         VelocityContext context = new VelocityContext();
 
         try {
             context.put("MAPSERVERURL",
-                FLYSUtils.getXPathString(FLYSUtils.XPATH_MAPSERVER_URL));
+                getMapserverUrl());
             context.put("SHAPEFILEPATH",
                 getShapefileBaseDir().getCanonicalPath());
             context.put("CONFIGDIR",
@@ -177,15 +183,19 @@
      * @return the mapfile template.
      * @throws Exception if an error occured while reading the configuration.
      */
-    protected Template getMapfileTemplate()
+    protected Template getMapfileTemplateObj()
     throws Exception
     {
         String mapfileName = FLYSUtils.getXPathString(
-            FLYSUtils.XPATH_MAPFILE_TEMPLATE);
+            FLYSUtils.XPATH_FLOODMAP_MAPFILE_TEMPLATE);
 
         return getTemplateByName(mapfileName);
     }
 
+    protected abstract String getMapfilePath();
+
+    protected abstract String getMapfileTemplate();
+
 
     /**
      * Returns the base directory storing the shapefiles.
@@ -200,7 +210,7 @@
     {
         if (shapefileDirectory == null) {
             String path = FLYSUtils.getXPathString(
-                FLYSUtils.XPATH_SHAPEFILE_DIR);
+                FLYSUtils.XPATH_FLOODMAP_SHAPEFILE_DIR);
 
             if (path != null) {
                 shapefileDirectory = new File(path);
@@ -270,27 +280,24 @@
      * section.
      */
     protected void writeLayer(
-        LayerInfo layerinfo,
-        File      dir,
-        String    filename,
+        LayerInfo layerInfo,
+        File      layerFile,
         Template  tpl
     )
     throws    FileNotFoundException
     {
         if (logger.isDebugEnabled()) {
             logger.debug("Write layer for:");
-            logger.debug("   directory: " + dir.getName());
-            logger.debug("   name:      " + filename);
+            logger.debug("   directory/file: " + layerFile.getName());
         }
 
-        File   layer  = new File(dir, filename);
         Writer writer = null;
 
         try {
-            writer = new FileWriter(layer);
+            writer = new FileWriter(layerFile);
 
             VelocityContext context = getVelocityContext();
-            context.put("LAYER", layerinfo);
+            context.put("LAYER", layerInfo);
 
             tpl.merge(context, writer);
         }
@@ -324,8 +331,7 @@
     protected void writeMapfile(List<String> layers) {
         String tmpMapName = "mapfile" + new Date().getTime();
 
-        File mapfile = new File(
-            FLYSUtils.getXPathString(FLYSUtils.XPATH_MAPFILE_PATH));
+        File mapfile = new File(getMapfilePath());
 
         File   tmp     = null;
         Writer writer  = null;
@@ -339,7 +345,7 @@
             VelocityContext context = getVelocityContext();
             context.put("LAYERS", layers);
 
-            Template mapTemplate = getMapfileTemplate();
+            Template mapTemplate = getMapfileTemplateObj();
             if (mapTemplate == null) {
                 logger.warn("No mapfile template found.");
                 return;

http://dive4elements.wald.intevation.org