diff flys-artifacts/src/main/java/de/intevation/flys/utils/RiverMapfileGenerator.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 13abfb1bcb75
line wrap: on
line diff
--- 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);
+    }
 }

http://dive4elements.wald.intevation.org