diff gnv-artifacts/src/main/java/de/intevation/gnv/utils/MapfileGenerator.java @ 624:6a3a1da5e680

Improved velocity configuration. gnv-artifacts/trunk@696 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 22 Feb 2010 10:43:25 +0000
parents 65f09139e9b3
children 40ead2d2a08d
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/MapfileGenerator.java	Sun Feb 21 21:05:55 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/MapfileGenerator.java	Mon Feb 22 10:43:25 2010 +0000
@@ -53,6 +53,9 @@
     public static final String SHAPEFILE_BASE_DIR =
         "/artifact-database/map-generator/mapfile/shapefiles/text()";
 
+    public static final String VELOCITY_LOGFILE =
+        "/artifact-database/velocity/logfile/@path";
+
     public static final String META_FILE_NAME = "meta.xml";
 
     public static final String XPATH_LAYER        = "/art:meta/art:layer";
@@ -153,26 +156,39 @@
     protected void setupVelocity(VelocityEngine engine)
     throws Exception
     {
-        Properties ps = new Properties();
-
-        ps.setProperty(
+        engine.setProperty(
             "input.encoding",
             "UTF-8");
 
-        ps.setProperty(
-            "resource.loader",
-            "class");
+        engine.setProperty(
+            VelocityEngine.RUNTIME_LOG,
+            getVelocityLogfile());
 
-        ps.setProperty(
-            "class.resource.loader.class",
-            "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
+        engine.setProperty(
+            "resource.loader",
+            "file");
 
-        engine.init(ps);
+        engine.setProperty(
+            "file.resource.loader.path",
+            getTemplateBaseDir());
+
+        engine.init();
+    }
+
+
+    protected String getVelocityLogfile() {
+        if (velocityLogfile == null)
+            velocityLogfile = Config.getStringXPath(VELOCITY_LOGFILE);
+
+        return velocityLogfile;
     }
 
 
     protected String getTemplateBaseDir() {
-        return Config.getStringXPath(TEMPLATE_PATH);
+        if (templatePath == null)
+            templatePath = Config.getStringXPath(TEMPLATE_PATH);
+
+        return templatePath;
     }
 
 
@@ -182,12 +198,6 @@
             model = model.concat(".vm");
         }
 
-        File file = new File(templatePath, model);
-        if (!file.exists() || !file.canRead()) {
-            logger.warn("Can't find template file: " + file.getAbsolutePath());
-            return null;
-        }
-
         try {
             VelocityEngine engine = getVelocityEngine();
             if (engine == null) {
@@ -195,7 +205,7 @@
                 return null;
             }
 
-            return engine.getTemplate(file.getAbsolutePath());
+            return engine.getTemplate(model);
         }
         catch (Exception e) {
             logger.warn(e, e);

http://dive4elements.wald.intevation.org