struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject svn commit: r1292722 - in /struts/struts2/trunk/core/src: main/java/org/apache/struts2/views/freemarker/FreemarkerManager.java test/java/org/apache/struts2/views/freemarker/FreemarkerManagerTest.java
Date Thu, 23 Feb 2012 09:28:13 GMT
Author: lukaszlenart
Date: Thu Feb 23 09:28:13 2012
New Revision: 1292722

URL: http://svn.apache.org/viewvc?rev=1292722&view=rev
Log:
WW-3761 - improves loading templates from file path

Modified:
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerManager.java
    struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/freemarker/FreemarkerManagerTest.java

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerManager.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerManager.java?rev=1292722&r1=1292721&r2=1292722&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerManager.java
(original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerManager.java
Thu Feb 23 09:28:13 2012
@@ -27,13 +27,21 @@ import com.opensymphony.xwork2.util.File
 import com.opensymphony.xwork2.util.ValueStack;
 import com.opensymphony.xwork2.util.logging.Logger;
 import com.opensymphony.xwork2.util.logging.LoggerFactory;
-import freemarker.cache.*;
+import freemarker.cache.ClassTemplateLoader;
+import freemarker.cache.FileTemplateLoader;
+import freemarker.cache.MultiTemplateLoader;
+import freemarker.cache.TemplateLoader;
+import freemarker.cache.WebappTemplateLoader;
 import freemarker.ext.jsp.TaglibFactory;
 import freemarker.ext.servlet.HttpRequestHashModel;
 import freemarker.ext.servlet.HttpRequestParametersHashModel;
 import freemarker.ext.servlet.HttpSessionHashModel;
 import freemarker.ext.servlet.ServletContextHashModel;
-import freemarker.template.*;
+import freemarker.template.Configuration;
+import freemarker.template.ObjectWrapper;
+import freemarker.template.TemplateException;
+import freemarker.template.TemplateExceptionHandler;
+import freemarker.template.TemplateModel;
 import freemarker.template.utility.StringUtil;
 import org.apache.struts2.StrutsConstants;
 import org.apache.struts2.views.JspSupportServlet;
@@ -49,7 +57,13 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
 
 
 /**
@@ -382,7 +396,7 @@ public class FreemarkerManager {
                      // substring(7) is intentional as we "reuse" the last slash
                      templatePathLoader = new ClassTemplateLoader(getClass(), templatePath.substring(7));
                  } else if (templatePath.startsWith("file://")) {
-                     templatePathLoader = new FileTemplateLoader(new File(templatePath));
+                     templatePathLoader = new FileTemplateLoader(new File(templatePath.substring(7)));
                  }
              }
          } catch (IOException e) {

Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/freemarker/FreemarkerManagerTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/freemarker/FreemarkerManagerTest.java?rev=1292722&r1=1292721&r2=1292722&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/freemarker/FreemarkerManagerTest.java
(original)
+++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/freemarker/FreemarkerManagerTest.java
Thu Feb 23 09:28:13 2012
@@ -21,12 +21,12 @@
 
 package org.apache.struts2.views.freemarker;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.struts2.StrutsTestCase;
 import org.apache.struts2.views.jsp.StrutsMockServletContext;
 
 /**
  * Test case for FreemarkerManager
- *
  */
 public class FreemarkerManagerTest extends StrutsTestCase {
 
@@ -38,4 +38,27 @@ public class FreemarkerManagerTest exten
         freemarker.template.Configuration conf = mgr.getConfiguration(servletContext);
         assertEquals(conf.getDefaultEncoding(), "UTF-8");
     }
+
+    public void testTemplateLoaderBaseOnFile() throws Exception {
+        // given
+        DummyFreemarkerManager manager = new DummyFreemarkerManager();
+        StrutsMockServletContext servletContext = new StrutsMockServletContext();
+        servletContext.setAttribute(FreemarkerManager.CONFIG_SERVLET_CONTEXT_KEY, null);
+
+        String tmpPath = "file://" + FileUtils.getTempDirectoryPath();
+        
+        // when
+        manager.load(servletContext, tmpPath);
+
+        // then
+        assertTrue(true); // should pass
+    }
+}
+
+class DummyFreemarkerManager extends FreemarkerManager {
+
+    public void load(StrutsMockServletContext servletContext, String path) {
+        createTemplateLoader(servletContext, path);
+    }
+    
 }



Mime
View raw message