struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [struts] 01/01: WW-5000 Extracts string literals as constants
Date Sun, 03 Jan 2021 08:52:38 GMT
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-5000-constants
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 7ebf8fb8c94e5fa745f00098e6e89a31b261c8fc
Author: Lukasz Lenart <lukaszlenart@apache.org>
AuthorDate: Sat Jan 2 19:08:00 2021 +0100

    WW-5000 Extracts string literals as constants
---
 .../com/opensymphony/xwork2/ObjectFactory.java     |  3 ++-
 .../xwork2/interceptor/ChainingInterceptor.java    | 13 ++++++-----
 .../opensymphony/xwork2/ognl/OgnlValueStack.java   |  2 +-
 .../ognl/accessor/XWorkListPropertyAccessor.java   |  6 -----
 .../java/org/apache/struts2/StrutsConstants.java   |  8 +++++++
 .../accessor/XWorkListPropertyAccessorTest.java    |  2 +-
 .../org/apache/struts2/cdi/CdiObjectFactory.java   |  5 ++--
 .../struts2/views/java/JavaTemplateConstants.java  | 27 ++++++++++++++++++++++
 .../struts2/views/java/JavaTemplateEngine.java     |  4 ++--
 .../interceptor/OValValidationInterceptor.java     |  5 +++-
 10 files changed, 55 insertions(+), 20 deletions(-)

diff --git a/core/src/main/java/com/opensymphony/xwork2/ObjectFactory.java b/core/src/main/java/com/opensymphony/xwork2/ObjectFactory.java
index 0d9f6c7..14e8830 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ObjectFactory.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ObjectFactory.java
@@ -31,6 +31,7 @@ import com.opensymphony.xwork2.util.ClassLoaderUtil;
 import com.opensymphony.xwork2.validator.Validator;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
+import org.apache.struts2.StrutsConstants;
 
 import java.io.Serializable;
 import java.util.Map;
@@ -68,7 +69,7 @@ public class ObjectFactory implements Serializable {
         this.container = container;
     }
 
-    @Inject(value="objectFactory.classloader", required=false)
+    @Inject(value= StrutsConstants.STRUTS_OBJECT_FACTORY_CLASSLOADER, required=false)
     public void setClassLoader(ClassLoader cl) {
         this.ccl = cl;
     }
diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java
b/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java
index ad99281..31b0075 100644
--- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java
@@ -30,6 +30,7 @@ import com.opensymphony.xwork2.util.ValueStack;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.LogManager;
 import com.opensymphony.xwork2.util.reflection.ReflectionProvider;
+import org.apache.struts2.StrutsConstants;
 
 import java.util.*;
 
@@ -59,9 +60,9 @@ import java.util.*;
  * </p>
  *
  * <ul>
- * <li>struts.xwork.chaining.copyErrors - set to true to copy Action Errors</li>
- * <li>struts.xwork.chaining.copyFieldErrors - set to true to copy Field Errors</li>
- * <li>struts.xwork.chaining.copyMessages - set to true to copy Action Messages</li>
+ * <li>struts.chaining.copyErrors - set to true to copy Action Errors</li>
+ * <li>struts.chaining.copyFieldErrors - set to true to copy Field Errors</li>
+ * <li>struts.chaining.copyMessages - set to true to copy Action Messages</li>
  * </ul>
  *
  * <p>
@@ -135,17 +136,17 @@ public class ChainingInterceptor extends AbstractInterceptor {
         this.reflectionProvider = prov;
     }
 
-    @Inject(value = "struts.xwork.chaining.copyErrors", required = false)
+    @Inject(value = StrutsConstants.STRUTS_CHAINING_COPY_ERRORS, required = false)
     public void setCopyErrors(String copyErrors) {
         this.copyErrors = "true".equalsIgnoreCase(copyErrors);
     }
 
-    @Inject(value = "struts.xwork.chaining.copyFieldErrors", required = false)
+    @Inject(value = StrutsConstants.STRUTS_CHAINING_COPY_FIELD_ERRORS, required = false)
     public void setCopyFieldErrors(String copyFieldErrors) {
         this.copyFieldErrors = "true".equalsIgnoreCase(copyFieldErrors);
     }
 
-    @Inject(value = "struts.xwork.chaining.copyMessages", required = false)
+    @Inject(value = StrutsConstants.STRUTS_CHAINING_COPY_MESSAGES, required = false)
     public void setCopyMessages(String copyMessages) {
         this.copyMessages = "true".equalsIgnoreCase(copyMessages);
     }
diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java
index 036407b..3d34954 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java
@@ -105,7 +105,7 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS
         this.devMode = BooleanUtils.toBoolean(mode);
     }
 
-    @Inject(value = "logMissingProperties", required = false)
+    @Inject(value = StrutsConstants.LOG_MISSING_PROPERTIES, required = false)
     protected void setLogMissingProperties(String logMissingProperties) {
         this.logMissingProperties = BooleanUtils.toBoolean(logMissingProperties);
     }
diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkListPropertyAccessor.java
b/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkListPropertyAccessor.java
index 6f3a682..ece1a92 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkListPropertyAccessor.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkListPropertyAccessor.java
@@ -51,12 +51,6 @@ public class XWorkListPropertyAccessor extends ListPropertyAccessor {
     private OgnlUtil ognlUtil;
     private int autoGrowCollectionLimit = 255;
 
-    @Deprecated()
-    @Inject(value = "xwork.autoGrowCollectionLimit", required = false)
-    public void setDeprecatedAutoGrowCollectionLimit(String value) {
-        this.autoGrowCollectionLimit = Integer.valueOf(value);
-    }
-    
     @Inject(value = StrutsConstants.STRUTS_OGNL_AUTO_GROWTH_COLLECTION_LIMIT, required =
false)
     public void setAutoGrowCollectionLimit(String value) {
         this.autoGrowCollectionLimit = Integer.parseInt(value);
diff --git a/core/src/main/java/org/apache/struts2/StrutsConstants.java b/core/src/main/java/org/apache/struts2/StrutsConstants.java
index 45b44a6..e6ab1f7 100644
--- a/core/src/main/java/org/apache/struts2/StrutsConstants.java
+++ b/core/src/main/java/org/apache/struts2/StrutsConstants.java
@@ -29,6 +29,9 @@ public final class StrutsConstants {
     /** Whether Struts is in development mode or not */
     public static final String STRUTS_DEVMODE = "struts.devMode";
 
+    /** Logs missing properties when setting values on an action **/
+    public static final String LOG_MISSING_PROPERTIES = "logMissingProperties";
+
     /** Whether the localization messages should automatically be reloaded */
     public static final String STRUTS_I18N_RELOAD = "struts.i18n.reload";
 
@@ -346,4 +349,9 @@ public final class StrutsConstants {
 
     /** See {@link com.opensymphony.xwork2.config.impl.AbstractMatcher#appendNamedParameters
*/
     public static final String STRUTS_MATCHER_APPEND_NAMED_PARAMETERS = "struts.matcher.appendNamedParameters";
+
+    public static final String STRUTS_CHAINING_COPY_ERRORS = "struts.chaining.copyErrors";
+    public static final String STRUTS_CHAINING_COPY_FIELD_ERRORS = "struts.chaining.copyFieldErrors";
+    public static final String STRUTS_CHAINING_COPY_MESSAGES = "struts.chaining.copyMessages";
+    public static final String STRUTS_OBJECT_FACTORY_CLASSLOADER = "struts.objectFactory.classloader";
 }
diff --git a/core/src/test/java/com/opensymphony/xwork2/ognl/accessor/XWorkListPropertyAccessorTest.java
b/core/src/test/java/com/opensymphony/xwork2/ognl/accessor/XWorkListPropertyAccessorTest.java
index 542efda..df5ea4b 100644
--- a/core/src/test/java/com/opensymphony/xwork2/ognl/accessor/XWorkListPropertyAccessorTest.java
+++ b/core/src/test/java/com/opensymphony/xwork2/ognl/accessor/XWorkListPropertyAccessorTest.java
@@ -85,7 +85,7 @@ public class XWorkListPropertyAccessorTest extends XWorkTestCase {
 
     public void testDeprecatedAutoGrowCollectionLimit() {
         PropertyAccessor accessor = container.getInstance(PropertyAccessor.class, ArrayList.class.getName());
-        ((XWorkListPropertyAccessor) accessor).setDeprecatedAutoGrowCollectionLimit("2");
+        ((XWorkListPropertyAccessor) accessor).setAutoGrowCollectionLimit("2");
 
         List<String> myList = new ArrayList<>();
         ListHolder listHolder = new ListHolder();
diff --git a/plugins/cdi/src/main/java/org/apache/struts2/cdi/CdiObjectFactory.java b/plugins/cdi/src/main/java/org/apache/struts2/cdi/CdiObjectFactory.java
index 72272cb..31a2766 100644
--- a/plugins/cdi/src/main/java/org/apache/struts2/cdi/CdiObjectFactory.java
+++ b/plugins/cdi/src/main/java/org/apache/struts2/cdi/CdiObjectFactory.java
@@ -45,7 +45,7 @@ import java.util.concurrent.ConcurrentHashMap;
  */
 public class CdiObjectFactory extends ObjectFactory {
 
-    private static final Logger LOG = LogManager.getLogger(CdiObjectFactory.class);
+	private static final Logger LOG = LogManager.getLogger(CdiObjectFactory.class);
 
     /**
      * The key under which the BeanManager can be found according to CDI API docs
@@ -60,10 +60,11 @@ public class CdiObjectFactory extends ObjectFactory {
 	 */
 	public static final String CDI_JNDIKEY_BEANMANAGER_COMP_ENV = "java:comp/env/BeanManager";
 
+	public static final String STRUTS_OBJECT_FACTORY_CDI_JNDI_KEY = "struts.objectFactory.cdi.jndiKey";
 
 	private String jndiKey;
 
-	@Inject(value = "struts.objectFactory.cdi.jndiKey", required = false)
+	@Inject(value = STRUTS_OBJECT_FACTORY_CDI_JNDI_KEY, required = false)
 	public void setJndiKey( String jndiKey ) {
 		this.jndiKey = jndiKey;
 	}
diff --git a/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/JavaTemplateConstants.java
b/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/JavaTemplateConstants.java
new file mode 100644
index 0000000..8001c83
--- /dev/null
+++ b/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/JavaTemplateConstants.java
@@ -0,0 +1,27 @@
+/*
+ * 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.java;
+
+public class JavaTemplateConstants {
+
+    public static final String STRUTS_JAVATEMPLATES_DEFAULT_TEMPLATE_TYPE = "struts.javatemplates.defaultTemplateType";
+
+    public static final String STRUTS_JAVATEMPLATES_CUSTOM_THEMES = "struts.javatemplates.customThemes";
+
+}
diff --git a/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/JavaTemplateEngine.java
b/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/JavaTemplateEngine.java
index 67bb9b3..dea448c 100644
--- a/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/JavaTemplateEngine.java
+++ b/plugins/javatemplates/src/main/java/org/apache/struts2/views/java/JavaTemplateEngine.java
@@ -110,7 +110,7 @@ public class JavaTemplateEngine extends BaseTemplateEngine {
      *
      * @param themeClasses a comma delimited list of custom theme class names
      */
-    @Inject(value = "struts.javatemplates.customThemes", required = false)
+    @Inject(value = JavaTemplateConstants.STRUTS_JAVATEMPLATES_CUSTOM_THEMES, required =
false)
     public void setThemeClasses(String themeClasses) {
         StringTokenizer customThemes = new StringTokenizer(themeClasses, ",");
         while (customThemes.hasMoreTokens()) {
@@ -135,7 +135,7 @@ public class JavaTemplateEngine extends BaseTemplateEngine {
      *
      * @param defaultTemplateTheme the struts default theme
      */
-    @Inject(value = "struts.javatemplates.defaultTemplateType", required = false)
+    @Inject(value = JavaTemplateConstants.STRUTS_JAVATEMPLATES_DEFAULT_TEMPLATE_TYPE, required
= false)
     public void setDefaultTemplateType(String defaultTemplateTheme) {
         // Make sure we don't set ourself as default for race condition
         if (defaultTemplateTheme != null && !defaultTemplateTheme.equalsIgnoreCase(getSuffix()))
{
diff --git a/plugins/oval/src/main/java/org/apache/struts2/oval/interceptor/OValValidationInterceptor.java
b/plugins/oval/src/main/java/org/apache/struts2/oval/interceptor/OValValidationInterceptor.java
index e6cf603..58f1fd2 100644
--- a/plugins/oval/src/main/java/org/apache/struts2/oval/interceptor/OValValidationInterceptor.java
+++ b/plugins/oval/src/main/java/org/apache/struts2/oval/interceptor/OValValidationInterceptor.java
@@ -55,6 +55,9 @@ import java.util.Map;
  This interceptor provides validation using the OVal validation framework
  */
 public class OValValidationInterceptor extends MethodFilterInterceptor {
+
+    public static final String STRUTS_OVAL_VALIDATE_JPAANNOTATIONS = "struts.oval.validateJPAAnnotations";
+
     private static final Logger LOG = LogManager.getLogger(OValValidationInterceptor.class);
 
     protected final static String VALIDATE_PREFIX = "validate";
@@ -85,7 +88,7 @@ public class OValValidationInterceptor extends MethodFilterInterceptor {
     /**
      * Enable OVal support for JPA
      */
-    @Inject(value = "struts.oval.validateJPAAnnotations")
+    @Inject(value = STRUTS_OVAL_VALIDATE_JPAANNOTATIONS)
     public void setValidateJPAAnnotations(String validateJPAAnnotations) {
         this.validateJPAAnnotations = Boolean.parseBoolean(validateJPAAnnotations);
     }


Mime
View raw message