Updated Branches:
  refs/heads/MARMOTTA-228 cbd4caaa7 -> 39deea295

copy template files to home directory


Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/39deea29
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/39deea29
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/39deea29

Branch: refs/heads/MARMOTTA-228
Commit: 39deea295e5833f0c35b1de8dbdf490fc8d6bf08
Parents: cbd4caa
Author: tkurz <[email protected]>
Authored: Fri May 17 12:10:13 2013 +0200
Committer: tkurz <[email protected]>
Committed: Fri May 17 12:10:13 2013 +0200

----------------------------------------------------------------------
 .../services/templating/TemplatingServiceImpl.java |   40 ++++++++++++---
 1 files changed, 33 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/39deea29/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/templating/TemplatingServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/templating/TemplatingServiceImpl.java
 
b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/templating/TemplatingServiceImpl.java
index 56728cc..2740442 100644
--- 
a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/templating/TemplatingServiceImpl.java
+++ 
b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/templating/TemplatingServiceImpl.java
@@ -17,12 +17,7 @@
  */
 package org.apache.marmotta.platform.core.services.templating;
 
-import java.io.BufferedWriter;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
+import java.io.*;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -31,6 +26,8 @@ import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.event.Observes;
 import javax.inject.Inject;
 
+import org.apache.commons.io.FileUtils;
+import org.apache.log4j.helpers.LogLog;
 import org.apache.marmotta.platform.core.api.config.ConfigurationService;
 import org.apache.marmotta.platform.core.api.templating.TemplatingService;
 import org.apache.marmotta.platform.core.events.ConfigurationChangedEvent;
@@ -38,6 +35,8 @@ import 
org.apache.marmotta.platform.core.events.ConfigurationChangedEvent;
 import freemarker.template.Configuration;
 import freemarker.template.Template;
 import freemarker.template.TemplateException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Template Service Implementation
@@ -52,6 +51,10 @@ public class TemplatingServiceImpl implements 
TemplatingService {
     @Inject
     private ConfigurationService configurationService;
 
+    private static Logger log = 
LoggerFactory.getLogger(ConfigurationService.class);
+
+    private File templateDir;
+
        public TemplatingServiceImpl() {
                super();
                common = new HashMap<String,String>();
@@ -66,6 +69,22 @@ public class TemplatingServiceImpl implements 
TemplatingService {
         common.put("BASIC_URL", configurationService.getBaseUri());
         common.put("LOGO", 
configurationService.getStringConfiguration("kiwi.pages.project."+project+".logo",
 project+".png"));
         common.put("FOOTER", 
configurationService.getStringConfiguration("kiwi.pages.project."+project+".footer",
 "(footer not properly configured for project "+project+")"));
+
+        templateDir =new 
File(configurationService.getHome()+TemplatingService.PATH);
+
+        if (!templateDir.exists()) templateDir.mkdirs();
+
+        for (String fName: new String[] {"admin.ftl", "404.ftl", 
"rdfhtml.ftl"}) {
+        final File dT = new File(templateDir, fName);
+        if (!dT.exists()) {
+            try {
+                log.info("Default Template not found, using fallback...");
+                final InputStream str = 
this.getClass().getResourceAsStream(TemplatingService.PATH+fName);
+                FileUtils.copyInputStreamToFile(str, dT);
+            } catch (IOException e) {
+                log.error("Could not create fallback template, templating 
might react weird!", e);
+            }
+        }                                      }
        }
        
     /**
@@ -89,10 +108,17 @@ public class TemplatingServiceImpl implements 
TemplatingService {
        @Override
     public  Configuration getConfiguration(Class<?> cls) {
         Configuration cfg = new Configuration();
-        cfg.setClassForTemplateLoading(cls, TemplatingService.PATH);
+        try {
+            cfg.setDirectoryForTemplateLoading(templateDir);
+        } catch (IOException e) {
+            LogLog.warn("not a directory");
+            cfg.setClassForTemplateLoading(cls, TemplatingService.PATH);
+        }
         return cfg;
     }
 
+
+
     @Override
     public Template getTemplate(String name) throws IOException {
         return getConfiguration().getTemplate(name);

Reply via email to