diff --git a/core/src/main/java/com/opensymphony/xwork2/ActionSupport.java b/core/src/main/java/com/opensymphony/xwork2/ActionSupport.java index 0434469dd..cb1ac4733 100644 --- a/core/src/main/java/com/opensymphony/xwork2/ActionSupport.java +++ b/core/src/main/java/com/opensymphony/xwork2/ActionSupport.java @@ -275,7 +275,7 @@ public class ActionSupport implements Action, Validateable, ValidationAware, Tex */ protected TextProvider getTextProvider() { if (textProvider == null) { - TextProviderFactory tpf = container.inject(TextProviderFactory.class); + TextProviderFactory tpf = container.getInstance(TextProviderFactory.class); textProvider = tpf.createInstance(getClass()); } return textProvider; diff --git a/core/src/main/java/com/opensymphony/xwork2/DefaultLocaleProvider.java b/core/src/main/java/com/opensymphony/xwork2/DefaultLocaleProvider.java index 19c8f5dc2..7fbc2bc38 100644 --- a/core/src/main/java/com/opensymphony/xwork2/DefaultLocaleProvider.java +++ b/core/src/main/java/com/opensymphony/xwork2/DefaultLocaleProvider.java @@ -1,3 +1,18 @@ +/* + * Copyright 2002-2006,2009 The Apache Software Foundation. + * + * Licensed 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 com.opensymphony.xwork2; import com.opensymphony.xwork2.util.DefaultLocalizedTextProvider; diff --git a/core/src/main/java/com/opensymphony/xwork2/StrutsTextProviderFactory.java b/core/src/main/java/com/opensymphony/xwork2/StrutsTextProviderFactory.java new file mode 100644 index 000000000..d398e698f --- /dev/null +++ b/core/src/main/java/com/opensymphony/xwork2/StrutsTextProviderFactory.java @@ -0,0 +1,68 @@ +/* + * Copyright 2002-2007,2009 The Apache Software Foundation. + * + * Licensed 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 com.opensymphony.xwork2; + +import com.opensymphony.xwork2.inject.Inject; + +import java.util.ResourceBundle; + +/** + * This factory enables users to provide and correctly initialize a custom TextProvider. + */ +public class StrutsTextProviderFactory implements TextProviderFactory { + + protected LocaleProviderFactory localeProviderFactory; + protected LocalizedTextProvider localizedTextProvider; + + @Inject + public void setLocaleProviderFactory(LocaleProviderFactory localeProviderFactory) { + this.localeProviderFactory = localeProviderFactory; + } + + @Inject + public void setLocalizedTextProvider(LocalizedTextProvider localizedTextProvider) { + this.localizedTextProvider = localizedTextProvider; + } + + @Override + public TextProvider createInstance(Class clazz) { + TextProvider instance = getTextProvider(clazz); + if (instance instanceof ResourceBundleTextProvider) { + ((ResourceBundleTextProvider) instance).setClazz(clazz); + ((ResourceBundleTextProvider) instance).setLocaleProvider(localeProviderFactory.createLocaleProvider()); + } + return instance; + } + + @Override + public TextProvider createInstance(ResourceBundle bundle) { + TextProvider instance = getTextProvider(bundle); + if (instance instanceof ResourceBundleTextProvider) { + ((ResourceBundleTextProvider) instance).setBundle(bundle); + ((ResourceBundleTextProvider) instance).setLocaleProvider(localeProviderFactory.createLocaleProvider()); + } + return instance; + } + + protected TextProvider getTextProvider(Class clazz) { + return new TextProviderSupport(clazz, localeProviderFactory.createLocaleProvider(), localizedTextProvider); + } + + protected TextProvider getTextProvider(ResourceBundle bundle) { + return new TextProviderSupport(bundle, localeProviderFactory.createLocaleProvider(), localizedTextProvider); + } + +} diff --git a/core/src/main/java/com/opensymphony/xwork2/TextProviderFactory.java b/core/src/main/java/com/opensymphony/xwork2/TextProviderFactory.java index 4d55d6c0a..e9b06238a 100644 --- a/core/src/main/java/com/opensymphony/xwork2/TextProviderFactory.java +++ b/core/src/main/java/com/opensymphony/xwork2/TextProviderFactory.java @@ -1,12 +1,12 @@ /* * Copyright 2002-2007,2009 The Apache Software Foundation. - * + * * Licensed 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. @@ -15,68 +15,12 @@ */ package com.opensymphony.xwork2; -import com.opensymphony.xwork2.inject.Inject; - import java.util.ResourceBundle; -/** - * This factory enables users to provide and correctly initialize a custom TextProvider. - * - * @author Oleg Gorobets - * @author Rene Gielen - */ -public class TextProviderFactory { +public interface TextProviderFactory { - private TextProvider textProvider; - private LocaleProviderFactory localeProviderFactory; - private LocalizedTextProvider localizedTextProvider; + TextProvider createInstance(Class clazz); - @Inject - public void setTextProvider(TextProvider textProvider) { - this.textProvider = textProvider; - } - - @Inject - public void setLocaleProviderFactory(LocaleProviderFactory localeProviderFactory) { - this.localeProviderFactory = localeProviderFactory; - } - - @Inject - public void setLocalizedTextProvider(LocalizedTextProvider localizedTextProvider) { - this.localizedTextProvider = localizedTextProvider; - } - - public TextProvider createInstance(Class clazz) { - TextProvider instance = getTextProvider(clazz); - if (instance instanceof ResourceBundleTextProvider) { - ((ResourceBundleTextProvider) instance).setClazz(clazz); - ((ResourceBundleTextProvider) instance).setLocaleProvider(localeProviderFactory.createLocaleProvider()); - } - return instance; - } - - public TextProvider createInstance(ResourceBundle bundle) { - TextProvider instance = getTextProvider(bundle); - if (instance instanceof ResourceBundleTextProvider) { - ((ResourceBundleTextProvider) instance).setBundle(bundle); - ((ResourceBundleTextProvider) instance).setLocaleProvider(localeProviderFactory.createLocaleProvider()); - } - return instance; - } - - protected TextProvider getTextProvider(Class clazz) { - if (this.textProvider == null) { - return new TextProviderSupport(clazz, localeProviderFactory.createLocaleProvider(), localizedTextProvider); - } else { - return textProvider; - } - } - - private TextProvider getTextProvider(ResourceBundle bundle) { - if (this.textProvider == null) { - return new TextProviderSupport(bundle, localeProviderFactory.createLocaleProvider(), localizedTextProvider); - } - return textProvider; - } + TextProvider createInstance(ResourceBundle bundle); } diff --git a/core/src/main/java/com/opensymphony/xwork2/TextProviderSupport.java b/core/src/main/java/com/opensymphony/xwork2/TextProviderSupport.java index 528a91000..d63291acd 100644 --- a/core/src/main/java/com/opensymphony/xwork2/TextProviderSupport.java +++ b/core/src/main/java/com/opensymphony/xwork2/TextProviderSupport.java @@ -29,16 +29,10 @@ import java.util.*; */ public class TextProviderSupport implements ResourceBundleTextProvider { - private Class clazz; - private LocaleProvider localeProvider; - private ResourceBundle bundle; - private LocalizedTextProvider localizedTextProvider; - - /** - * Default constructor - */ - public TextProviderSupport() { - } + protected Class clazz; + protected LocaleProvider localeProvider; + protected ResourceBundle bundle; + protected LocalizedTextProvider localizedTextProvider; /** * Constructor. diff --git a/core/src/main/java/com/opensymphony/xwork2/config/impl/DefaultConfiguration.java b/core/src/main/java/com/opensymphony/xwork2/config/impl/DefaultConfiguration.java index c7c5a9277..8882a2f4b 100644 --- a/core/src/main/java/com/opensymphony/xwork2/config/impl/DefaultConfiguration.java +++ b/core/src/main/java/com/opensymphony/xwork2/config/impl/DefaultConfiguration.java @@ -245,8 +245,6 @@ public class DefaultConfiguration implements Configuration { builder.factory(ReflectionProvider.class, OgnlReflectionProvider.class, Scope.SINGLETON); builder.factory(ValueStackFactory.class, OgnlValueStackFactory.class, Scope.SINGLETON); - builder.factory(LocalizedTextProvider.class, DefaultLocalizedTextProvider.class, Scope.SINGLETON); - builder.factory(XWorkConverter.class, Scope.SINGLETON); builder.factory(ConversionPropertiesProcessor.class, DefaultConversionPropertiesProcessor.class, Scope.SINGLETON); builder.factory(ConversionFileProcessor.class, DefaultConversionFileProcessor.class, Scope.SINGLETON); @@ -261,11 +259,14 @@ public class DefaultConfiguration implements Configuration { builder.factory(TypeConverter.class, XWorkConstants.NUMBER_CONVERTER, NumberConverter.class, Scope.SINGLETON); builder.factory(TypeConverter.class, XWorkConstants.STRING_CONVERTER, StringConverter.class, Scope.SINGLETON); - builder.factory(TextParser.class, OgnlTextParser.class, Scope.SINGLETON); builder.factory(TextProvider.class, "system", DefaultTextProvider.class, Scope.SINGLETON); - builder.factory(TextProvider.class, TextProviderSupport.class, Scope.SINGLETON); + + builder.factory(LocalizedTextProvider.class, DefaultLocalizedTextProvider.class, Scope.SINGLETON); + builder.factory(TextProviderFactory.class, StrutsTextProviderFactory.class, Scope.SINGLETON); builder.factory(LocaleProviderFactory.class, DefaultLocaleProviderFactory.class, Scope.SINGLETON); + builder.factory(TextParser.class, OgnlTextParser.class, Scope.SINGLETON); + builder.factory(ObjectTypeDeterminer.class, DefaultObjectTypeDeterminer.class, Scope.SINGLETON); builder.factory(PropertyAccessor.class, CompoundRoot.class.getName(), CompoundRootAccessor.class, Scope.SINGLETON); builder.factory(OgnlUtil.class, Scope.SINGLETON); diff --git a/core/src/main/java/com/opensymphony/xwork2/config/providers/XWorkConfigurationProvider.java b/core/src/main/java/com/opensymphony/xwork2/config/providers/XWorkConfigurationProvider.java index 5c912e1fc..1bc698696 100644 --- a/core/src/main/java/com/opensymphony/xwork2/config/providers/XWorkConfigurationProvider.java +++ b/core/src/main/java/com/opensymphony/xwork2/config/providers/XWorkConfigurationProvider.java @@ -4,6 +4,7 @@ import com.opensymphony.xwork2.ActionProxyFactory; import com.opensymphony.xwork2.DefaultActionProxyFactory; import com.opensymphony.xwork2.DefaultLocaleProviderFactory; import com.opensymphony.xwork2.LocaleProviderFactory; +import com.opensymphony.xwork2.StrutsTextProviderFactory; import com.opensymphony.xwork2.TextProviderFactory; import com.opensymphony.xwork2.factory.DefaultUnknownHandlerFactory; import com.opensymphony.xwork2.factory.UnknownHandlerFactory; @@ -12,16 +13,13 @@ import com.opensymphony.xwork2.ognl.accessor.ParameterPropertyAccessor; import com.opensymphony.xwork2.security.AcceptedPatternsChecker; import com.opensymphony.xwork2.security.DefaultAcceptedPatternsChecker; import com.opensymphony.xwork2.security.DefaultExcludedPatternsChecker; -import com.opensymphony.xwork2.DefaultLocaleProvider; import com.opensymphony.xwork2.DefaultTextProvider; import com.opensymphony.xwork2.DefaultUnknownHandlerManager; import com.opensymphony.xwork2.security.ExcludedPatternsChecker; import com.opensymphony.xwork2.FileManager; import com.opensymphony.xwork2.FileManagerFactory; -import com.opensymphony.xwork2.LocaleProvider; import com.opensymphony.xwork2.ObjectFactory; import com.opensymphony.xwork2.TextProvider; -import com.opensymphony.xwork2.TextProviderSupport; import com.opensymphony.xwork2.UnknownHandlerManager; import com.opensymphony.xwork2.XWorkConstants; import com.opensymphony.xwork2.config.Configuration; @@ -183,12 +181,11 @@ public class XWorkConfigurationProvider implements ConfigurationProvider { .factory(ActionValidatorManager.class, AnnotationActionValidatorManager.class, Scope.SINGLETON) .factory(ActionValidatorManager.class, "no-annotations", DefaultActionValidatorManager.class, Scope.SINGLETON) - .factory(TextProviderFactory.class, Scope.SINGLETON) - .factory(LocalizedTextProvider.class, DefaultLocalizedTextProvider.class, Scope.SINGLETON) .factory(TextProvider.class, "system", DefaultTextProvider.class, Scope.SINGLETON) - .factory(TextProvider.class, TextProviderSupport.class, Scope.SINGLETON) - + .factory(LocalizedTextProvider.class, DefaultLocalizedTextProvider.class, Scope.SINGLETON) + .factory(TextProviderFactory.class, StrutsTextProviderFactory.class, Scope.SINGLETON) .factory(LocaleProviderFactory.class, DefaultLocaleProviderFactory.class, Scope.SINGLETON) + .factory(OgnlUtil.class, Scope.SINGLETON) .factory(CollectionConverter.class, Scope.SINGLETON) .factory(ArrayConverter.class, Scope.SINGLETON) diff --git a/core/src/main/java/com/opensymphony/xwork2/validator/DelegatingValidatorContext.java b/core/src/main/java/com/opensymphony/xwork2/validator/DelegatingValidatorContext.java index b8921e916..0e3fe97dd 100644 --- a/core/src/main/java/com/opensymphony/xwork2/validator/DelegatingValidatorContext.java +++ b/core/src/main/java/com/opensymphony/xwork2/validator/DelegatingValidatorContext.java @@ -74,7 +74,7 @@ public class DelegatingValidatorContext implements ValidatorContext { @Deprecated public DelegatingValidatorContext(Class clazz) { localeProvider = new ActionContextLocaleProvider(); - textProvider = new TextProviderFactory().createInstance(clazz); + textProvider = new StrutsTextProviderFactory().createInstance(clazz); validationAware = new LoggingValidationAware(clazz); } diff --git a/core/src/main/java/com/opensymphony/xwork2/validator/validators/ConditionalVisitorFieldValidator.java b/core/src/main/java/com/opensymphony/xwork2/validator/validators/ConditionalVisitorFieldValidator.java index 7e92f3fc3..395269897 100644 --- a/core/src/main/java/com/opensymphony/xwork2/validator/validators/ConditionalVisitorFieldValidator.java +++ b/core/src/main/java/com/opensymphony/xwork2/validator/validators/ConditionalVisitorFieldValidator.java @@ -1,6 +1,8 @@ package com.opensymphony.xwork2.validator.validators; import com.opensymphony.xwork2.validator.ValidationException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** * @@ -29,6 +31,8 @@ import com.opensymphony.xwork2.validator.ValidationException; */ public class ConditionalVisitorFieldValidator extends VisitorFieldValidator { + private static final Logger LOG = LogManager.getLogger(ConditionalVisitorFieldValidator.class); + private String expression; public void setExpression(String expression) { @@ -75,7 +79,7 @@ public class ConditionalVisitorFieldValidator extends VisitorFieldValidator { if ((obj != null) && (obj instanceof Boolean)) { answer = (Boolean) obj; } else { - log.warn("Got result of {} when trying to get Boolean.", obj); + LOG.warn("Got result of {} when trying to get Boolean.", obj); } return answer; diff --git a/core/src/main/java/com/opensymphony/xwork2/validator/validators/ExpressionValidator.java b/core/src/main/java/com/opensymphony/xwork2/validator/validators/ExpressionValidator.java index 6e59af200..f3e3da0e0 100644 --- a/core/src/main/java/com/opensymphony/xwork2/validator/validators/ExpressionValidator.java +++ b/core/src/main/java/com/opensymphony/xwork2/validator/validators/ExpressionValidator.java @@ -16,6 +16,8 @@ package com.opensymphony.xwork2.validator.validators; import com.opensymphony.xwork2.validator.ValidationException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** * @@ -44,6 +46,8 @@ import com.opensymphony.xwork2.validator.ValidationException; */ public class ExpressionValidator extends ValidatorSupport { + private static final Logger LOG = LogManager.getLogger(ExpressionValidator.class); + private String expression; public void setExpression(String expression) { @@ -69,11 +73,11 @@ public class ExpressionValidator extends ValidatorSupport { if ((obj != null) && (obj instanceof Boolean)) { answer = (Boolean) obj; } else { - log.warn("Got result of [{}] when trying to get Boolean.", obj); + LOG.warn("Got result of [{}] when trying to get Boolean.", obj); } if (!answer) { - log.debug("Validation failed on expression [{}] with validated object [{}]", expression, object); + LOG.debug("Validation failed on expression [{}] with validated object [{}]", expression, object); addActionError(object); } } diff --git a/core/src/main/java/com/opensymphony/xwork2/validator/validators/FieldExpressionValidator.java b/core/src/main/java/com/opensymphony/xwork2/validator/validators/FieldExpressionValidator.java index 12dd7c575..e1f5618a2 100644 --- a/core/src/main/java/com/opensymphony/xwork2/validator/validators/FieldExpressionValidator.java +++ b/core/src/main/java/com/opensymphony/xwork2/validator/validators/FieldExpressionValidator.java @@ -16,6 +16,8 @@ package com.opensymphony.xwork2.validator.validators; import com.opensymphony.xwork2.validator.ValidationException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** @@ -55,6 +57,8 @@ import com.opensymphony.xwork2.validator.ValidationException; */ public class FieldExpressionValidator extends FieldValidatorSupport { + private static final Logger LOG = LogManager.getLogger(FieldExpressionValidator.class); + private String expression; public void setExpression(String expression) { @@ -82,10 +86,10 @@ public class FieldExpressionValidator extends FieldValidatorSupport { if ((obj != null) && (obj instanceof Boolean)) { answer = (Boolean) obj; } else { - log.warn("Got result of {} when trying to get Boolean.", obj); + LOG.warn("Got result of {} when trying to get Boolean.", obj); } - if (!answer.booleanValue()) { + if (!answer) { addFieldError(fieldName, object); } } diff --git a/core/src/main/java/com/opensymphony/xwork2/validator/validators/ValidatorSupport.java b/core/src/main/java/com/opensymphony/xwork2/validator/validators/ValidatorSupport.java index 3cfdb4bad..2173a2f9b 100644 --- a/core/src/main/java/com/opensymphony/xwork2/validator/validators/ValidatorSupport.java +++ b/core/src/main/java/com/opensymphony/xwork2/validator/validators/ValidatorSupport.java @@ -37,16 +37,16 @@ import java.util.List; */ public abstract class ValidatorSupport implements Validator, ShortCircuitableValidator { - protected final Logger log = LogManager.getLogger(this.getClass()); + private static final Logger LOG = LogManager.getLogger(ValidatorSupport.class); - protected String defaultMessage = ""; - protected String messageKey; private ValidatorContext validatorContext; private boolean shortCircuit; private String type; private String[] messageParameters; - protected ValueStack stack; + protected String defaultMessage = ""; + protected String messageKey; + protected ValueStack stack; protected TextProviderFactory textProviderFactory; @Inject @@ -97,7 +97,7 @@ public abstract class ValidatorSupport implements Validator, ShortCircuitableVal } catch (Exception e) { // if there's an exception in parsing, we'll just treat the expression itself as the // parameter - log.warn("exception while parsing message parameter [{}]", messageParameter, e); + LOG.warn("exception while parsing message parameter [{}]", messageParameter, e); parsedMessageParameters.add(messageParameter); } } diff --git a/core/src/main/java/com/opensymphony/xwork2/validator/validators/VisitorFieldValidator.java b/core/src/main/java/com/opensymphony/xwork2/validator/validators/VisitorFieldValidator.java index 8fd62a63a..ce8731663 100644 --- a/core/src/main/java/com/opensymphony/xwork2/validator/validators/VisitorFieldValidator.java +++ b/core/src/main/java/com/opensymphony/xwork2/validator/validators/VisitorFieldValidator.java @@ -24,6 +24,8 @@ import com.opensymphony.xwork2.validator.ActionValidatorManager; import com.opensymphony.xwork2.validator.DelegatingValidatorContext; import com.opensymphony.xwork2.validator.ValidationException; import com.opensymphony.xwork2.validator.ValidatorContext; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Collection; import java.util.LinkedList; @@ -85,6 +87,8 @@ import java.util.List; */ public class VisitorFieldValidator extends FieldValidatorSupport { + private static final Logger LOG = LogManager.getLogger(VisitorFieldValidator.class); + private String context; private boolean appendPrefix = true; private ActionValidatorManager actionValidatorManager; @@ -125,7 +129,7 @@ public class VisitorFieldValidator extends FieldValidatorSupport { String fieldName = getFieldName(); Object value = this.getFieldValue(fieldName, object); if (value == null) { - log.warn("The visited object is null, VisitorValidator will not be able to handle validation properly. Please make sure the visited object is not null for VisitorValidator to function properly"); + LOG.warn("The visited object is null, VisitorValidator will not be able to handle validation properly. Please make sure the visited object is not null for VisitorValidator to function properly"); return; } ValueStack stack = ActionContext.getContext().getValueStack(); diff --git a/core/src/main/java/org/apache/struts2/components/I18n.java b/core/src/main/java/org/apache/struts2/components/I18n.java index 89e38bb88..497fff854 100644 --- a/core/src/main/java/org/apache/struts2/components/I18n.java +++ b/core/src/main/java/org/apache/struts2/components/I18n.java @@ -25,16 +25,16 @@ import java.io.Writer; import java.util.ResourceBundle; import com.opensymphony.xwork2.LocaleProviderFactory; +import com.opensymphony.xwork2.LocalizedTextProvider; +import com.opensymphony.xwork2.TextProviderFactory; import org.apache.struts2.views.annotations.StrutsTag; import org.apache.struts2.views.annotations.StrutsTagAttribute; import org.apache.struts2.StrutsException; import com.opensymphony.xwork2.LocaleProvider; import com.opensymphony.xwork2.TextProvider; -import com.opensymphony.xwork2.TextProviderFactory; import com.opensymphony.xwork2.inject.Container; import com.opensymphony.xwork2.inject.Inject; -import com.opensymphony.xwork2.util.DefaultLocalizedTextProvider; import com.opensymphony.xwork2.util.ValueStack; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -90,28 +90,35 @@ public class I18n extends Component { protected boolean pushed; protected String name; - protected Container container; + + private LocalizedTextProvider localizedTextProvider; private TextProvider textProvider; private TextProvider defaultTextProvider; - private LocaleProvider localeProvider; + private LocaleProviderFactory localeProviderFactory; + private TextProviderFactory textProviderFactory; public I18n(ValueStack stack) { super(stack); } - - @Inject - public void setContainer(Container container) { - this.container = container; - } @Inject + public void setLocalizedTextProvider(LocalizedTextProvider localizedTextProvider) { + this.localizedTextProvider = localizedTextProvider; + } + + @Inject("system") public void setTextProvider(TextProvider textProvider) { this.defaultTextProvider = textProvider; } + @Inject + public void setTextProviderFactory(TextProviderFactory textProviderFactory) { + this.textProviderFactory = textProviderFactory; + } + @Inject public void setLocaleProviderFactory(LocaleProviderFactory localeProviderFactory) { - this.localeProvider = localeProviderFactory.createLocaleProvider(); + this.localeProviderFactory = localeProviderFactory; } public boolean start(Writer writer) { @@ -122,12 +129,12 @@ public class I18n extends Component { ResourceBundle bundle = defaultTextProvider.getTexts(name); if (bundle == null) { - bundle = container.getInstance(DefaultLocalizedTextProvider.class).findResourceBundle(name, localeProvider.getLocale()); + LocaleProvider localeProvider = localeProviderFactory.createLocaleProvider(); + bundle = localizedTextProvider.findResourceBundle(name, localeProvider.getLocale()); } if (bundle != null) { - TextProviderFactory tpf = container.inject(TextProviderFactory.class); - textProvider = tpf.createInstance(bundle); + textProvider = textProviderFactory.createInstance(bundle); getStack().push(textProvider); pushed = true; } diff --git a/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java index b00f2e3a2..a392813b0 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java @@ -446,7 +446,7 @@ public class FileUploadInterceptor extends AbstractInterceptor { } private TextProvider getTextProvider(Object action) { - TextProviderFactory tpf = container.inject(TextProviderFactory.class); + TextProviderFactory tpf = container.getInstance(TextProviderFactory.class); return tpf.createInstance(action.getClass()); } diff --git a/core/src/main/resources/struts-default.xml b/core/src/main/resources/struts-default.xml index 3a4f6ee9a..d66654136 100644 --- a/core/src/main/resources/struts-default.xml +++ b/core/src/main/resources/struts-default.xml @@ -130,9 +130,9 @@ - + - + @@ -142,7 +142,6 @@ - diff --git a/core/src/test/java/com/opensymphony/xwork2/CompositeTextProviderTest.java b/core/src/test/java/com/opensymphony/xwork2/CompositeTextProviderTest.java index 729090298..3b5f30c44 100644 --- a/core/src/test/java/com/opensymphony/xwork2/CompositeTextProviderTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/CompositeTextProviderTest.java @@ -78,7 +78,6 @@ public class CompositeTextProviderTest extends XWorkTestCase { super.setUp(); TextProviderFactory tpf = container.getInstance(TextProviderFactory.class); - tpf.setTextProvider(null); ActionContext.getContext().setLocale(Locale.ENGLISH); diff --git a/core/src/test/java/com/opensymphony/xwork2/validator/ConversionErrorFieldValidatorTest.java b/core/src/test/java/com/opensymphony/xwork2/validator/ConversionErrorFieldValidatorTest.java index 8182d779a..411dbf8c6 100644 --- a/core/src/test/java/com/opensymphony/xwork2/validator/ConversionErrorFieldValidatorTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/validator/ConversionErrorFieldValidatorTest.java @@ -53,7 +53,7 @@ public class ConversionErrorFieldValidatorTest extends XWorkTestCase { validator = new ConversionErrorFieldValidator(); validationAware = new ValidationAwareSupport(); - DelegatingValidatorContext validatorContext = new DelegatingValidatorContext(validationAware, container.inject(TextProviderFactory.class)); + DelegatingValidatorContext validatorContext = new DelegatingValidatorContext(validationAware, container.getInstance(TextProviderFactory.class)); stack.push(validatorContext); validator.setValidatorContext(validatorContext); validator.setFieldName("foo"); diff --git a/core/src/test/java/com/opensymphony/xwork2/validator/DoubleRangeValidatorTest.java b/core/src/test/java/com/opensymphony/xwork2/validator/DoubleRangeValidatorTest.java index 3f75a1455..e60d24768 100644 --- a/core/src/test/java/com/opensymphony/xwork2/validator/DoubleRangeValidatorTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/validator/DoubleRangeValidatorTest.java @@ -237,7 +237,7 @@ public class DoubleRangeValidatorTest extends XWorkTestCase { val = new DoubleRangeFieldValidator(); val.setValueStack(ActionContext.getContext().getValueStack()); ActionContext.getContext().setParameters(HttpParameters.create().build()); - tpf = container.inject(TextProviderFactory.class); + tpf = container.getInstance(TextProviderFactory.class); } @Override diff --git a/core/src/test/java/com/opensymphony/xwork2/validator/EmailValidatorTest.java b/core/src/test/java/com/opensymphony/xwork2/validator/EmailValidatorTest.java index ae8c036f3..dffad12ce 100644 --- a/core/src/test/java/com/opensymphony/xwork2/validator/EmailValidatorTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/validator/EmailValidatorTest.java @@ -162,6 +162,6 @@ public class EmailValidatorTest extends XWorkTestCase { public void setUp() throws Exception { super.setUp(); - tpf = container.inject(TextProviderFactory.class); + tpf = container.getInstance(TextProviderFactory.class); } } diff --git a/core/src/test/java/com/opensymphony/xwork2/validator/ExpressionValidatorTest.java b/core/src/test/java/com/opensymphony/xwork2/validator/ExpressionValidatorTest.java index 30613a40f..92c5a5acb 100644 --- a/core/src/test/java/com/opensymphony/xwork2/validator/ExpressionValidatorTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/validator/ExpressionValidatorTest.java @@ -139,7 +139,7 @@ public class ExpressionValidatorTest extends XWorkTestCase { ActionContext.getContext().setActionInvocation(invocation); - tpf = container.inject(TextProviderFactory.class); + tpf = container.getInstance(TextProviderFactory.class); } } diff --git a/core/src/test/java/com/opensymphony/xwork2/validator/RegexFieldValidatorTest.java b/core/src/test/java/com/opensymphony/xwork2/validator/RegexFieldValidatorTest.java index 5c7e94b05..4fa50fd79 100644 --- a/core/src/test/java/com/opensymphony/xwork2/validator/RegexFieldValidatorTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/validator/RegexFieldValidatorTest.java @@ -41,7 +41,7 @@ public class RegexFieldValidatorTest extends XWorkTestCase { public void setUp() throws Exception { super.setUp(); - tpf = container.inject(TextProviderFactory.class); + tpf = container.getInstance(TextProviderFactory.class); } public void testMatch() throws Exception { diff --git a/core/src/test/java/com/opensymphony/xwork2/validator/RepopulateConversionErrorFieldValidatorSupportTest.java b/core/src/test/java/com/opensymphony/xwork2/validator/RepopulateConversionErrorFieldValidatorSupportTest.java index c4aa1783c..51d8236ba 100644 --- a/core/src/test/java/com/opensymphony/xwork2/validator/RepopulateConversionErrorFieldValidatorSupportTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/validator/RepopulateConversionErrorFieldValidatorSupportTest.java @@ -92,7 +92,7 @@ public class RepopulateConversionErrorFieldValidatorSupportTest extends XWorkTes conversionErrors.put("someFieldName", conversionErrorValue); conversionErrors.put("xxxsomeFieldName", conversionErrorValue); - TextProviderFactory tpf = container.inject(TextProviderFactory.class); + TextProviderFactory tpf = container.getInstance(TextProviderFactory.class); action = container.inject(ActionSupport.class); validator1 = diff --git a/core/src/test/java/com/opensymphony/xwork2/validator/SimpleActionValidationTest.java b/core/src/test/java/com/opensymphony/xwork2/validator/SimpleActionValidationTest.java index 991a75ead..06695eafc 100644 --- a/core/src/test/java/com/opensymphony/xwork2/validator/SimpleActionValidationTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/validator/SimpleActionValidationTest.java @@ -153,7 +153,7 @@ public class SimpleActionValidationTest extends XWorkTestCase { SimpleAction action = new SimpleAction(); container.inject(action); - ValidatorContext validatorContext = new DelegatingValidatorContext(action, container.inject(TextProviderFactory.class)); + ValidatorContext validatorContext = new DelegatingValidatorContext(action, container.getInstance(TextProviderFactory.class)); validator.setValidatorContext(validatorContext); validator.validate(this); assertTrue(validatorContext.hasActionErrors()); diff --git a/core/src/test/java/com/opensymphony/xwork2/validator/StringLengthFieldValidatorTest.java b/core/src/test/java/com/opensymphony/xwork2/validator/StringLengthFieldValidatorTest.java index 884d4951b..ee6daf7a2 100644 --- a/core/src/test/java/com/opensymphony/xwork2/validator/StringLengthFieldValidatorTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/validator/StringLengthFieldValidatorTest.java @@ -163,7 +163,7 @@ public class StringLengthFieldValidatorTest extends XWorkTestCase { validator = new StringLengthFieldValidator(); validator.setFieldName("myField"); validator.setMessageKey("error"); - validator.setValidatorContext(new DelegatingValidatorContext(action, container.inject(TextProviderFactory.class))); + validator.setValidatorContext(new DelegatingValidatorContext(action, container.getInstance(TextProviderFactory.class))); validator.setMaxLength(5); validator.setMinLength(2); validator.setValueStack(valueStack); diff --git a/core/src/test/java/com/opensymphony/xwork2/validator/StringValidatorTest.java b/core/src/test/java/com/opensymphony/xwork2/validator/StringValidatorTest.java index c737d972b..45a021113 100644 --- a/core/src/test/java/com/opensymphony/xwork2/validator/StringValidatorTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/validator/StringValidatorTest.java @@ -217,6 +217,6 @@ public class StringValidatorTest extends XWorkTestCase { ActionContext.getContext().setActionInvocation(invocation); - tpf = container.inject(TextProviderFactory.class); + tpf = container.getInstance(TextProviderFactory.class); } } diff --git a/core/src/test/java/com/opensymphony/xwork2/validator/URLValidatorTest.java b/core/src/test/java/com/opensymphony/xwork2/validator/URLValidatorTest.java index ff9ab5041..b961d78f2 100644 --- a/core/src/test/java/com/opensymphony/xwork2/validator/URLValidatorTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/validator/URLValidatorTest.java @@ -205,7 +205,7 @@ public class URLValidatorTest extends XWorkTestCase { super.setUp(); stack = ActionContext.getContext().getValueStack(); actionContext = ActionContext.getContext(); - tpf = container.inject(TextProviderFactory.class); + tpf = container.getInstance(TextProviderFactory.class); } @Override diff --git a/core/src/test/java/com/opensymphony/xwork2/validator/validators/DateRangeFieldValidatorTest.java b/core/src/test/java/com/opensymphony/xwork2/validator/validators/DateRangeFieldValidatorTest.java index 6129fc0ae..597a19bb2 100644 --- a/core/src/test/java/com/opensymphony/xwork2/validator/validators/DateRangeFieldValidatorTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/validator/validators/DateRangeFieldValidatorTest.java @@ -91,7 +91,7 @@ public class DateRangeFieldValidatorTest extends XWorkTestCase { public void setUp() throws Exception { super.setUp(); ActionContext.getContext().setLocale(new Locale("DE")); - tpf = container.inject(TextProviderFactory.class); + tpf = container.getInstance(TextProviderFactory.class); } } diff --git a/core/src/test/java/com/opensymphony/xwork2/validator/validators/IntRangeFieldValidatorTest.java b/core/src/test/java/com/opensymphony/xwork2/validator/validators/IntRangeFieldValidatorTest.java index 77037328b..229e8fc5f 100644 --- a/core/src/test/java/com/opensymphony/xwork2/validator/validators/IntRangeFieldValidatorTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/validator/validators/IntRangeFieldValidatorTest.java @@ -13,7 +13,7 @@ public class IntRangeFieldValidatorTest extends XWorkTestCase { public void setUp() throws Exception { super.setUp(); - tpf = container.inject(TextProviderFactory.class); + tpf = container.getInstance(TextProviderFactory.class); } public void testPassValidation() throws Exception { diff --git a/core/src/test/java/com/opensymphony/xwork2/validator/validators/LongRangeFieldValidatorTest.java b/core/src/test/java/com/opensymphony/xwork2/validator/validators/LongRangeFieldValidatorTest.java index bc14b57aa..fc99e8b0f 100644 --- a/core/src/test/java/com/opensymphony/xwork2/validator/validators/LongRangeFieldValidatorTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/validator/validators/LongRangeFieldValidatorTest.java @@ -13,7 +13,7 @@ public class LongRangeFieldValidatorTest extends XWorkTestCase { public void setUp() throws Exception { super.setUp(); - tpf = container.inject(TextProviderFactory.class); + tpf = container.getInstance(TextProviderFactory.class); } public void testPassValidation() throws Exception { diff --git a/core/src/test/java/com/opensymphony/xwork2/validator/validators/RequiredStringValidatorTest.java b/core/src/test/java/com/opensymphony/xwork2/validator/validators/RequiredStringValidatorTest.java index 1495733f9..8d4d919f4 100644 --- a/core/src/test/java/com/opensymphony/xwork2/validator/validators/RequiredStringValidatorTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/validator/validators/RequiredStringValidatorTest.java @@ -14,7 +14,7 @@ public class RequiredStringValidatorTest extends XWorkTestCase { public void setUp() throws Exception { super.setUp(); - tpf = container.inject(TextProviderFactory.class); + tpf = container.getInstance(TextProviderFactory.class); } public void testRequiredStringPass() throws Exception { diff --git a/core/src/test/java/com/opensymphony/xwork2/validator/validators/ShortRangeFieldValidatorTest.java b/core/src/test/java/com/opensymphony/xwork2/validator/validators/ShortRangeFieldValidatorTest.java index bb2766405..869f43908 100644 --- a/core/src/test/java/com/opensymphony/xwork2/validator/validators/ShortRangeFieldValidatorTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/validator/validators/ShortRangeFieldValidatorTest.java @@ -13,7 +13,7 @@ public class ShortRangeFieldValidatorTest extends XWorkTestCase { public void setUp() throws Exception { super.setUp(); - tpf = container.inject(TextProviderFactory.class); + tpf = container.getInstance(TextProviderFactory.class); } public void testPassValidation() throws Exception { diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/I18NAttributeEvaluator.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/I18NAttributeEvaluator.java index 647a289e1..1ef7357c7 100644 --- a/plugins/tiles/src/main/java/org/apache/struts2/tiles/I18NAttributeEvaluator.java +++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/I18NAttributeEvaluator.java @@ -20,17 +20,13 @@ package org.apache.struts2.tiles; import com.opensymphony.xwork2.ActionContext; -import com.opensymphony.xwork2.LocaleProvider; import com.opensymphony.xwork2.TextProvider; import com.opensymphony.xwork2.TextProviderFactory; import com.opensymphony.xwork2.config.ConfigurationException; -import com.opensymphony.xwork2.ognl.OgnlUtil; -import ognl.OgnlException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.struts2.ServletActionContext; import org.apache.tiles.evaluator.AbstractAttributeEvaluator; -import org.apache.tiles.evaluator.EvaluationException; import org.apache.tiles.request.Request; import org.apache.tiles.request.servlet.ServletUtil; @@ -52,7 +48,7 @@ public class I18NAttributeEvaluator extends AbstractAttributeEvaluator { throw new ConfigurationException("There is no ActionContext for current request!"); } - TextProviderFactory tpf = ctx.getContainer().inject(TextProviderFactory.class); + TextProviderFactory tpf = ctx.getContainer().getInstance(TextProviderFactory.class); TextProvider textProvider = tpf.createInstance(ctx.getActionInvocation().getAction().getClass()); if (textProvider != null) {