marmotta-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ja...@apache.org
Subject [1/4] git commit: switched templating to lean template loading which fixes step 2 for MARMOTTA-379
Date Wed, 08 Jan 2014 11:03:39 GMT
Updated Branches:
  refs/heads/develop e5e54ff1b -> bc88f463f


switched templating to lean template loading which fixes step 2 for MARMOTTA-379


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

Branch: refs/heads/develop
Commit: bc88f463f2e73fee10c0b4c18a69f0b1ba6c718d
Parents: b4a418d
Author: Jakob Frank <jakob@apache.org>
Authored: Wed Jan 8 11:59:54 2014 +0100
Committer: Jakob Frank <jakob@apache.org>
Committed: Wed Jan 8 12:02:32 2014 +0100

----------------------------------------------------------------------
 .../templating/TemplatingServiceImpl.java       | 40 ++++++++++++--------
 1 file changed, 24 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/bc88f463/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 e19b770..02a5ff7 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
@@ -84,23 +84,25 @@ public class TemplatingServiceImpl implements TemplatingService {
 
         if (!templateDir.exists()) templateDir.mkdirs();
 
-        for (String fName: new String[] { 
-        		TemplatingService.ADMIN_TPL, 
-        		TemplatingService.ERROR_404_TPL, 
-        		TemplatingService.RDF_HTML_TPL }) {
-	        final File dT = new File(templateDir, fName);
-	        if (!dT.exists()) {
-	            try {
-	                log.warn("Default template not found at {}, copying fallback...", dT.getAbsolutePath());
-	                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);
-	            }
-	        }                                     
-        }
 	}
-	
+
+    private void loadTemplateFromClasspath(String templateName, Class<?> clazz) {
+        final String src = TemplatingService.PATH + templateName;
+        final File dT = new File(templateDir, templateName);
+        if (!dT.exists()) {
+            try {
+                log.info("template {} not found in {}, copying fallback...", templateName,
templateDir.getAbsolutePath());
+                final InputStream str = clazz.getResourceAsStream(src);
+                if (str == null) {
+                    throw new IOException("Resource " + src + " not found in ClassLoader
(" + clazz + ")");
+                }
+                FileUtils.copyInputStreamToFile(str, dT);
+            } catch (IOException e) {
+                log.error("Could not load template from classpath, templating might react
weird!", e);
+            }
+        }
+    }
+    
     /**
      * Update the data model in case an important value has changed
      * @param event
@@ -135,11 +137,17 @@ public class TemplatingServiceImpl implements TemplatingService {
 
     @Override
     public Template getTemplate(String name) throws IOException {
+        // make sure template exists
+        loadTemplateFromClasspath(name, TemplatingServiceImpl.class);
+        
         return getConfiguration().getTemplate(name);
     }
 	
     @Override
     public Template getTemplate(Class<?> cls, String name) throws IOException {
+        // make sure template exists
+        loadTemplateFromClasspath(name, cls);
+        
         return getConfiguration(cls).getTemplate(name);
     }
 	


Mime
View raw message