You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2023/04/09 10:00:28 UTC
[struts] 01/01: WW-5280 Cleans up NoParameters interfaces
This is an automated email from the ASF dual-hosted git repository.
lukaszlenart pushed a commit to branch WW-5280-no-params
in repository https://gitbox.apache.org/repos/asf/struts.git
commit 73eafddd73ab20bfae8ec7c4bacf49bd0c5725ab
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sun Apr 9 12:00:20 2023 +0200
WW-5280 Cleans up NoParameters interfaces
---
.../xwork2/interceptor/NoParameters.java | 3 +-
.../interceptor/ParameterRemoverInterceptor.java | 152 +++++++++------------
.../{interceptor => action}/NoParameters.java | 2 +-
3 files changed, 70 insertions(+), 87 deletions(-)
diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/NoParameters.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/NoParameters.java
index 6c918d032..4657380ea 100644
--- a/core/src/main/java/com/opensymphony/xwork2/interceptor/NoParameters.java
+++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/NoParameters.java
@@ -30,7 +30,8 @@ package com.opensymphony.xwork2.interceptor;
* parameters cannot be set by malicious users.
* </p>
*
- * @author Dick Zetterberg (dick@transitor.se)
+ * @deprecated since Struts 6.2.0, use {@link org.apache.struts2.action.NoParameters}
*/
+@Deprecated
public interface NoParameters {
}
diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ParameterRemoverInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/ParameterRemoverInterceptor.java
index 1003be900..c0f83765c 100644
--- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ParameterRemoverInterceptor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ParameterRemoverInterceptor.java
@@ -23,120 +23,102 @@ import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.util.TextParseUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import org.apache.struts2.dispatcher.Parameter;
+import org.apache.struts2.action.NoParameters;
import org.apache.struts2.dispatcher.HttpParameters;
+import org.apache.struts2.dispatcher.Parameter;
import java.util.Collections;
import java.util.Set;
/**
- * <!-- START SNIPPET: description -->
* This is a simple XWork interceptor that allows parameters (matching
- * one of the paramNames attribute csv value) to be
+ * one of the paramNames attribute csv value) to be
* removed from the parameter map if they match a certain value
- * (matching one of the paramValues attribute csv value), before they
- * are set on the action. A typical usage would be to want a dropdown/select
- * to map onto a boolean value on an action. The select had the options
- * none, yes and no with values -1, true and false. The true and false would
- * map across correctly. However the -1 would be set to false.
- * This was not desired as one might needed the value on the action to stay null.
- * This interceptor fixes this by preventing the parameter from ever reaching
+ * (matching one of the paramValues attribute csv value), before they
+ * are set on the action. A typical usage would be to want a dropdown/select
+ * to map onto a boolean value on an action. The select had the options
+ * none, yes and no with values -1, true and false. The true and false would
+ * map across correctly. However the -1 would be set to false.
+ * This was not desired as one might needed the value on the action to stay null.
+ * This interceptor fixes this by preventing the parameter from ever reaching
* the action.
- * <!-- END SNIPPET: description -->
- *
- *
- * <!-- START SNIPPET: parameters -->
+ *
* <ul>
- * <li>paramNames - A comma separated value (csv) indicating the parameter name
- * whose param value should be considered that if they match any of the
- * comma separated value (csv) from paramValues attribute, shall be
- * removed from the parameter map such that they will not be applied
- * to the action</li>
- * <li>paramValues - A comma separated value (csv) indicating the parameter value that if
- * matched shall have its parameter be removed from the parameter map
- * such that they will not be applied to the action</li>
+ * <li>paramNames - A comma separated value (csv) indicating the parameter name
+ * whose param value should be considered that if they match any of the
+ * comma separated value (csv) from paramValues attribute, shall be
+ * removed from the parameter map such that they will not be applied
+ * to the action</li>
+ * <li>paramValues - A comma separated value (csv) indicating the parameter value that if
+ * matched shall have its parameter be removed from the parameter map
+ * such that they will not be applied to the action</li>
* </ul>
- * <!-- END SNIPPET: parameters -->
- *
- *
- * <!-- START SNIPPET: extending -->
+ * <p>
* No intended extension point
- * <!-- END SNIPPET: extending -->
- *
+ *
* <pre>
- * <!-- START SNIPPET: example -->
- *
* <action name="sample" class="org.martingilday.Sample">
* <interceptor-ref name="paramRemover">
- * <param name="paramNames">aParam,anotherParam</param>
- * <param name="paramValues">--,-1</param>
+ * <param name="paramNames">aParam,anotherParam</param>
+ * <param name="paramValues">--,-1</param>
* </interceptor-ref>
* <interceptor-ref name="defaultStack" />
* ...
* </action>
- *
- * <!-- END SNIPPET: example -->
* </pre>
- *
- *
- * @author martin.gilday
*/
public class ParameterRemoverInterceptor extends AbstractInterceptor {
- private static final Logger LOG = LogManager.getLogger(ParameterRemoverInterceptor.class);
-
- private static final long serialVersionUID = 1;
+ private static final Logger LOG = LogManager.getLogger(ParameterRemoverInterceptor.class);
- private Set<String> paramNames = Collections.emptySet();
- private Set<String> paramValues = Collections.emptySet();
+ private Set<String> paramNames = Collections.emptySet();
+ private Set<String> paramValues = Collections.emptySet();
-
- /**
- * Decide if the parameter should be removed from the parameter map based on
- * <code>paramNames</code> and <code>paramValues</code>.
- *
- * @see com.opensymphony.xwork2.interceptor.AbstractInterceptor
- */
- @Override
- public String intercept(ActionInvocation invocation) throws Exception {
- if (!(invocation.getAction() instanceof NoParameters)
- && (null != this.paramNames)) {
- ActionContext ac = invocation.getInvocationContext();
- HttpParameters parameters = ac.getParameters();
+ /**
+ * Decide if the parameter should be removed from the parameter map based on
+ * <code>paramNames</code> and <code>paramValues</code>.
+ *
+ * @see com.opensymphony.xwork2.interceptor.AbstractInterceptor
+ */
+ @Override
+ public String intercept(ActionInvocation invocation) throws Exception {
+ if (!(invocation.getAction() instanceof NoParameters)
+ && (null != this.paramNames)) {
+ ActionContext ac = invocation.getInvocationContext();
+ HttpParameters parameters = ac.getParameters();
- if (parameters != null) {
+ if (parameters != null) {
for (String removeName : paramNames) {
- try {
- Parameter parameter = parameters.get(removeName);
- if (parameter.isDefined() && this.paramValues.contains(parameter.getValue())) {
- parameters.remove(removeName);
- }
- } catch (Exception e) {
- LOG.error("Failed to convert parameter to string", e);
- }
+ try {
+ Parameter parameter = parameters.get(removeName);
+ if (parameter.isDefined() && this.paramValues.contains(parameter.getValue())) {
+ parameters.remove(removeName);
+ }
+ } catch (Exception e) {
+ LOG.error("Failed to convert parameter to string", e);
+ }
}
- }
- }
- return invocation.invoke();
- }
+ }
+ }
+ return invocation.invoke();
+ }
- /**
- * Allows <code>paramNames</code> attribute to be set as comma-separated-values (csv).
- *
- * @param paramNames the paramNames to set
- */
- public void setParamNames(String paramNames) {
- this.paramNames = TextParseUtil.commaDelimitedStringToSet(paramNames);
- }
+ /**
+ * Allows <code>paramNames</code> attribute to be set as comma-separated-values (csv).
+ *
+ * @param paramNames the paramNames to set
+ */
+ public void setParamNames(String paramNames) {
+ this.paramNames = TextParseUtil.commaDelimitedStringToSet(paramNames);
+ }
+ /**
+ * Allows <code>paramValues</code> attribute to be set as a comma-separated-values (csv).
+ *
+ * @param paramValues the paramValues to set
+ */
+ public void setParamValues(String paramValues) {
+ this.paramValues = TextParseUtil.commaDelimitedStringToSet(paramValues);
+ }
- /**
- * Allows <code>paramValues</code> attribute to be set as a comma-separated-values (csv).
- *
- * @param paramValues the paramValues to set
- */
- public void setParamValues(String paramValues) {
- this.paramValues = TextParseUtil.commaDelimitedStringToSet(paramValues);
- }
}
-
diff --git a/core/src/main/java/org/apache/struts2/interceptor/NoParameters.java b/core/src/main/java/org/apache/struts2/action/NoParameters.java
similarity index 96%
rename from core/src/main/java/org/apache/struts2/interceptor/NoParameters.java
rename to core/src/main/java/org/apache/struts2/action/NoParameters.java
index c42aa809b..80424a5f0 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/NoParameters.java
+++ b/core/src/main/java/org/apache/struts2/action/NoParameters.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.struts2.interceptor;
+package org.apache.struts2.action;
/**
* This marker interface should be implemented by actions that do not want any parameters set on