WW-4169 Solves problem resolving path when action contains slashes

This commit is contained in:
Lukasz Lenart
2014-03-28 08:09:31 +01:00
parent a6017dcac4
commit 272feecfbd
2 changed files with 16 additions and 5 deletions
@@ -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
@@ -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());
}