mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
WW-4756 Implements TextProviderFactory and used it accros the framework
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
+4
-7
@@ -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)
|
||||
|
||||
+1
-1
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -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;
|
||||
|
||||
/**
|
||||
* <!-- START SNIPPET: javadoc -->
|
||||
@@ -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;
|
||||
|
||||
+6
-2
@@ -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;
|
||||
|
||||
/**
|
||||
* <!-- START SNIPPET: javadoc -->
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -130,9 +130,9 @@
|
||||
<bean type="com.opensymphony.xwork2.conversion.impl.NumberConverter" name="struts" class="com.opensymphony.xwork2.conversion.impl.NumberConverter" scope="singleton"/>
|
||||
<bean type="com.opensymphony.xwork2.conversion.impl.StringConverter" name="struts" class="com.opensymphony.xwork2.conversion.impl.StringConverter" scope="singleton"/>
|
||||
|
||||
<bean type="com.opensymphony.xwork2.TextProviderFactory" name="struts" class="com.opensymphony.xwork2.TextProviderFactory" scope="prototype" />
|
||||
<bean type="com.opensymphony.xwork2.TextProvider" name="system" class="com.opensymphony.xwork2.DefaultTextProvider" scope="singleton" />
|
||||
<bean type="com.opensymphony.xwork2.LocalizedTextProvider" name="struts" class="com.opensymphony.xwork2.util.DefaultLocalizedTextProvider" scope="singleton" />
|
||||
<bean type="com.opensymphony.xwork2.TextProvider" name="struts" class="com.opensymphony.xwork2.TextProviderSupport" scope="prototype" />
|
||||
<bean type="com.opensymphony.xwork2.TextProviderFactory" name="struts" class="com.opensymphony.xwork2.StrutsTextProviderFactory" scope="singleton" />
|
||||
<bean type="com.opensymphony.xwork2.LocaleProviderFactory" name="struts" class="com.opensymphony.xwork2.DefaultLocaleProviderFactory" scope="singleton" />
|
||||
|
||||
<bean type="org.apache.struts2.components.UrlRenderer" name="struts" class="org.apache.struts2.components.ServletUrlRenderer"/>
|
||||
@@ -142,7 +142,6 @@
|
||||
<bean type="com.opensymphony.xwork2.util.reflection.ReflectionProvider" name="struts" class="com.opensymphony.xwork2.ognl.OgnlReflectionProvider" />
|
||||
<bean type="com.opensymphony.xwork2.util.reflection.ReflectionContextFactory" name="struts" class="com.opensymphony.xwork2.ognl.OgnlReflectionContextFactory" />
|
||||
|
||||
<bean type="com.opensymphony.xwork2.TextProvider" name="system" class="com.opensymphony.xwork2.DefaultTextProvider" />
|
||||
<bean type="com.opensymphony.xwork2.conversion.NullHandler" name="java.lang.Object" class="com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler" />
|
||||
|
||||
<bean type="com.opensymphony.xwork2.validator.ActionValidatorManager" name="struts" class="com.opensymphony.xwork2.validator.AnnotationActionValidatorManager" />
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
+1
-1
@@ -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");
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ public class ExpressionValidatorTest extends XWorkTestCase {
|
||||
|
||||
ActionContext.getContext().setActionInvocation(invocation);
|
||||
|
||||
tpf = container.inject(TextProviderFactory.class);
|
||||
tpf = container.getInstance(TextProviderFactory.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+1
-1
@@ -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 =
|
||||
|
||||
+1
-1
@@ -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());
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
@@ -217,6 +217,6 @@ public class StringValidatorTest extends XWorkTestCase {
|
||||
|
||||
ActionContext.getContext().setActionInvocation(invocation);
|
||||
|
||||
tpf = container.inject(TextProviderFactory.class);
|
||||
tpf = container.getInstance(TextProviderFactory.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
+1
-1
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -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 {
|
||||
|
||||
+1
-1
@@ -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 {
|
||||
|
||||
+1
-1
@@ -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 {
|
||||
|
||||
+1
-1
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user