WW-5338 Removes deprecated OgnTool

This commit is contained in:
Lukasz Lenart
2023-10-04 09:46:40 +02:00
parent 248bc72144
commit debcb541e3
5 changed files with 15 additions and 89 deletions
@@ -18,13 +18,10 @@
*/
package org.apache.struts2.util;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.ognl.OgnlUtil;
import com.opensymphony.xwork2.util.ClassLoaderUtil;
import com.opensymphony.xwork2.util.TextParseUtil;
import com.opensymphony.xwork2.util.ValueStack;
import ognl.OgnlException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.StrutsException;
@@ -62,7 +59,6 @@ public class StrutsUtil {
protected HttpServletRequest request;
protected HttpServletResponse response;
protected Map<String, Class<?>> classes = new HashMap<>();
protected OgnlUtil ognl;
protected ValueStack stack;
private final UrlHelper urlHelper;
@@ -72,7 +68,6 @@ public class StrutsUtil {
this.stack = stack;
this.request = request;
this.response = response;
this.ognl = stack.getActionContext().getContainer().getInstance(OgnlUtil.class);
this.urlHelper = stack.getActionContext().getContainer().getInstance(UrlHelper.class);
this.objectFactory = stack.getActionContext().getContainer().getInstance(ObjectFactory.class);
}
@@ -125,12 +120,10 @@ public class StrutsUtil {
public Object findValue(String expr, Object context) {
try {
return ognl.getValue(expr, ActionContext.getContext().getContextMap(), context);
} catch (OgnlException e) {
if (e.getReason() instanceof SecurityException) {
LOG.error(format("Could not evaluate this expression due to security constraints: [{0}]", expr), e);
}
return null;
stack.push(context);
return stack.findValue(expr, true);
} finally {
stack.pop();
}
}
@@ -33,7 +33,6 @@ import freemarker.template.TemplateModelException;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsStatics;
import org.apache.struts2.result.StrutsResultSupport;
@@ -207,7 +206,7 @@ public class FreemarkerResult extends StrutsResultSupport {
* @throws TemplateException in case of freemarker configuration errors
*/
protected Configuration getConfiguration() throws TemplateException {
return freemarkerManager.getConfiguration(ServletActionContext.getServletContext());
return freemarkerManager.getConfiguration(ActionContext.getContext().getServletContext());
}
/**
@@ -244,7 +243,7 @@ public class FreemarkerResult extends StrutsResultSupport {
if (writer != null) {
return writer;
}
return ServletActionContext.getResponse().getWriter();
return ActionContext.getContext().getServletResponse().getWriter();
}
/**
@@ -261,7 +260,6 @@ public class FreemarkerResult extends StrutsResultSupport {
* <li>request - the HttpServletRequst object for direct access
* <li>response - the HttpServletResponse object for direct access
* <li>stack - the OgnLValueStack instance for direct access
* <li>ognl - the instance of the OgnlTool
* <li>action - the action itself
* <li>exception - optional : the JSP or Servlet exception as per the servlet spec (for JSP Exception pages)
* <li>struts - instance of the StrutsUtil class
@@ -271,9 +269,9 @@ public class FreemarkerResult extends StrutsResultSupport {
* @throws TemplateModelException in case of errors during creating the model
*/
protected TemplateModel createModel() throws TemplateModelException {
ServletContext servletContext = ServletActionContext.getServletContext();
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
ServletContext servletContext = ActionContext.getContext().getServletContext();
HttpServletRequest request = ActionContext.getContext().getServletRequest();
HttpServletResponse response = ActionContext.getContext().getServletResponse();
ValueStack stack = ActionContext.getContext().getValueStack();
Object action = null;
@@ -321,7 +319,7 @@ public class FreemarkerResult extends StrutsResultSupport {
protected boolean preTemplateProcess(Template template, TemplateModel model) throws IOException {
Object attrContentType = template.getCustomAttribute("content_type");
HttpServletResponse response = ServletActionContext.getResponse();
HttpServletResponse response = ActionContext.getContext().getServletResponse();
if (response.getContentType() == null) {
if (attrContentType != null) {
response.setContentType(attrContentType.toString());
@@ -349,7 +347,7 @@ public class FreemarkerResult extends StrutsResultSupport {
}
private boolean isInsideActionTag() {
Object attribute = ServletActionContext.getRequest().getAttribute(StrutsStatics.STRUTS_ACTION_TAG_INVOCATION);
Object attribute = ActionContext.getContext().getServletRequest().getAttribute(StrutsStatics.STRUTS_ACTION_TAG_INVOCATION);
return (Boolean) ObjectUtils.defaultIfNull(attribute, Boolean.FALSE);
}
@@ -1,60 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.struts2.views.jsp.ui;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.ognl.OgnlUtil;
import ognl.OgnlException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* @deprecated since 6.3.0. Use {@link org.apache.struts2.util.StrutsUtil} instead.
*/
@Deprecated
public class OgnlTool {
private static final Logger LOG = LogManager.getLogger(OgnlTool.class);
private OgnlUtil ognlUtil;
public OgnlTool() {
}
@Inject
public void setOgnlUtil(OgnlUtil ognlUtil) {
this.ognlUtil = ognlUtil;
}
/**
* @deprecated since 6.3.0. Use {@link org.apache.struts2.util.StrutsUtil#findValue(String, Object)} instead.
*/
@Deprecated
public Object findValue(String expr, Object context) {
try {
return ognlUtil.getValue(expr, ActionContext.getContext().getContextMap(), context);
} catch (OgnlException e) {
if (e.getReason() instanceof SecurityException) {
LOG.error("Could not evaluate this expression due to security constraints: [{}]", expr, e);
}
return null;
}
}
}
-3
View File
@@ -200,9 +200,6 @@
<bean type="ognl.MethodAccessor" name="com.opensymphony.xwork2.util.CompoundRoot"
class="com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor"/>
<!-- Deprecated since 6.3.0, inject OgnlUtil directly instead, or use StrutsUtil -->
<bean class="org.apache.struts2.views.jsp.ui.OgnlTool"/>
<bean type="org.apache.struts2.dispatcher.StaticContentLoader"
class="org.apache.struts2.dispatcher.DefaultStaticContentLoader" name="struts"/>
<bean type="com.opensymphony.xwork2.UnknownHandlerManager"
@@ -71,7 +71,7 @@ public class PortletFreemarkerResult extends StrutsResultSupport {
public PortletFreemarkerResult(String location) {
super(location);
}
@Inject
public void setFreemarkerManager(FreemarkerManager mgr) {
this.freemarkerManager = mgr;
@@ -157,7 +157,7 @@ public class PortletFreemarkerResult extends StrutsResultSupport {
}
}
}
private void executeResourceResult(String location, ActionInvocation invocation)
throws TemplateException, IOException, PortletException {
this.location = location;
@@ -243,7 +243,6 @@ public class PortletFreemarkerResult extends StrutsResultSupport {
* <li>request - the HttpServletRequst object for direct access
* <li>response - the HttpServletResponse object for direct access
* <li>stack - the OgnLValueStack instance for direct access
* <li>ognl - the instance of the OgnlTool
* <li>action - the action itself
* <li>exception - optional : the JSP or Servlet exception as per the
* servlet spec (for JSP Exception pages)
@@ -255,11 +254,10 @@ public class PortletFreemarkerResult extends StrutsResultSupport {
* @throws TemplateModelException in case of template model errors
*/
protected TemplateModel createModel() throws TemplateModelException {
ServletContext servletContext = ServletActionContext
.getServletContext();
ServletContext servletContext = ServletActionContext.getServletContext();
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
ValueStack stack = ServletActionContext.getContext().getValueStack();
ValueStack stack = ServletActionContext.getActionContext().getValueStack();
return freemarkerManager.buildTemplateModel(stack, invocation.getAction(), servletContext, request, response, wrapper);
}