struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [1/4] struts git commit: Uses LocaleProvider and default TextProvider instead of evaluating expression
Date Wed, 22 Jun 2016 09:14:02 GMT
Repository: struts
Updated Branches:
  refs/heads/master d5e0fe920 -> cd13846e1


Uses LocaleProvider and default TextProvider instead of evaluating expression


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

Branch: refs/heads/master
Commit: 8dfe178585d06858eb307cfb2a1bf1995243476a
Parents: d5e0fe9
Author: Lukasz Lenart <lukaszlenart@apache.org>
Authored: Wed Jun 22 10:38:12 2016 +0200
Committer: Lukasz Lenart <lukaszlenart@apache.org>
Committed: Wed Jun 22 11:03:41 2016 +0200

----------------------------------------------------------------------
 .../org/apache/struts2/components/I18n.java     | 38 +++++++++++---------
 1 file changed, 22 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/8dfe1785/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 4db0e07..a04840f 100644
--- a/core/src/main/java/org/apache/struts2/components/I18n.java
+++ b/core/src/main/java/org/apache/struts2/components/I18n.java
@@ -21,7 +21,13 @@
 
 package org.apache.struts2.components;
 
-import com.opensymphony.xwork2.ActionContext;
+import java.io.Writer;
+import java.util.ResourceBundle;
+
+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;
@@ -31,13 +37,6 @@ import com.opensymphony.xwork2.util.LocalizedTextUtil;
 import com.opensymphony.xwork2.util.ValueStack;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
-import org.apache.struts2.StrutsException;
-import org.apache.struts2.views.annotations.StrutsTag;
-import org.apache.struts2.views.annotations.StrutsTagAttribute;
-
-import java.io.Writer;
-import java.util.Locale;
-import java.util.ResourceBundle;
 
 /**
  * <!-- START SNIPPET: javadoc -->
@@ -92,6 +91,8 @@ public class I18n extends Component {
     protected String name;
     protected Container container;
     private TextProvider textProvider;
+    private TextProvider defaultTextProvider;
+    private LocaleProvider localeProvider;
 
     public I18n(ValueStack stack) {
         super(stack);
@@ -102,26 +103,31 @@ public class I18n extends Component {
         this.container = container;
     }
 
+    @Inject
+    public void setTextProvider(TextProvider textProvider) {
+        this.defaultTextProvider = textProvider;
+    }
+
+    @Inject
+    public void setLocaleProvider(LocaleProvider localeProvider) {
+        this.localeProvider = localeProvider;
+    }
+
     public boolean start(Writer writer) {
         boolean result = super.start(writer);
 
         try {
             String name = this.findString(this.name, "name", "Resource bundle name is required.
Example: foo or foo_en");
-            ResourceBundle bundle = (ResourceBundle) findValue("getTexts('" + name + "')");
+            ResourceBundle bundle = defaultTextProvider.getTexts(name);
 
             if (bundle == null) {
-                bundle = LocalizedTextUtil.findResourceBundle(name, (Locale) getStack().getContext().get(ActionContext.LOCALE));
+                bundle = LocalizedTextUtil.findResourceBundle(name, localeProvider.getLocale());
             }
 
             if (bundle != null) {
-                final Locale locale = (Locale) getStack().getContext().get(ActionContext.LOCALE);
                 TextProviderFactory tpf = new TextProviderFactory();
                 container.inject(tpf);
-                textProvider = tpf.createInstance(bundle, new LocaleProvider() {
-                    public Locale getLocale() {
-                        return locale;
-                    }
-                });
+                textProvider = tpf.createInstance(bundle, localeProvider);
                 getStack().push(textProvider);
                 pushed = true;
             }


Mime
View raw message