Skip to content

Commit

Permalink
WW-4169 Solves problem resolving path when action contains slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed Mar 28, 2014
1 parent a6017dc commit 272feec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
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;
Expand Down Expand Up @@ -165,12 +164,21 @@ public void doExecute(String locationArg, ActionInvocation invocation) throws IO
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -164,6 +166,7 @@ protected void setUp() throws Exception {
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());
}
Expand Down

0 comments on commit 272feec

Please sign in to comment.