You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Jim Cushing (JIRA)" <ji...@apache.org> on 2007/08/29 16:14:35 UTC

[jira] Created: (WW-2146) Codebehind only looks for templates in the web root, not in the class path

Codebehind only looks for templates in the web root, not in the class path
--------------------------------------------------------------------------

                 Key: WW-2146
                 URL: https://issues.apache.org/struts/browse/WW-2146
             Project: Struts 2
          Issue Type: Improvement
          Components: Plugins
    Affects Versions: 2.0.9
            Reporter: Jim Cushing


Normally, Struts 2 will look for templates (Freemarker, Velocity) first in the web root, then in the class path. This allows templates to be bundled with a JAR, but overridden in the web root. When using Codebehind, however, it only looks for the templates in the web root, disabling a valueable Struts 2 feature. The following patch to CodebehindUnknownHandler.java fixes this issue, though it has only been tested with Freemarker. It has not been tested with Velocity, and it does attempt to look for JSPs in the classpath, which may not be appropriate.

------------------------

Index: src/main/java/org/apache/struts2/codebehind/CodebehindUnknownHandler.java
===================================================================
--- src/main/java/org/apache/struts2/codebehind/CodebehindUnknownHandler.java	(revision 570808)
+++ src/main/java/org/apache/struts2/codebehind/CodebehindUnknownHandler.java	(working copy)
@@ -21,6 +21,7 @@
 package org.apache.struts2.codebehind;
 
 import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -107,7 +108,7 @@
             }
             String path = string(pathPrefix, actionName, "." , ext);
             try {
-                if (servletContext.getResource(path) != null) {
+                if (locateTemplate(path) != null) {
                     actionConfig = buildActionConfig(path, namespace, actionName, resultsByExtension.get(ext));
                     break;
                 }
@@ -148,7 +149,7 @@
             }
             String path = string(pathPrefix, actionName, "-", resultCode, "." , ext);
             try {
-                if (servletContext.getResource(path) != null) {
+                if (locateTemplate(path) != null) {
                     result = buildResult(path, resultCode, resultsByExtension.get(ext), actionContext);
                     break;
                 }
@@ -158,7 +159,7 @@
             
             path = string(pathPrefix, actionName, "." , ext);
             try {
-                if (servletContext.getResource(path) != null) {
+                if (locateTemplate(path) != null) {
                     result = buildResult(path, resultCode, resultsByExtension.get(ext), actionContext);
                     break;
                 }
@@ -209,7 +210,23 @@
         }
         return prefix + ns;
     }
+    
+    private URL locateTemplate(String path) throws MalformedURLException {
+        URL template = servletContext.getResource(path);
+        if (template != null) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Loaded template '" + path + "' from servlet context.");
+            }
+        } else {
+            template = this.getClass().getResource(path);
+            if (template != null && LOG.isDebugEnabled()) {
+                LOG.debug("Loaded template '" + path + "' from class path.");                
+            }
+        }
+        return template;
+    }
 
+
     /**
      * Not used
      */



-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (WW-2146) Codebehind only looks for templates in the web root, not in the class path

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

Jim Cushing updated WW-2146:
----------------------------

    Attachment: CodebehindUnknownHandler.java.patch

Patch to enable Codebehind to look in the classpath for templates

> Codebehind only looks for templates in the web root, not in the class path
> --------------------------------------------------------------------------
>
>                 Key: WW-2146
>                 URL: https://issues.apache.org/struts/browse/WW-2146
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Plugins
>    Affects Versions: 2.0.9
>            Reporter: Jim Cushing
>         Attachments: CodebehindUnknownHandler.java.patch
>
>
> Normally, Struts 2 will look for templates (Freemarker, Velocity) first in the web root, then in the class path. This allows templates to be bundled with a JAR, but overridden in the web root. When using Codebehind, however, it only looks for the templates in the web root, disabling a valueable Struts 2 feature. The following patch to CodebehindUnknownHandler.java fixes this issue, though it has only been tested with Freemarker. It has not been tested with Velocity, and it does attempt to look for JSPs in the classpath, which may not be appropriate.
> ------------------------
> Index: src/main/java/org/apache/struts2/codebehind/CodebehindUnknownHandler.java
> ===================================================================
> --- src/main/java/org/apache/struts2/codebehind/CodebehindUnknownHandler.java	(revision 570808)
> +++ src/main/java/org/apache/struts2/codebehind/CodebehindUnknownHandler.java	(working copy)
> @@ -21,6 +21,7 @@
>  package org.apache.struts2.codebehind;
>  
>  import java.net.MalformedURLException;
> +import java.net.URL;
>  import java.util.ArrayList;
>  import java.util.Collections;
>  import java.util.HashMap;
> @@ -107,7 +108,7 @@
>              }
>              String path = string(pathPrefix, actionName, "." , ext);
>              try {
> -                if (servletContext.getResource(path) != null) {
> +                if (locateTemplate(path) != null) {
>                      actionConfig = buildActionConfig(path, namespace, actionName, resultsByExtension.get(ext));
>                      break;
>                  }
> @@ -148,7 +149,7 @@
>              }
>              String path = string(pathPrefix, actionName, "-", resultCode, "." , ext);
>              try {
> -                if (servletContext.getResource(path) != null) {
> +                if (locateTemplate(path) != null) {
>                      result = buildResult(path, resultCode, resultsByExtension.get(ext), actionContext);
>                      break;
>                  }
> @@ -158,7 +159,7 @@
>              
>              path = string(pathPrefix, actionName, "." , ext);
>              try {
> -                if (servletContext.getResource(path) != null) {
> +                if (locateTemplate(path) != null) {
>                      result = buildResult(path, resultCode, resultsByExtension.get(ext), actionContext);
>                      break;
>                  }
> @@ -209,7 +210,23 @@
>          }
>          return prefix + ns;
>      }
> +    
> +    private URL locateTemplate(String path) throws MalformedURLException {
> +        URL template = servletContext.getResource(path);
> +        if (template != null) {
> +            if (LOG.isDebugEnabled()) {
> +                LOG.debug("Loaded template '" + path + "' from servlet context.");
> +            }
> +        } else {
> +            template = this.getClass().getResource(path);
> +            if (template != null && LOG.isDebugEnabled()) {
> +                LOG.debug("Loaded template '" + path + "' from class path.");                
> +            }
> +        }
> +        return template;
> +    }
>  
> +
>      /**
>       * Not used
>       */

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (WW-2146) Codebehind only looks for templates in the web root, not in the class path

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

Don Brown resolved WW-2146.
---------------------------

    Resolution: Fixed
      Assignee: Don Brown

Applied with minor modifications.  Thanks for the patch!

> Codebehind only looks for templates in the web root, not in the class path
> --------------------------------------------------------------------------
>
>                 Key: WW-2146
>                 URL: https://issues.apache.org/struts/browse/WW-2146
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Plugins
>    Affects Versions: 2.0.9
>            Reporter: Jim Cushing
>            Assignee: Don Brown
>             Fix For: 2.1.0
>
>         Attachments: CodebehindUnknownHandler.java.patch
>
>
> Normally, Struts 2 will look for templates (Freemarker, Velocity) first in the web root, then in the class path. This allows templates to be bundled with a JAR, but overridden in the web root. When using Codebehind, however, it only looks for the templates in the web root, disabling a valueable Struts 2 feature. The following patch to CodebehindUnknownHandler.java fixes this issue, though it has only been tested with Freemarker. It has not been tested with Velocity, and it does attempt to look for JSPs in the classpath, which may not be appropriate.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (WW-2146) Codebehind only looks for templates in the web root, not in the class path

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

Jim Cushing updated WW-2146:
----------------------------

    Description: 
Normally, Struts 2 will look for templates (Freemarker, Velocity) first in the web root, then in the class path. This allows templates to be bundled with a JAR, but overridden in the web root. When using Codebehind, however, it only looks for the templates in the web root, disabling a valueable Struts 2 feature. The following patch to CodebehindUnknownHandler.java fixes this issue, though it has only been tested with Freemarker. It has not been tested with Velocity, and it does attempt to look for JSPs in the classpath, which may not be appropriate.


  was:
Normally, Struts 2 will look for templates (Freemarker, Velocity) first in the web root, then in the class path. This allows templates to be bundled with a JAR, but overridden in the web root. When using Codebehind, however, it only looks for the templates in the web root, disabling a valueable Struts 2 feature. The following patch to CodebehindUnknownHandler.java fixes this issue, though it has only been tested with Freemarker. It has not been tested with Velocity, and it does attempt to look for JSPs in the classpath, which may not be appropriate.

------------------------

Index: src/main/java/org/apache/struts2/codebehind/CodebehindUnknownHandler.java
===================================================================
--- src/main/java/org/apache/struts2/codebehind/CodebehindUnknownHandler.java	(revision 570808)
+++ src/main/java/org/apache/struts2/codebehind/CodebehindUnknownHandler.java	(working copy)
@@ -21,6 +21,7 @@
 package org.apache.struts2.codebehind;
 
 import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -107,7 +108,7 @@
             }
             String path = string(pathPrefix, actionName, "." , ext);
             try {
-                if (servletContext.getResource(path) != null) {
+                if (locateTemplate(path) != null) {
                     actionConfig = buildActionConfig(path, namespace, actionName, resultsByExtension.get(ext));
                     break;
                 }
@@ -148,7 +149,7 @@
             }
             String path = string(pathPrefix, actionName, "-", resultCode, "." , ext);
             try {
-                if (servletContext.getResource(path) != null) {
+                if (locateTemplate(path) != null) {
                     result = buildResult(path, resultCode, resultsByExtension.get(ext), actionContext);
                     break;
                 }
@@ -158,7 +159,7 @@
             
             path = string(pathPrefix, actionName, "." , ext);
             try {
-                if (servletContext.getResource(path) != null) {
+                if (locateTemplate(path) != null) {
                     result = buildResult(path, resultCode, resultsByExtension.get(ext), actionContext);
                     break;
                 }
@@ -209,7 +210,23 @@
         }
         return prefix + ns;
     }
+    
+    private URL locateTemplate(String path) throws MalformedURLException {
+        URL template = servletContext.getResource(path);
+        if (template != null) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Loaded template '" + path + "' from servlet context.");
+            }
+        } else {
+            template = this.getClass().getResource(path);
+            if (template != null && LOG.isDebugEnabled()) {
+                LOG.debug("Loaded template '" + path + "' from class path.");                
+            }
+        }
+        return template;
+    }
 
+
     /**
      * Not used
      */




Removing patch from description, since the patch is attached.

> Codebehind only looks for templates in the web root, not in the class path
> --------------------------------------------------------------------------
>
>                 Key: WW-2146
>                 URL: https://issues.apache.org/struts/browse/WW-2146
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Plugins
>    Affects Versions: 2.0.9
>            Reporter: Jim Cushing
>         Attachments: CodebehindUnknownHandler.java.patch
>
>
> Normally, Struts 2 will look for templates (Freemarker, Velocity) first in the web root, then in the class path. This allows templates to be bundled with a JAR, but overridden in the web root. When using Codebehind, however, it only looks for the templates in the web root, disabling a valueable Struts 2 feature. The following patch to CodebehindUnknownHandler.java fixes this issue, though it has only been tested with Freemarker. It has not been tested with Velocity, and it does attempt to look for JSPs in the classpath, which may not be appropriate.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (WW-2146) Codebehind only looks for templates in the web root, not in the class path

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

Don Brown updated WW-2146:
--------------------------

    Fix Version/s:     (was: 2.0.11)
                   2.1.0

> Codebehind only looks for templates in the web root, not in the class path
> --------------------------------------------------------------------------
>
>                 Key: WW-2146
>                 URL: https://issues.apache.org/struts/browse/WW-2146
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Plugins
>    Affects Versions: 2.0.9
>            Reporter: Jim Cushing
>             Fix For: 2.1.0
>
>         Attachments: CodebehindUnknownHandler.java.patch
>
>
> Normally, Struts 2 will look for templates (Freemarker, Velocity) first in the web root, then in the class path. This allows templates to be bundled with a JAR, but overridden in the web root. When using Codebehind, however, it only looks for the templates in the web root, disabling a valueable Struts 2 feature. The following patch to CodebehindUnknownHandler.java fixes this issue, though it has only been tested with Freemarker. It has not been tested with Velocity, and it does attempt to look for JSPs in the classpath, which may not be appropriate.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (WW-2146) Codebehind only looks for templates in the web root, not in the class path

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

James Holmes updated WW-2146:
-----------------------------

    Fix Version/s: 2.0.11

> Codebehind only looks for templates in the web root, not in the class path
> --------------------------------------------------------------------------
>
>                 Key: WW-2146
>                 URL: https://issues.apache.org/struts/browse/WW-2146
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Plugins
>    Affects Versions: 2.0.9
>            Reporter: Jim Cushing
>             Fix For: 2.0.11
>
>         Attachments: CodebehindUnknownHandler.java.patch
>
>
> Normally, Struts 2 will look for templates (Freemarker, Velocity) first in the web root, then in the class path. This allows templates to be bundled with a JAR, but overridden in the web root. When using Codebehind, however, it only looks for the templates in the web root, disabling a valueable Struts 2 feature. The following patch to CodebehindUnknownHandler.java fixes this issue, though it has only been tested with Freemarker. It has not been tested with Velocity, and it does attempt to look for JSPs in the classpath, which may not be appropriate.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.