Skip to content

Commit

Permalink
WW-5000 Extracts string literals as constants
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed Jan 3, 2021
1 parent dcc53ae commit 1775e0e
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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;
Expand Down Expand Up @@ -68,7 +69,7 @@ public void setContainer(Container container) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ protected Container createBootstrapContainer(List<ContainerProvider> providers)
builder.factory(ValueSubstitutor.class, EnvsValueSubstitutor.class, Scope.SINGLETON);

builder.constant(StrutsConstants.STRUTS_DEVMODE, "false");
builder.constant(StrutsConstants.STRUTS_LOG_MISSING_PROPERTIES, "false");
builder.constant(StrutsConstants.STRUTS_OGNL_LOG_MISSING_PROPERTIES, "false");
builder.constant(StrutsConstants.STRUTS_ENABLE_OGNL_EVAL_EXPRESSION, "false");
builder.constant(StrutsConstants.STRUTS_ENABLE_OGNL_EXPRESSION_CACHE, "true");
builder.constant(StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD, "false");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public void register(ContainerBuilder builder, LocatableProperties props)
props.setProperty(StrutsConstants.STRUTS_ENABLE_DYNAMIC_METHOD_INVOCATION, Boolean.FALSE.toString());
props.setProperty(StrutsConstants.STRUTS_I18N_RELOAD, Boolean.FALSE.toString());
props.setProperty(StrutsConstants.STRUTS_DEVMODE, Boolean.FALSE.toString());
props.setProperty(StrutsConstants.STRUTS_LOG_MISSING_PROPERTIES, Boolean.FALSE.toString());
props.setProperty(StrutsConstants.STRUTS_OGNL_LOG_MISSING_PROPERTIES, Boolean.FALSE.toString());
props.setProperty(StrutsConstants.STRUTS_ENABLE_OGNL_EXPRESSION_CACHE, Boolean.TRUE.toString());
props.setProperty(StrutsConstants.STRUTS_ENABLE_OGNL_EVAL_EXPRESSION, Boolean.FALSE.toString());
props.setProperty(StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD, Boolean.FALSE.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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.*;

Expand Down Expand Up @@ -59,9 +60,9 @@
* </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>
Expand Down Expand Up @@ -135,17 +136,17 @@ public void setReflectionProvider(ReflectionProvider prov) {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected void setDevMode(String mode) {
this.devMode = BooleanUtils.toBoolean(mode);
}

@Inject(value = "logMissingProperties", required = false)
@Inject(value = StrutsConstants.STRUTS_OGNL_LOG_MISSING_PROPERTIES, required = false)
protected void setLogMissingProperties(String logMissingProperties) {
this.logMissingProperties = BooleanUtils.toBoolean(logMissingProperties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion core/src/main/java/org/apache/struts2/StrutsConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public final class StrutsConstants {
public static final String STRUTS_EL_THROW_EXCEPTION = "struts.el.throwExceptionOnFailure";

/** Logs properties that are not found (very verbose) */
public static final String STRUTS_LOG_MISSING_PROPERTIES = "struts.ognl.logMissingProperties";
public static final String STRUTS_OGNL_LOG_MISSING_PROPERTIES = "struts.ognl.logMissingProperties";

/** Enables caching of parsed OGNL expressions */
public static final String STRUTS_ENABLE_OGNL_EXPRESSION_CACHE = "struts.ognl.enableExpressionCache";
Expand Down Expand Up @@ -346,4 +346,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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public Map<String, String> getAllAsStringsMap() {
map.put(StrutsConstants.STRUTS_STATIC_CONTENT_LOADER, beanConfToString(staticContentLoader));
map.put(StrutsConstants.STRUTS_UNKNOWN_HANDLER_MANAGER, beanConfToString(unknownHandlerManager));
map.put(StrutsConstants.STRUTS_EL_THROW_EXCEPTION, Objects.toString(elThrowExceptionOnFailure, null));
map.put(StrutsConstants.STRUTS_LOG_MISSING_PROPERTIES, Objects.toString(ognlLogMissingProperties, null));
map.put(StrutsConstants.STRUTS_OGNL_LOG_MISSING_PROPERTIES, Objects.toString(ognlLogMissingProperties, null));
map.put(StrutsConstants.STRUTS_ENABLE_OGNL_EXPRESSION_CACHE, Objects.toString(ognlEnableExpressionCache, null));
map.put(StrutsConstants.STRUTS_ENABLE_OGNL_EVAL_EXPRESSION, Objects.toString(ognlEnableOGNLEvalExpression, null));
map.put(StrutsConstants.STRUTS_DISABLE_REQUEST_ATTRIBUTE_VALUE_STACK_LOOKUP, Objects.toString(disableRequestAttributeValueStackLookup, null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void testAutoGrowthCollectionLimit() {

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
*/
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
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public Theme get(String name) {
*
* @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()) {
Expand All @@ -135,7 +135,7 @@ public void setThemeClasses(String themeClasses) {
*
* @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())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
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";
Expand Down Expand Up @@ -85,7 +88,7 @@ public void setTextProviderFactory(TextProviderFactory textProviderFactory) {
/**
* 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);
}
Expand Down

0 comments on commit 1775e0e

Please sign in to comment.