mirror of
https://github.com/apache/struts.git
synced 2026-08-06 15:17:00 +00:00
WW-5336 Deprecate OGNL in template context
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -33,5 +33,5 @@
|
||||
#end
|
||||
|
||||
#macro(property $object $property)
|
||||
$!{ognl.findValue($property, $object)}
|
||||
$!{struts.findValue($property, $object)}
|
||||
#end
|
||||
|
||||
+5
-1
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user