struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [03/17] struts git commit: Adjust usage of the factory
Date Mon, 13 Mar 2017 17:46:12 GMT
Adjust usage of the factory


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/728055dc
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/728055dc
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/728055dc

Branch: refs/heads/master
Commit: 728055dc46b2517791d5860d60a77e6196ddcbaf
Parents: db8ebe7
Author: Lukasz Lenart <lukaszlenart@apache.org>
Authored: Fri Mar 10 08:40:24 2017 +0100
Committer: Lukasz Lenart <lukaszlenart@apache.org>
Committed: Fri Mar 10 08:40:24 2017 +0100

----------------------------------------------------------------------
 .../com/opensymphony/xwork2/ActionSupport.java  |  7 ++----
 .../AnnotationActionValidatorManager.java       |  8 ++++++-
 .../DefaultActionValidatorManager.java          | 12 ++++++++--
 .../validator/validators/ValidatorSupport.java  | 10 +++++++-
 .../validators/VisitorFieldValidator.java       | 24 ++++++++++++++++----
 .../org/apache/struts2/components/I18n.java     |  5 ++--
 .../interceptor/FileUploadInterceptor.java      |  8 ++-----
 .../struts2/tiles/I18NAttributeEvaluator.java   |  7 ++----
 8 files changed, 54 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/728055dc/core/src/main/java/com/opensymphony/xwork2/ActionSupport.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/ActionSupport.java b/core/src/main/java/com/opensymphony/xwork2/ActionSupport.java
index d2b551a..bb7048f 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ActionSupport.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ActionSupport.java
@@ -274,11 +274,8 @@ public class ActionSupport implements Action, Validateable, ValidationAware,
Tex
      */
     private TextProvider getTextProvider() {
         if (textProvider == null) {
-            TextProviderFactory tpf = new TextProviderFactory();
-            if (container != null) {
-                container.inject(tpf);
-            }
-            textProvider = tpf.createInstance(getClass(), this);
+            TextProviderFactory tpf = container.inject(TextProviderFactory.class);
+            textProvider = tpf.createInstance(getClass());
         }
         return textProvider;
     }

http://git-wip-us.apache.org/repos/asf/struts/blob/728055dc/core/src/main/java/com/opensymphony/xwork2/validator/AnnotationActionValidatorManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/validator/AnnotationActionValidatorManager.java
b/core/src/main/java/com/opensymphony/xwork2/validator/AnnotationActionValidatorManager.java
index 641bc43..cd6fa4e 100644
--- a/core/src/main/java/com/opensymphony/xwork2/validator/AnnotationActionValidatorManager.java
+++ b/core/src/main/java/com/opensymphony/xwork2/validator/AnnotationActionValidatorManager.java
@@ -52,6 +52,7 @@ public class AnnotationActionValidatorManager implements ActionValidatorManager
     private ValidatorFileParser validatorFileParser;
     private FileManager fileManager;
     private boolean reloadingConfigs;
+    private TextProviderFactory textProviderFactory;
 
     @Inject
     public void setValidatorFactory(ValidatorFactory fac) {
@@ -73,6 +74,11 @@ public class AnnotationActionValidatorManager implements ActionValidatorManager
         this.reloadingConfigs = Boolean.parseBoolean(reloadingConfigs);
     }
 
+    @Inject
+    public void setTextProviderFactory(TextProviderFactory textProviderFactory) {
+        this.textProviderFactory = textProviderFactory;
+    }
+
     public List<Validator> getValidators(Class clazz, String context) {
         return getValidators(clazz, context, null);
     }
@@ -116,7 +122,7 @@ public class AnnotationActionValidatorManager implements ActionValidatorManager
     }
 
     public void validate(Object object, String context, String method) throws ValidationException
{
-        ValidatorContext validatorContext = new DelegatingValidatorContext(object);
+        ValidatorContext validatorContext = new DelegatingValidatorContext(object, textProviderFactory);
         validate(object, context, validatorContext, method);
     }
 

http://git-wip-us.apache.org/repos/asf/struts/blob/728055dc/core/src/main/java/com/opensymphony/xwork2/validator/DefaultActionValidatorManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/validator/DefaultActionValidatorManager.java
b/core/src/main/java/com/opensymphony/xwork2/validator/DefaultActionValidatorManager.java
index d16afcd..7ad0ac9 100644
--- a/core/src/main/java/com/opensymphony/xwork2/validator/DefaultActionValidatorManager.java
+++ b/core/src/main/java/com/opensymphony/xwork2/validator/DefaultActionValidatorManager.java
@@ -18,6 +18,7 @@ package com.opensymphony.xwork2.validator;
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.FileManager;
 import com.opensymphony.xwork2.FileManagerFactory;
+import com.opensymphony.xwork2.TextProviderFactory;
 import com.opensymphony.xwork2.XWorkConstants;
 import com.opensymphony.xwork2.inject.Inject;
 import com.opensymphony.xwork2.util.ClassLoaderUtil;
@@ -50,16 +51,19 @@ import java.util.*;
  */
 public class DefaultActionValidatorManager implements ActionValidatorManager {
 
+    private final static Logger LOG = LogManager.getLogger(DefaultActionValidatorManager.class);
+
     /** The file suffix for any validation file. */
     protected static final String VALIDATION_CONFIG_SUFFIX = "-validation.xml";
 
     private final Map<String, List<ValidatorConfig>> validatorCache = Collections.synchronizedMap(new
HashMap<String, List<ValidatorConfig>>());
     private final Map<String, List<ValidatorConfig>> validatorFileCache = Collections.synchronizedMap(new
HashMap<String, List<ValidatorConfig>>());
-    private final Logger LOG = LogManager.getLogger(DefaultActionValidatorManager.class);
+
     private ValidatorFactory validatorFactory;
     private ValidatorFileParser validatorFileParser;
     private FileManager fileManager;
     private boolean reloadingConfigs;
+    private TextProviderFactory textProviderFactory;
 
     @Inject
     public void setValidatorFileParser(ValidatorFileParser parser) {
@@ -81,6 +85,10 @@ public class DefaultActionValidatorManager implements ActionValidatorManager
{
         this.reloadingConfigs = Boolean.parseBoolean(reloadingConfigs);
     }
 
+    public void setTextProviderFactory(TextProviderFactory textProviderFactory) {
+        this.textProviderFactory = textProviderFactory;
+    }
+
     public synchronized List<Validator> getValidators(Class clazz, String context)
{
         return getValidators(clazz, context, null);
     }
@@ -118,7 +126,7 @@ public class DefaultActionValidatorManager implements ActionValidatorManager
{
     }
 
     public void validate(Object object, String context, String method) throws ValidationException
{
-        ValidatorContext validatorContext = new DelegatingValidatorContext(object);
+        ValidatorContext validatorContext = new DelegatingValidatorContext(object, textProviderFactory);
         validate(object, context, validatorContext, method);
     }
 

http://git-wip-us.apache.org/repos/asf/struts/blob/728055dc/core/src/main/java/com/opensymphony/xwork2/validator/validators/ValidatorSupport.java
----------------------------------------------------------------------
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 1df9450..3cfdb4b 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
@@ -15,6 +15,8 @@
  */
 package com.opensymphony.xwork2.validator.validators;
 
+import com.opensymphony.xwork2.TextProviderFactory;
+import com.opensymphony.xwork2.inject.Inject;
 import com.opensymphony.xwork2.util.TextParseUtil;
 import com.opensymphony.xwork2.util.ValueStack;
 import com.opensymphony.xwork2.validator.*;
@@ -45,6 +47,12 @@ public abstract class ValidatorSupport implements Validator, ShortCircuitableVal
     private String[] messageParameters;
     protected ValueStack stack;
 
+    protected TextProviderFactory textProviderFactory;
+
+    @Inject
+    public void setTextProviderFactory(TextProviderFactory textProviderFactory) {
+        this.textProviderFactory = textProviderFactory;
+    }
 
     public void setValueStack(ValueStack stack) {
         this.stack = stack;
@@ -76,7 +84,7 @@ public abstract class ValidatorSupport implements Validator, ShortCircuitableVal
                 defaultMessage = messageKey;
             }
             if (validatorContext == null) {
-                validatorContext = new DelegatingValidatorContext(object);
+                validatorContext = new DelegatingValidatorContext(object, textProviderFactory);
             }
             List<Object> parsedMessageParameters = null;
             if (messageParameters != null) {

http://git-wip-us.apache.org/repos/asf/struts/blob/728055dc/core/src/main/java/com/opensymphony/xwork2/validator/validators/VisitorFieldValidator.java
----------------------------------------------------------------------
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 9f8e67d..37d9f66 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
@@ -16,6 +16,8 @@
 package com.opensymphony.xwork2.validator.validators;
 
 import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.CompositeTextProvider;
+import com.opensymphony.xwork2.TextProvider;
 import com.opensymphony.xwork2.inject.Inject;
 import com.opensymphony.xwork2.util.ValueStack;
 import com.opensymphony.xwork2.validator.ActionValidatorManager;
@@ -24,6 +26,8 @@ import com.opensymphony.xwork2.validator.ValidationException;
 import com.opensymphony.xwork2.validator.ValidatorContext;
 
 import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
 
 
 /**
@@ -166,24 +170,36 @@ public class VisitorFieldValidator extends FieldValidatorSupport {
         ValidatorContext validatorContext;
 
         if (appendPrefix) {
-            validatorContext = new AppendingValidatorContext(getValidatorContext(), o, fieldName,
getMessage(o));
+            ValidatorContext parent = getValidatorContext();
+            validatorContext = new AppendingValidatorContext(parent, createTextProvider(o,
parent), fieldName, getMessage(o));
         } else {
             ValidatorContext parent = getValidatorContext();
-            validatorContext = new DelegatingValidatorContext(parent, DelegatingValidatorContext.makeTextProvider(o,
parent), parent);
+            CompositeTextProvider textProvider = createTextProvider(o, parent);
+            validatorContext = new DelegatingValidatorContext(parent, textProvider, parent);
         }
 
         actionValidatorManager.validate(o, visitorContext, validatorContext);
         stack.pop();
     }
 
+    private CompositeTextProvider createTextProvider(Object o, ValidatorContext parent) {
+        List<TextProvider> textProviders = new LinkedList<>();
+        if (o instanceof TextProvider) {
+            textProviders.add((TextProvider) o);
+        }
+        textProviders.add(parent);
+
+        return new CompositeTextProvider(textProviders);
+    }
+
 
     public static class AppendingValidatorContext extends DelegatingValidatorContext {
         private String field;
         private String message;
         private ValidatorContext parent;
 
-        public AppendingValidatorContext(ValidatorContext parent, Object object, String field,
String message) {
-            super(parent, makeTextProvider(object, parent), parent);
+        public AppendingValidatorContext(ValidatorContext parent, TextProvider textProvider,
String field, String message) {
+            super(parent, textProvider, parent);
 
             this.field = field;
             this.message = message;

http://git-wip-us.apache.org/repos/asf/struts/blob/728055dc/core/src/main/java/org/apache/struts2/components/I18n.java
----------------------------------------------------------------------
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 a04840f..c35f4a0 100644
--- a/core/src/main/java/org/apache/struts2/components/I18n.java
+++ b/core/src/main/java/org/apache/struts2/components/I18n.java
@@ -125,9 +125,8 @@ public class I18n extends Component {
             }
 
             if (bundle != null) {
-                TextProviderFactory tpf = new TextProviderFactory();
-                container.inject(tpf);
-                textProvider = tpf.createInstance(bundle, localeProvider);
+                TextProviderFactory tpf = container.inject(TextProviderFactory.class);
+                textProvider = tpf.createInstance(bundle);
                 getStack().push(textProvider);
                 pushed = true;
             }

http://git-wip-us.apache.org/repos/asf/struts/blob/728055dc/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java
----------------------------------------------------------------------
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 aa7fe01..a428b53 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java
@@ -446,12 +446,8 @@ public class FileUploadInterceptor extends AbstractInterceptor {
     }
 
     private TextProvider getTextProvider(Object action) {
-        TextProviderFactory tpf = new TextProviderFactory();
-        if (container != null) {
-            container.inject(tpf);
-        }
-        LocaleProvider localeProvider = getLocaleProvider(action);
-        return tpf.createInstance(action.getClass(), localeProvider);
+        TextProviderFactory tpf = container.inject(TextProviderFactory.class);
+        return tpf.createInstance(action.getClass());
     }
 
     private LocaleProvider getLocaleProvider(Object action) {

http://git-wip-us.apache.org/repos/asf/struts/blob/728055dc/plugins/tiles/src/main/java/org/apache/struts2/tiles/I18NAttributeEvaluator.java
----------------------------------------------------------------------
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 37150ae..647a289 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
@@ -52,11 +52,8 @@ public class I18NAttributeEvaluator extends AbstractAttributeEvaluator
{
             throw new ConfigurationException("There is no ActionContext for current request!");
         }
 
-        TextProviderFactory tpf = new TextProviderFactory();
-        ctx.getContainer().inject(tpf);
-        LocaleProvider localeProvider = ctx.getContainer().getInstance(LocaleProvider.class);
-
-        TextProvider textProvider = tpf.createInstance(ctx.getActionInvocation().getAction().getClass(),
localeProvider);
+        TextProviderFactory tpf = ctx.getContainer().inject(TextProviderFactory.class);
+        TextProvider textProvider = tpf.createInstance(ctx.getActionInvocation().getAction().getClass());
 
         if (textProvider != null) {
             LOG.debug("Trying find text [{}] using TextProvider {}", expression, textProvider);


Mime
View raw message