Skip to content

Commit

Permalink
WW-5336 Deprecate OGNL in template context
Browse files Browse the repository at this point in the history
  • Loading branch information
kusalk committed Aug 22, 2023
1 parent 12cd92c commit 85e8d81
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
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;
Expand All @@ -48,8 +47,9 @@ public static Map<String, Object> getStandardContext(ValueStack stack, HttpServl
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) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/struts.vm
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
#end

#macro(property $object $property)
$!{ognl.findValue($property, $object)}
$!{struts.findValue($property, $object)}
#end
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
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
*/
Expand Down Expand Up @@ -141,7 +143,9 @@ protected Context buildContext(ValueStack stack, HttpServletRequest req, HttpSer
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
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;
Expand Down Expand Up @@ -95,7 +94,7 @@ public void testCreateContext() {

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);
Expand Down

0 comments on commit 85e8d81

Please sign in to comment.