Loading FreeMarker Templates from file system
---------------------------------------------

                 Key: WW-3761
                 URL: https://issues.apache.org/jira/browse/WW-3761
             Project: Struts 2
          Issue Type: Temp
    Affects Versions: 2.3.1.1
         Environment: Tomcat 7.0
            Reporter: Vijayakannan
             Fix For: 2.5


Loading the freemarker template from the file system using templatePath in 
web.xml is not working as expected

Example:

My template path is --> "file://D://templates"

 try {
             if(templatePath!=null){
                 if (templatePath.startsWith("class://")) {
                     // 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));
                 }
             }
         } catch (IOException e) {
             LOG.error("Invalid template path specified: " + e.getMessage(), e);
         }

Line "templatePathLoader = new FileTemplateLoader(new File(templatePath));" 
always return null 


Fix:

By changing the above line as below, it's working fine.

templatePathLoader = new FileTemplateLoader(new 
File(templatePath.substring(7)));



--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to