changeset 625:40ead2d2a08d

Restructured configuration, removed duplicated entry and store config information in MapfileGenerator to avoid reading config file every time while updating mapfile. gnv-artifacts/trunk@697 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 22 Feb 2010 11:29:34 +0000
parents 6a3a1da5e680
children 61f688a69a55
files gnv-artifacts/ChangeLog gnv-artifacts/doc/conf/conf.xml gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java gnv-artifacts/src/main/java/de/intevation/gnv/utils/MapfileGenerator.java
diffstat 4 files changed, 63 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Mon Feb 22 10:43:25 2010 +0000
+++ b/gnv-artifacts/ChangeLog	Mon Feb 22 11:29:34 2010 +0000
@@ -1,3 +1,20 @@
+2010-02-22  Ingo Weinzierl <ingo.weinzierl@intevation.de>
+
+	* doc/conf/conf.xml: Restructured configuration of shapfile and template
+	  directories. Moved map-generator part into gnv section.
+	  Moved shapefile-directory configuration to an own section and removed
+	  duplicated shapefile-directory config from map-generator.
+
+	* src/main/java/de/intevation/gnv/utils/MapfileGenerator.java: Adjusted
+	  xpath expressions regarding the changes in conf.xml. MapfileGenerator got
+	  some instance variables to store information about mapfile location,
+	  velocity log file and shapefile and template directories. This avoids
+	  reading conf.xml every single time while updating the mapfile.
+
+	* src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java:
+	  Adjusted xpath expression regaring the changes of shapefile-directory in
+	  conf.xml.
+
 2010-02-22  Ingo Weinzierl <ingo.weinzierl@intevation.de>
 
 	*  doc/conf/conf.xml: Added path for velocity logfile.
--- a/gnv-artifacts/doc/conf/conf.xml	Mon Feb 22 10:43:25 2010 +0000
+++ b/gnv-artifacts/doc/conf/conf.xml	Mon Feb 22 11:29:34 2010 +0000
@@ -461,7 +461,6 @@
             <samples number="1024"/>
             <extrapolation rounds="0"/>
             <ground interpolation="bilinear" />
-            <result-shapefile-directory path="${artifacts.config.dir}/../shapefiles/"/>
         </horizontal-cross-section>
 
         <vertical-cross-section>
@@ -476,6 +475,19 @@
             </filters>
             -->
         </vertical-cross-section>
+
+        <!-- The target directory for shapefiles -->
+        <shapefile-directory path="${artifacts.config.dir}/../shapefiles/" />
+
+        <!-- In this section the required Configuration for mapfile generation is
+             given. -->
+        <map-generator>
+            <mapfile path="/opt/artifacts/mapfiles/mapfile.map" />
+            <templates>
+                <path>${artifacts.config.dir}/maptemplates</path>
+                <maptemplate>mapfile.vm</maptemplate>
+            </templates>
+        </map-generator>
     </gnv>
 
     <velocity>
@@ -514,17 +526,4 @@
         <sql></sql> -->
     </database>
 
-    <!-- In this section the required Configuration for mapfile generation is
-         given. -->
-    <map-generator>
-        <mapfile>
-            <name>mapfile.map</name>
-            <path>/opt/artifacts/mapfiles</path>
-            <shapefiles>/opt/artifacts/shapefiles</shapefiles>
-        </mapfile>
-        <templates>
-            <path>/opt/artifacts/conf/maptemplates</path>
-            <maptemplate>mapfile.vm</maptemplate>
-        </templates>
-    </map-generator>
 </artifact-database>
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java	Mon Feb 22 10:43:25 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java	Mon Feb 22 11:29:34 2010 +0000
@@ -82,7 +82,7 @@
         "/artifact-database/gnv/horizontal-cross-section/extrapolation/@rounds";
     
     public final static String HORIZONTAL_CROSS_SECTION_RESULT_SHAPEFILE_PATH =
-        "/artifact-database/gnv/horizontal-cross-section/result-shapefile-directory/@path";
+        "/artifact-database/gnv/shapefile-directory/@path";
     
     public final static String VERTICAL_CROSS_SECTION_SAMPLES =
         "/artifact-database/gnv/vertical-cross-section/samples";
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/MapfileGenerator.java	Mon Feb 22 10:43:25 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/MapfileGenerator.java	Mon Feb 22 11:29:34 2010 +0000
@@ -2,9 +2,7 @@
 
 import de.intevation.artifactdatabase.Config;
 import de.intevation.artifactdatabase.XMLUtils;
-
 import de.intevation.artifacts.ArtifactNamespaceContext;
-
 import de.intevation.gnv.wms.LayerInfo;
 
 import java.io.File;
@@ -13,11 +11,9 @@
 import java.io.IOException;
 import java.io.StringWriter;
 import java.io.Writer;
-
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
-import java.util.Properties;
 
 import javax.xml.xpath.XPathConstants;
 
@@ -25,13 +21,13 @@
 
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
-
 import org.apache.velocity.app.VelocityEngine;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
+
 /**
  * @author Ingo Weinzierl (ingo.weinzierl@intevation.de)
  */
@@ -39,19 +35,16 @@
 extends Thread
 {
     public static final String TEMPLATE_PATH =
-        "/artifact-database/map-generator/templates/path/text()";
+        "/artifact-database/gnv/map-generator/templates/path/text()";
 
     public static final String TEMPLATE_MAPFILE =
-        "/artifact-database/map-generator/templates/maptemplate/text()";
+        "/artifact-database/gnv/map-generator/templates/maptemplate/text()";
 
     public static final String MAPFILE_PATH =
-        "/artifact-database/map-generator/mapfile/path/text()";
-
-    public static final String MAPFILE_NAME =
-        "/artifact-database/map-generator/mapfile/name/text()";
+        "/artifact-database/gnv/map-generator/mapfile/@path";
 
     public static final String SHAPEFILE_BASE_DIR =
-        "/artifact-database/map-generator/mapfile/shapefiles/text()";
+        "/artifact-database/gnv/shapefile-directory/@path";
 
     public static final String VELOCITY_LOGFILE =
         "/artifact-database/velocity/logfile/@path";
@@ -71,6 +64,11 @@
 
     private static MapfileGenerator instance;
 
+    private File   mapfile;
+    private String shapefileDirectory;
+    private String templatePath;
+    private String velocityLogfile;
+
     private VelocityEngine velocityEngine;
     private boolean lock[];
 
@@ -185,15 +183,16 @@
 
 
     protected String getTemplateBaseDir() {
-        if (templatePath == null)
+        if (templatePath == null) {
             templatePath = Config.getStringXPath(TEMPLATE_PATH);
+            templatePath = Config.replaceConfigDir(templatePath);
+        }
 
         return templatePath;
     }
 
 
     protected Template getTemplateByName(String model) {
-        String templatePath   = getTemplateBaseDir();
         if (model.indexOf(".vm") < 0) {
             model = model.concat(".vm");
         }
@@ -224,7 +223,23 @@
 
 
     protected String getShapefileBaseDir() {
-        return Config.getStringXPath(SHAPEFILE_BASE_DIR);
+        if (shapefileDirectory == null) {
+            shapefileDirectory = Config.getStringXPath(SHAPEFILE_BASE_DIR);
+            shapefileDirectory = Config.replaceConfigDir(shapefileDirectory);
+        }
+
+        return shapefileDirectory;
+    }
+
+
+    protected File getMapfile() {
+        if (mapfile == null) {
+            String tmp = Config.getStringXPath(MAPFILE_PATH);
+            tmp        = Config.replaceConfigDir(tmp);
+            mapfile    = new File(tmp);
+        }
+
+        return mapfile;
     }
 
 
@@ -320,8 +335,6 @@
 
 
     protected void writeMapfile(List layers) {
-        String pathName   = Config.getStringXPath(MAPFILE_PATH);
-        String mapName    = Config.getStringXPath(MAPFILE_NAME);
         String tmpMapName = "mapfile" + new Date().getTime();
 
         int layersize         = layers.size();
@@ -347,13 +360,12 @@
             }
         }
 
+        File   map    = getMapfile();
         Writer writer = null;
         File   tmp    = null;
-        File   map    = null;
 
         try {
-            tmp = new File(pathName, tmpMapName);
-            map = new File(pathName, mapName);
+            tmp = new File(map.getParent(), tmpMapName);
 
             tmp.createNewFile();
             writer   = new FileWriter(tmp);

http://dive4elements.wald.intevation.org