struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [17/31] git commit: WW-4169 Solves problem resolving path when action contains slashes
Date Sun, 06 Apr 2014 19:14:19 GMT
WW-4169 Solves problem resolving path when action contains slashes


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

Branch: refs/heads/feature/use-js-to-support-multiple-buttons
Commit: 272feecfbd9bd69bf500af31541567f254dd0c6d
Parents: a6017dc
Author: Lukasz Lenart <lukaszlenart@apache.org>
Authored: Fri Mar 28 08:09:31 2014 +0100
Committer: Lukasz Lenart <lukaszlenart@apache.org>
Committed: Fri Mar 28 08:09:31 2014 +0100

----------------------------------------------------------------------
 .../views/freemarker/FreemarkerResult.java        | 18 +++++++++++++-----
 .../views/freemarker/FreeMarkerResultTest.java    |  3 +++
 2 files changed, 16 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/272feecf/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerResult.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerResult.java
b/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerResult.java
index b8af3d6..3ded53b 100644
--- a/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerResult.java
+++ b/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerResult.java
@@ -39,7 +39,6 @@ import org.apache.commons.lang3.ObjectUtils;
 import org.apache.struts2.ServletActionContext;
 import org.apache.struts2.StrutsStatics;
 import org.apache.struts2.dispatcher.StrutsResultSupport;
-import org.apache.struts2.views.util.ResourceUtil;
 
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
@@ -165,12 +164,21 @@ public class FreemarkerResult extends StrutsResultSupport {
         ActionContext ctx = invocation.getInvocationContext();
         HttpServletRequest req = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
 
-        if (!locationArg.startsWith("/")) {
-            String base = ResourceUtil.getResourceBase(req);
-            locationArg = base + "/" + locationArg;
+        String absoluteLocation;
+        if (location.startsWith("/")) {
+            absoluteLocation = location; 
+        } else { 
+            String namespace = invocation.getProxy().getNamespace();
+            if (namespace == null || namespace.length() == 0 || namespace.equals("/")) {
+                absoluteLocation = "/" + location;
+            } else if (namespace.startsWith("/")) {
+                absoluteLocation = namespace + "/" + location;
+            } else {
+                absoluteLocation = "/" + namespace + "/" + location;
+            }
         }
 
-        Template template = configuration.getTemplate(locationArg, deduceLocale());
+        Template template = configuration.getTemplate(absoluteLocation, deduceLocale());
         TemplateModel model = createModel();
 
         // Give subclasses a chance to hook into preprocessing

http://git-wip-us.apache.org/repos/asf/struts/blob/272feecf/core/src/test/java/org/apache/struts2/views/freemarker/FreeMarkerResultTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/views/freemarker/FreeMarkerResultTest.java
b/core/src/test/java/org/apache/struts2/views/freemarker/FreeMarkerResultTest.java
index d721826..060b927 100644
--- a/core/src/test/java/org/apache/struts2/views/freemarker/FreeMarkerResultTest.java
+++ b/core/src/test/java/org/apache/struts2/views/freemarker/FreeMarkerResultTest.java
@@ -22,7 +22,9 @@
 package org.apache.struts2.views.freemarker;
 
 import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionProxy;
 import com.opensymphony.xwork2.mock.MockActionInvocation;
+import com.opensymphony.xwork2.mock.MockActionProxy;
 import com.opensymphony.xwork2.util.ClassLoaderUtil;
 import com.opensymphony.xwork2.util.ValueStack;
 import com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory;
@@ -164,6 +166,7 @@ public class FreeMarkerResultTest extends StrutsInternalTestCase {
         invocation = new MockActionInvocation();
         invocation.setStack(stack);
         invocation.setInvocationContext(context);
+        invocation.setProxy(new MockActionProxy());
         servletContext.setRealPath(new File(FreeMarkerResultTest.class.getResource(
                 "someFreeMarkerFile.ftl").toURI()).toURL().getFile());
     }


Mime
View raw message