WW-5336 Deprecate OGNL in template context

This commit is contained in:
Kusal Kithul-Godage
2023-08-21 19:10:40 +10:00
parent 12cd92cb62
commit 85e8d819ef
4 changed files with 10 additions and 7 deletions
@@ -21,7 +21,6 @@ package org.apache.struts2.views.util;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.util.ValueStack;
import org.apache.struts2.util.StrutsUtil;
import org.apache.struts2.views.jsp.ui.OgnlTool;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -48,8 +47,9 @@ public class ContextUtil {
map.put(SESSION, req.getSession(false));
map.put(BASE, req.getContextPath());
map.put(STACK, stack);
map.put(OGNL, stack.getActionContext().getContainer().getInstance(OgnlTool.class));
map.put(STRUTS, new StrutsUtil(stack, req, res));
StrutsUtil util = new StrutsUtil(stack, req, res);
map.put(STRUTS, util);
map.put(OGNL, util); // Deprecated since 6.3.0
ActionInvocation invocation = stack.getActionContext().getActionInvocation();
if (invocation != null) {
+1 -1
View File
@@ -33,5 +33,5 @@
#end
#macro(property $object $property)
$!{ognl.findValue($property, $object)}
$!{struts.findValue($property, $object)}
#end
@@ -58,6 +58,8 @@ import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
import static org.apache.struts2.views.util.ContextUtil.STRUTS;
import static org.apache.struts2.views.util.ContextUtil.OGNL;
/**
* Manages the environment for Velocity result types
*/
@@ -141,7 +143,9 @@ public class VelocityManager {
List<VelocityContext> chainedContexts = prepareChainedContexts(req, res, stack.getContext());
Context context = new StrutsVelocityContext(chainedContexts, stack);
ContextUtil.getStandardContext(stack, req, res).forEach(context::put);
context.put(STRUTS, new VelocityStrutsUtil(velocityEngine, context, stack, req, res));
VelocityStrutsUtil util = new VelocityStrutsUtil(velocityEngine, context, stack, req, res);
context.put(STRUTS, util);
context.put(OGNL, util); // Deprecated since 6.3.0
return context;
}
@@ -22,7 +22,6 @@ import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.util.ValueStack;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.junit.StrutsJUnit4TestCase;
import org.apache.struts2.views.jsp.ui.OgnlTool;
import org.apache.velocity.context.Context;
import org.apache.velocity.tools.ToolContext;
import org.junit.After;
@@ -95,7 +94,7 @@ public class VelocityManagerTest extends StrutsJUnit4TestCase {
assertNotNull(context);
assertThat(context.get("struts")).isInstanceOf(VelocityStrutsUtil.class);
assertThat(context.get("ognl")).isInstanceOf(OgnlTool.class);
assertThat(context.get("ognl")).isInstanceOf(VelocityStrutsUtil.class); // Deprecated since 6.3.0
assertThat(context.get("stack")).isInstanceOf(ValueStack.class);
assertThat(context.get("request")).isInstanceOf(HttpServletRequest.class);
assertThat(context.get("response")).isInstanceOf(HttpServletResponse.class);