You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Vijayakannan (Created) (JIRA)" <ji...@apache.org> on 2012/02/22 12:51:48 UTC

[jira] [Created] (WW-3761) Loading FreeMarker Templates from file system

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

        

[jira] [Assigned] (WW-3761) Loading FreeMarker Templates from file system

Posted by "Lukasz Lenart (Assigned) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WW-3761?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Lukasz Lenart reassigned WW-3761:
---------------------------------

    Assignee: Lukasz Lenart
    
> 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
>            Assignee: Lukasz Lenart
>              Labels: freemarker-template-filesystem-loading
>             Fix For: 2.5
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> 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

        

[jira] [Closed] (WW-3761) Loading FreeMarker Templates from file system

Posted by "Lukasz Lenart (Closed) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WW-3761?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Lukasz Lenart closed WW-3761.
-----------------------------

       Resolution: Fixed
    Fix Version/s:     (was: 2.5)
                   2.3.2

Thanks for reporting and patch!
                
> 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
>            Assignee: Lukasz Lenart
>              Labels: freemarker-template-filesystem-loading
>             Fix For: 2.3.2
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> 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

        

[jira] [Commented] (WW-3761) Loading FreeMarker Templates from file system

Posted by "Lukasz Lenart (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WW-3761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13214491#comment-13214491 ] 

Lukasz Lenart commented on WW-3761:
-----------------------------------

So it looks that the only solution is
{code}
templatePathLoader = new FileTemplateLoader(new File(templatePath.substring(7)));
{code}
                
> 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
>            Assignee: Lukasz Lenart
>              Labels: freemarker-template-filesystem-loading
>             Fix For: 2.5
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> 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

        

[jira] [Commented] (WW-3761) Loading FreeMarker Templates from file system

Posted by "Vijayakannan (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WW-3761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13213687#comment-13213687 ] 

Vijayakannan commented on WW-3761:
----------------------------------

Getting the below Exception if we changed the line as

templatePathLoader = new FileTemplateLoader(new File(URI.create(templatePath)));

Exception Details:-

java.lang.IllegalArgumentException: URI has an authority component
at java.io.File.<init>(File.java:368)

File.java line 368

if (uri.getAuthority() != null)
throw new IllegalArgumentException("URI has an authority component");

uri.getAuthority() --> D: in my case
                
> 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
>            Assignee: Lukasz Lenart
>              Labels: freemarker-template-filesystem-loading
>             Fix For: 2.5
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> 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

        

[jira] [Commented] (WW-3761) Loading FreeMarker Templates from file system

Posted by "Hudson (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WW-3761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13214519#comment-13214519 ] 

Hudson commented on WW-3761:
----------------------------

Integrated in Struts2 #419 (See [https://builds.apache.org/job/Struts2/419/])
    WW-3761 - improves loading templates from file path (Revision 1292722)

     Result = SUCCESS
lukaszlenart : 
Files : 
* /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

                
> 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
>            Assignee: Lukasz Lenart
>              Labels: freemarker-template-filesystem-loading
>             Fix For: 2.3.2
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> 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

        

[jira] [Commented] (WW-3761) Loading FreeMarker Templates from file system

Posted by "Lukasz Lenart (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WW-3761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13213606#comment-13213606 ] 

Lukasz Lenart commented on WW-3761:
-----------------------------------

Isn't better to use URI instead ?
{code}
templatePathLoader = new FileTemplateLoader(new File(URI.create(templatePath)));
{code}
                
> 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
>              Labels: freemarker-template-filesystem-loading
>             Fix For: 2.5
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> 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