[Dive4elements-commits] [PATCH] Introduce river mapfile generation (WARNING: Changes in config xml files required!)

Wald Commits scm-commit at wald.intevation.org
Tue Dec 11 15:24:30 CET 2012


# HG changeset patch
# User Christian Lins <christian.lins at intevation.de>
# Date 1355235864 -3600
# Node ID 442fbb290fa82dd32b2c9877ca9c5de8adba5bee
# Parent  cd44d28d0fbc03db1076c509ae715f9d94c42067
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.

diff -r cd44d28d0fbc -r 442fbb290fa8 flys-artifacts/doc/conf/conf.xml
--- a/flys-artifacts/doc/conf/conf.xml	Tue Dec 11 09:44:04 2012 +0100
+++ b/flys-artifacts/doc/conf/conf.xml	Tue Dec 11 15:24:24 2012 +0100
@@ -6,6 +6,7 @@
     <!ENTITY seddb-db    SYSTEM "seddb-db.xml">
     <!ENTITY rest-server SYSTEM "rest-server.xml">
     <!ENTITY floodmap    SYSTEM "floodmap.xml">
+    <!ENTITY rivermap	 SYSTEM "rivermap.xml">
 ]>
 <artifact-database>
     <export-secret>YOUR_SECRET</export-secret>
@@ -224,7 +225,7 @@
     <lifetime-listeners>
         <listener>de.intevation.flys.artifacts.datacage.Datacage</listener>
         <listener>de.intevation.flys.wsplgen.SchedulerSetup</listener>
-        <listener>de.intevation.flys.map.RiverMapGeneratorStarter</listener>
+        <listener>de.intevation.flys.artifacts.map.RiverMapfileGeneratorStarter</listener>
     </lifetime-listeners>
 
     <backend-listeners>
@@ -371,6 +372,7 @@
     </metadata>
 
     &floodmap;
+    &rivermap;
 
     &rest-server;
 
diff -r cd44d28d0fbc -r 442fbb290fa8 flys-artifacts/doc/conf/floodmap.xml
--- a/flys-artifacts/doc/conf/floodmap.xml	Tue Dec 11 09:44:04 2012 +0100
+++ b/flys-artifacts/doc/conf/floodmap.xml	Tue Dec 11 15:24:24 2012 +0100
@@ -9,7 +9,7 @@
     </mapserver>
 
     <velocity>
-        <logfile path="${artifacts.config.dir}/../velocity_log.log"/>
+        <logfile path="${artifacts.config.dir}/../velocity.log"/>
     </velocity>
 
     <river name="Saar">
diff -r cd44d28d0fbc -r 442fbb290fa8 flys-artifacts/doc/conf/rivermap.xml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/doc/conf/rivermap.xml	Tue Dec 11 15:24:24 2012 +0100
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--// configuration fragment for static river WMS //-->
+<rivermap>
+    <mapserver>
+        <server path="http://flys-devel.intevation.de/cgi-bin/"/>
+        <mapfile path="${artifacts.config.dir}/../rivers.map"/>
+        <templates path="${artifacts.config.dir}/mapserver/"/>
+        <map-template path="mapfile.vm"/>
+    </mapserver>
+
+    <velocity>
+        <logfile path="${artifacts.config.dir}/../rivermap_velocity.log"/>
+    </velocity>
+</rivermap>
diff -r cd44d28d0fbc -r 442fbb290fa8 flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java	Tue Dec 11 09:44:04 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java	Tue Dec 11 15:24:24 2012 +0100
@@ -344,7 +344,7 @@
         public void endOfLife(Artifact owner, Object context) {
             logger.info("Destroy WMSDBState: " + getID());
 
-            String p = FLYSUtils.getXPathString(FLYSUtils.XPATH_SHAPEFILE_DIR);
+            String p = FLYSUtils.getXPathString(FLYSUtils.XPATH_FLOODMAP_SHAPEFILE_DIR);
             File dir = new File(p, owner.identifier());
 
             if (dir != null && dir.exists()) {
diff -r cd44d28d0fbc -r 442fbb290fa8 flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java	Tue Dec 11 09:44:04 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/FLYSContextFactory.java	Tue Dec 11 15:24:24 2012 +0100
@@ -1,5 +1,22 @@
 package de.intevation.flys.artifacts.context;
 
+import de.intevation.artifactdatabase.state.State;
+import de.intevation.artifactdatabase.state.StateEngine;
+import de.intevation.artifactdatabase.transition.Transition;
+import de.intevation.artifactdatabase.transition.TransitionEngine;
+import de.intevation.artifacts.ArtifactContextFactory;
+import de.intevation.artifacts.GlobalContext;
+import de.intevation.artifacts.common.utils.Config;
+import de.intevation.artifacts.common.utils.XMLUtils;
+import de.intevation.flys.artifacts.model.Module;
+import de.intevation.flys.artifacts.model.ZoomScale;
+import de.intevation.flys.artifacts.states.StateFactory;
+import de.intevation.flys.artifacts.transitions.TransitionFactory;
+import de.intevation.flys.themes.Theme;
+import de.intevation.flys.themes.ThemeFactory;
+import de.intevation.flys.themes.ThemeGroup;
+import de.intevation.flys.themes.ThemeMapping;
+
 import java.io.File;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -9,32 +26,11 @@
 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;
 import org.w3c.dom.NodeList;
 
-import de.intevation.artifacts.ArtifactContextFactory;
-import de.intevation.artifacts.GlobalContext;
-
-import de.intevation.artifacts.common.utils.XMLUtils;
-import de.intevation.artifacts.common.utils.Config;
-
-import de.intevation.artifactdatabase.state.State;
-import de.intevation.artifactdatabase.state.StateEngine;
-import de.intevation.artifactdatabase.transition.Transition;
-import de.intevation.artifactdatabase.transition.TransitionEngine;
-
-import de.intevation.flys.artifacts.model.Module;
-import de.intevation.flys.artifacts.model.ZoomScale;
-import de.intevation.flys.artifacts.states.StateFactory;
-import de.intevation.flys.artifacts.transitions.TransitionFactory;
-import de.intevation.flys.themes.Theme;
-import de.intevation.flys.themes.ThemeGroup;
-import de.intevation.flys.themes.ThemeFactory;
-import de.intevation.flys.themes.ThemeMapping;
-
 
 /**
  * The ArtifactContextFactory is used to initialize basic components and put
@@ -94,6 +90,7 @@
      * @param config The artifact server configuration.
      * @return a FLYSArtifactContext.
      */
+    @Override
     public GlobalContext createArtifactContext(Document config) {
         FLYSContext context = new FLYSContext(config);
 
@@ -102,7 +99,7 @@
         configureOutGenerators(config, context);
         configureThemes(config, context);
         configureThemesMappings(config, context);
-        configureRiverWMS(config, context);
+        configureFloodmapWMS(config, context);
         configureModules(config, context);
         configureZoomScales(config, context);
 
@@ -110,7 +107,7 @@
     }
 
 
-    private void configureZoomScales(Document config, FLYSContext context) {
+    protected void configureZoomScales(Document config, FLYSContext context) {
         NodeList list = (NodeList)XMLUtils.xpath(
             config,
             XPATH_ZOOM_SCALES,
@@ -278,7 +275,7 @@
      * @param context the FLYSContext.
      */
     protected void configureOutGenerators(Document config, FLYSContext context){
-        Map<String, Class> generators = new HashMap<String, Class>();
+        Map<String, Class<?>> generators = new HashMap<String, Class<?>>();
 
         NodeList outGenerators = (NodeList) XMLUtils.xpath(
             config,
@@ -451,7 +448,13 @@
     }
 
 
-    protected void configureRiverWMS(Document cfg, FLYSContext context) {
+    /**
+     * Reads configured floodmap river WMSs from floodmap.xml and
+     * loads them into the given FLYSContext.
+     * @param cfg
+     * @param context
+     */
+    protected void configureFloodmapWMS(Document cfg, FLYSContext context) {
         Map<String, String> riverWMS = new HashMap<String, String>();
 
         NodeList rivers = (NodeList) XMLUtils.xpath(
diff -r cd44d28d0fbc -r 442fbb290fa8 flys-artifacts/src/main/java/de/intevation/flys/artifacts/map/RiverMapfileGeneratorStarter.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/map/RiverMapfileGeneratorStarter.java	Tue Dec 11 09:44:04 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/map/RiverMapfileGeneratorStarter.java	Tue Dec 11 15:24:24 2012 +0100
@@ -10,6 +10,7 @@
 /**
  * LifetimeListener that creates a Mapfile containing river axis layers.
  * The listener is called when the server has completed its startup.
+ *
  * @author <a href="mailto:christian.lins at intevation.de">Christian Lins</a>
  */
 public class RiverMapfileGeneratorStarter implements LifetimeListener {
@@ -18,15 +19,18 @@
 
     @Override
     public void setup(Document document) {
-
+        // Nothing to setup here
     }
 
+    /**
+     * Calls RiverMapfileGenerator.generate().
+     */
     @Override
     public void systemUp(GlobalContext globalContext) {
         logger.debug("systemUp()");
 
         RiverMapfileGenerator fmfg = new RiverMapfileGenerator();
-
+        fmfg.generate();
     }
 
     @Override
diff -r cd44d28d0fbc -r 442fbb290fa8 flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/FileUploadService.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/FileUploadService.java	Tue Dec 11 09:44:04 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/FileUploadService.java	Tue Dec 11 15:24:24 2012 +0100
@@ -1,26 +1,22 @@
 package de.intevation.flys.artifacts.services;
 
+import de.intevation.artifacts.CallMeta;
+import de.intevation.artifacts.GlobalContext;
+import de.intevation.artifacts.common.ArtifactNamespaceContext;
+import de.intevation.artifacts.common.utils.FileTools;
+import de.intevation.artifacts.common.utils.XMLUtils;
+import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
+import de.intevation.flys.utils.FLYSUtils;
+
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 
+import org.apache.commons.codec.binary.Base64;
 import org.apache.log4j.Logger;
-
-import org.apache.commons.codec.binary.Base64;
-
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import de.intevation.artifacts.common.ArtifactNamespaceContext;
-import de.intevation.artifacts.common.utils.XMLUtils;
-import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
-import de.intevation.artifacts.common.utils.FileTools;
-
-import de.intevation.artifacts.CallMeta;
-import de.intevation.artifacts.GlobalContext;
-
-import de.intevation.flys.utils.FLYSUtils;
-
 /**
  * @author <a href="mailto:raimund.renkert at intevation.de">Raimund Renkert</a>
  */
@@ -54,7 +50,7 @@
         if (fileData != null) {
             try {
                 String shapePath = FLYSUtils.getXPathString(
-                    FLYSUtils.XPATH_SHAPEFILE_DIR);
+                    FLYSUtils.XPATH_FLOODMAP_SHAPEFILE_DIR);
 
                 File artifactDir = FileTools.getDirectory(shapePath, uuid);
                 FileOutputStream fos =
diff -r cd44d28d0fbc -r 442fbb290fa8 flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java	Tue Dec 11 09:44:04 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java	Tue Dec 11 15:24:24 2012 +0100
@@ -227,7 +227,7 @@
      */
     protected File getDirectory(FLYSArtifact artifact) {
         String shapePath = FLYSUtils.getXPathString(
-            FLYSUtils.XPATH_SHAPEFILE_DIR);
+            FLYSUtils.XPATH_FLOODMAP_SHAPEFILE_DIR);
 
         File artifactDir = FileTools.getDirectory(
             shapePath, artifact.identifier());
@@ -242,13 +242,16 @@
      */
     protected void removeDirectory(FLYSArtifact artifact) {
         String shapePath = FLYSUtils.getXPathString(
-            FLYSUtils.XPATH_SHAPEFILE_DIR);
+            FLYSUtils.XPATH_FLOODMAP_SHAPEFILE_DIR);
 
         File artifactDir = new File(shapePath, artifact.identifier());
 
         if (artifactDir.exists()) {
             logger.info("Delete directory: " + artifactDir.getAbsolutePath());
-            boolean success = FileTools.deleteRecursive(artifactDir);
+            if (!FileTools.deleteRecursive(artifactDir)) {
+                logger.warn("Could not delete directory: "
+                        + artifactDir.getAbsolutePath());
+            }
         }
         else {
             logger.debug("There is no directory to remove.");
diff -r cd44d28d0fbc -r 442fbb290fa8 flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ScenarioSelect.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ScenarioSelect.java	Tue Dec 11 09:44:04 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ScenarioSelect.java	Tue Dec 11 15:24:24 2012 +0100
@@ -1,25 +1,21 @@
 package de.intevation.flys.artifacts.states;
 
+import de.intevation.artifactdatabase.ProtocolUtils;
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+import de.intevation.artifacts.CallMeta;
+import de.intevation.artifacts.common.utils.FileTools;
+import de.intevation.artifacts.common.utils.XMLUtils;
+import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
+import de.intevation.flys.artifacts.FLYSArtifact;
+import de.intevation.flys.artifacts.resources.Resources;
+import de.intevation.flys.utils.FLYSUtils;
+
 import java.io.File;
 
 import org.apache.log4j.Logger;
-
 import org.w3c.dom.Element;
 
-import de.intevation.artifacts.Artifact;
-import de.intevation.artifacts.CallContext;
-import de.intevation.artifacts.CallMeta;
-
-import de.intevation.artifacts.common.utils.XMLUtils;
-import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
-import de.intevation.artifacts.common.utils.FileTools;
-
-import de.intevation.artifactdatabase.ProtocolUtils;
-
-import de.intevation.flys.artifacts.FLYSArtifact;
-import de.intevation.flys.artifacts.resources.Resources;
-import de.intevation.flys.utils.FLYSUtils;
-
 /**
  * @author <a href="mailto:ingo.weinzierl at intevation.de">Ingo Weinzierl</a>
  */
@@ -105,6 +101,7 @@
     }
 
 
+    @Override
     protected Element createItem(XMLUtils.ElementCreator cr, Object obj) {
         Element item  = ProtocolUtils.createArtNode(cr, "item", null, null);
         Element label = ProtocolUtils.createArtNode(cr, "label", null, null);
@@ -137,9 +134,10 @@
      * Removes the directory and all its content where the required data and the
      * results of WSPLGEN are stored. Should be called in endOfLife().
      */
+    // FIXME: I've seen this code somewhere else...
     protected void removeDirectory(FLYSArtifact artifact) {
         String shapePath = FLYSUtils.getXPathString(
-            FLYSUtils.XPATH_SHAPEFILE_DIR);
+            FLYSUtils.XPATH_FLOODMAP_SHAPEFILE_DIR);
 
         File artifactDir = new File(shapePath, artifact.identifier());
 
diff -r cd44d28d0fbc -r 442fbb290fa8 flys-artifacts/src/main/java/de/intevation/flys/utils/ArtefactMapfileGenerator.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/ArtefactMapfileGenerator.java	Tue Dec 11 09:44:04 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/ArtefactMapfileGenerator.java	Tue Dec 11 15:24:24 2012 +0100
@@ -23,6 +23,21 @@
 
     private static Logger logger = Logger.getLogger(ArtefactMapfileGenerator.class);
 
+    @Override
+    protected String getVelocityLogfile() {
+        return FLYSUtils.getXPathString(FLYSUtils.XPATH_FLOODMAP_VELOCITY_LOGFILE);
+    }
+
+    @Override
+    protected String getMapserverTemplatePath() {
+        return FLYSUtils.getXPathString(FLYSUtils.XPATH_FLOODMAP_MAPSERVER_TEMPLATE_PATH);
+    }
+
+    @Override
+    protected String getMapserverUrl() {
+        return FLYSUtils.getXPathString(FLYSUtils.XPATH_FLOODMAP_MAPSERVER_URL);
+    }
+
     /**
      * Method which starts searching for meta information file and mapfile
      * generation.
@@ -74,7 +89,7 @@
 
         try {
             File dir = new File(getShapefileBaseDir(), flys.identifier());
-            writeLayer(layerinfo, dir, name, template);
+            writeLayer(layerinfo, new File(dir, name), template);
         }
         catch (FileNotFoundException fnfe) {
             logger.error(fnfe, fnfe);
@@ -140,7 +155,7 @@
         }
 
         try {
-            writeLayer(lineInfo, dir, nameLines, tpl);
+            writeLayer(lineInfo, new File(dir, nameLines), tpl);
         }
         catch (FileNotFoundException fnfe) {
             logger.error(fnfe, fnfe);
@@ -185,7 +200,7 @@
             }
 
             try {
-                writeLayer(polygonInfo, dir, namePolygons, tpl);
+                writeLayer(polygonInfo, new File(dir, namePolygons), tpl);
             }
             catch (FileNotFoundException fnfe) {
                 logger.error(fnfe, fnfe);
@@ -250,7 +265,7 @@
             }
 
             try {
-                writeLayer(info, dir, nameUser, tpl);
+                writeLayer(info, new File(dir, nameUser), tpl);
             }
             catch (FileNotFoundException fnfe) {
                 logger.error(fnfe, fnfe);
@@ -301,7 +316,7 @@
 
             try {
                 File dir = new File(getShapefileBaseDir(), flys.identifier());
-                writeLayer(layerinfo, dir, name, template);
+                writeLayer(layerinfo, new File(dir, name), template);
             }
             catch (FileNotFoundException fnfe) {
                 logger.error(fnfe, fnfe);
@@ -309,4 +324,14 @@
             }
         }
 
+        @Override
+        protected String getMapfilePath() {
+            return FLYSUtils.getXPathString(FLYSUtils.XPATH_FLOODMAP_MAPFILE_PATH);
+        }
+
+        @Override
+        protected String getMapfileTemplate() {
+            return FLYSUtils.getXPathString(FLYSUtils.XPATH_FLOODMAP_MAPFILE_TEMPLATE);
+        }
+
 }
diff -r cd44d28d0fbc -r 442fbb290fa8 flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java	Tue Dec 11 09:44:04 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java	Tue Dec 11 15:24:24 2012 +0100
@@ -70,27 +70,48 @@
     public static final Pattern NUMBERS_PATTERN =
         Pattern.compile("\\D*(\\d++.\\d*)\\D*");
 
-    public static final String XPATH_RIVER_PROJECTION =
+    public static final String XPATH_FLOODMAP_RIVER_PROJECTION =
         "/artifact-database/floodmap/river[@name=$name]/srid/@value";
 
-    public static final String XPATH_SHAPEFILE_DIR =
+    public static final String XPATH_FLOODMAP_SHAPEFILE_DIR =
         "/artifact-database/floodmap/shapefile-path/@value";
 
-    public static final String XPATH_VELOCITY_LOGFILE =
+    public static final String XPATH_FLOODMAP_VELOCITY_LOGFILE =
         "/artifact-database/floodmap/velocity/logfile/@path";
 
-    public static final String XPATH_MAPSERVER_URL =
+    public static final String XPATH_FLOODMAP_MAPSERVER_URL =
         "/artifact-database/floodmap/mapserver/server/@path";
 
-    public static final String XPATH_MAPFILE_PATH =
+    public static final String XPATH_FLOODMAP_MAPFILE_PATH =
         "/artifact-database/floodmap/mapserver/mapfile/@path";
 
-    public static final String XPATH_MAPFILE_TEMPLATE =
+    public static final String XPATH_FLOODMAP_MAPFILE_TEMPLATE =
         "/artifact-database/floodmap/mapserver/map-template/@path";
 
-    public static final String XPATH_MAPSERVER_TEMPLATE_PATH =
+    public static final String XPATH_FLOODMAP_MAPSERVER_TEMPLATE_PATH =
         "/artifact-database/floodmap/mapserver/templates/@path";
 
+    public static final String XPATH_RIVERMAP_RIVER_PROJECTION =
+        "/artifact-database/rivermap/river[@name=$name]/srid/@value";
+
+    public static final String XPATH_RIVERMAP_SHAPEFILE_DIR =
+        "/artifact-database/rivermap/shapefile-path/@value";
+
+    public static final String XPATH_RIVERMAP_VELOCITY_LOGFILE =
+        "/artifact-database/rivermap/velocity/logfile/@path";
+
+    public static final String XPATH_RIVERMAP_MAPSERVER_URL =
+        "/artifact-database/rivermap/mapserver/server/@path";
+
+    public static final String XPATH_RIVERMAP_MAPFILE_PATH =
+        "/artifact-database/rivermap/mapserver/mapfile/@path";
+
+    public static final String XPATH_RIVERMAP_MAPFILE_TEMPLATE =
+        "/artifact-database/rivermap/mapserver/map-template/@path";
+
+    public static final String XPATH_RIVERMAP_MAPSERVER_TEMPLATE_PATH =
+        "/artifact-database/rivermap/mapserver/templates/@path";
+
 
     private FLYSUtils() {
     }
@@ -348,6 +369,7 @@
                 locations.add(Double.parseDouble(l));
             }
             catch (NumberFormatException nfe) {
+                logger.debug(nfe.getLocalizedMessage(), nfe);
             }
         }
 
@@ -452,7 +474,7 @@
 
         return (String) XMLUtils.xpath(
             cfg,
-            XPATH_RIVER_PROJECTION,
+            XPATH_FLOODMAP_RIVER_PROJECTION,
             XPathConstants.STRING,
             null,
             variables);
@@ -694,7 +716,7 @@
      * @return the URL of the user wms.
      */
     public static String getUserWMSUrl(String artifactId) {
-        String url = getXPathString(XPATH_MAPSERVER_URL);
+        String url = getXPathString(XPATH_FLOODMAP_MAPSERVER_URL);
         url = url.endsWith("/") ? url + "user-wms" : url + "/" + "user-wms";
 
         return url;
diff -r cd44d28d0fbc -r 442fbb290fa8 flys-artifacts/src/main/java/de/intevation/flys/utils/MapfileGenerator.java
--- 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;
diff -r cd44d28d0fbc -r 442fbb290fa8 flys-artifacts/src/main/java/de/intevation/flys/utils/Pair.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/Pair.java	Tue Dec 11 09:44:04 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/Pair.java	Tue Dec 11 15:24:24 2012 +0100
@@ -21,6 +21,7 @@
     private A a;
     private B b;
 
+    @SuppressWarnings("unused")
     private Pair() {
     }
 
diff -r cd44d28d0fbc -r 442fbb290fa8 flys-artifacts/src/main/java/de/intevation/flys/utils/RiverMapfileGenerator.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/RiverMapfileGenerator.java	Tue Dec 11 09:44:04 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/RiverMapfileGenerator.java	Tue Dec 11 15:24:24 2012 +0100
@@ -4,15 +4,22 @@
 import de.intevation.flys.artifacts.model.RiverFactory;
 import de.intevation.flys.model.River;
 
+import java.io.File;
+import java.io.FileNotFoundException;
 import java.util.List;
 
+import org.apache.log4j.Logger;
+import org.apache.velocity.Template;
+
 public class RiverMapfileGenerator extends MapfileGenerator {
 
+    private static Logger logger = Logger.getLogger(RiverMapfileGenerator.class);
+
     /**
      * Generate river axis mapfile.
      */
     @Override
-    protected void generate() {
+    public void generate() {
         List<River> rivers = RiverFactory.getRivers();
 
         for (River river : rivers) {
@@ -29,6 +36,44 @@
         layerInfo.setName(riverName);
         layerInfo.setSrid(srid);
         layerInfo.setExtent(extend);
+
+        File layerFile = new File(getMapfilePath());
+        Template template = getTemplateByName(DB_LAYER_TEMPLATE);
+        if (template == null) {
+            logger.warn("Template '" + DB_LAYER_TEMPLATE + "' found.");
+            return;
+        }
+
+        try {
+            writeLayer(layerInfo, layerFile, template);
+        }
+        catch (FileNotFoundException e) {
+            logger.warn(e.getLocalizedMessage(), e);
+        }
     }
 
+    @Override
+    protected String getVelocityLogfile() {
+        return FLYSUtils.getXPathString(FLYSUtils.XPATH_RIVERMAP_VELOCITY_LOGFILE);
+    }
+
+    @Override
+    protected String getMapserverTemplatePath() {
+        return FLYSUtils.getXPathString(FLYSUtils.XPATH_RIVERMAP_MAPSERVER_TEMPLATE_PATH);
+    }
+
+    @Override
+    protected String getMapserverUrl() {
+        return FLYSUtils.getXPathString(FLYSUtils.XPATH_RIVERMAP_MAPSERVER_URL);
+    }
+
+    @Override
+    protected String getMapfilePath() {
+        return FLYSUtils.getXPathString(FLYSUtils.XPATH_RIVERMAP_MAPFILE_PATH);
+    }
+
+    @Override
+    protected String getMapfileTemplate() {
+        return FLYSUtils.getXPathString(FLYSUtils.XPATH_RIVERMAP_MAPFILE_TEMPLATE);
+    }
 }


More information about the Dive4elements-commits mailing list