struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject struts git commit: Narrows possible locale to those from available locales
Date Fri, 11 Mar 2016 10:03:50 GMT
Repository: struts
Updated Branches:
  refs/heads/support-2-3 609cb0bb9 -> 37842193a


Narrows possible locale to those from available locales


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

Branch: refs/heads/support-2-3
Commit: 37842193ab33b7655c78a2d2c305f2e0a0e50355
Parents: 609cb0b
Author: Lukasz Lenart <lukaszlenart@apache.org>
Authored: Fri Mar 11 11:03:36 2016 +0100
Committer: Lukasz Lenart <lukaszlenart@apache.org>
Committed: Fri Mar 11 11:03:36 2016 +0100

----------------------------------------------------------------------
 .../struts2/interceptor/I18nInterceptorTest.java    | 16 ++++++++--------
 .../xwork2/interceptor/I18nInterceptor.java         |  5 +++++
 .../xwork2/interceptor/I18nInterceptorTest.java     | 16 ++++++++--------
 3 files changed, 21 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/37842193/core/src/test/java/org/apache/struts2/interceptor/I18nInterceptorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/interceptor/I18nInterceptorTest.java b/core/src/test/java/org/apache/struts2/interceptor/I18nInterceptorTest.java
index 04d853e..07abec2 100644
--- a/core/src/test/java/org/apache/struts2/interceptor/I18nInterceptorTest.java
+++ b/core/src/test/java/org/apache/struts2/interceptor/I18nInterceptorTest.java
@@ -173,12 +173,12 @@ public class I18nInterceptorTest {
 
     @Test
     public void testCountryOnlyLocale() throws Exception {
-        params.put(I18nInterceptor.DEFAULT_PARAMETER, "DK");
+        params.put(I18nInterceptor.DEFAULT_PARAMETER, "NL");
         interceptor.intercept(mai);
 
         assertNull(params.get(I18nInterceptor.DEFAULT_PARAMETER)); // should have been removed
 
-        Locale denmark = new Locale("DK");
+        Locale denmark = new Locale("NL");
         assertNotNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should
be stored here
         assertEquals(denmark, session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); //
should create a locale object
     }
@@ -197,31 +197,31 @@ public class I18nInterceptorTest {
 
     @Test
     public void testWithVariant() throws Exception {
-        params.put(I18nInterceptor.DEFAULT_PARAMETER, "fr_CA_xx");
+        params.put(I18nInterceptor.DEFAULT_PARAMETER, "ja_JP_JP");
         interceptor.intercept(mai);
 
         assertNull(params.get(I18nInterceptor.DEFAULT_PARAMETER)); // should have been removed
 
-        Locale variant = new Locale("fr", "CA", "xx");
+        Locale variant = new Locale("ja", "JP", "JP");
         Locale locale = (Locale) session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE);
         assertNotNull(locale); // should be stored here
         assertEquals(variant, locale);
-        assertEquals("xx", locale.getVariant());
+        assertEquals("JP", locale.getVariant());
     }
 
     @Test
     public void testWithVariantRequestOnly() throws Exception {
-        params.put(I18nInterceptor.DEFAULT_REQUESTONLY_PARAMETER, "fr_CA_xx");
+        params.put(I18nInterceptor.DEFAULT_REQUESTONLY_PARAMETER, "ja_JP_JP");
         interceptor.intercept(mai);
 
         assertNull(params.get(I18nInterceptor.DEFAULT_PARAMETER)); // should have been removed
         assertNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE));
 
-        Locale variant = new Locale("fr", "CA", "xx");
+        Locale variant = new Locale("ja", "JP", "JP");
         Locale locale = mai.getInvocationContext().getLocale();
         assertNotNull(locale); // should be stored here
         assertEquals(variant, locale);
-        assertEquals("xx", locale.getVariant());
+        assertEquals("JP", locale.getVariant());
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/struts/blob/37842193/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/I18nInterceptor.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/I18nInterceptor.java
b/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/I18nInterceptor.java
index 3deb268..a0d4fc5 100644
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/I18nInterceptor.java
+++ b/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/I18nInterceptor.java
@@ -21,6 +21,7 @@ import com.opensymphony.xwork2.util.LocalizedTextUtil;
 import com.opensymphony.xwork2.util.logging.Logger;
 import com.opensymphony.xwork2.util.logging.LoggerFactory;
 
+import java.util.Arrays;
 import java.util.Locale;
 import java.util.Map;
 
@@ -226,6 +227,10 @@ public class I18nInterceptor extends AbstractInterceptor {
                 LOG.debug("applied request locale=#0", locale);
             }
         }
+
+        if (locale != null && !Arrays.asList(Locale.getAvailableLocales()).contains(locale))
{
+            locale = Locale.getDefault();
+        }
         return locale;
     }
 

http://git-wip-us.apache.org/repos/asf/struts/blob/37842193/xwork-core/src/test/java/com/opensymphony/xwork2/interceptor/I18nInterceptorTest.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/test/java/com/opensymphony/xwork2/interceptor/I18nInterceptorTest.java
b/xwork-core/src/test/java/com/opensymphony/xwork2/interceptor/I18nInterceptorTest.java
index 1b585ec..495a2df 100644
--- a/xwork-core/src/test/java/com/opensymphony/xwork2/interceptor/I18nInterceptorTest.java
+++ b/xwork-core/src/test/java/com/opensymphony/xwork2/interceptor/I18nInterceptorTest.java
@@ -82,12 +82,12 @@ public class I18nInterceptorTest extends TestCase {
     }
 
     public void testCountryOnlyLocale() throws Exception {
-        params.put(I18nInterceptor.DEFAULT_PARAMETER, "DK");
+        params.put(I18nInterceptor.DEFAULT_PARAMETER, "NL");
         interceptor.intercept(mai);
 
         assertNull(params.get(I18nInterceptor.DEFAULT_PARAMETER)); // should have been removed
 
-        Locale denmark = new Locale("DK");
+        Locale denmark = new Locale("NL");
         assertNotNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should
be stored here
         assertEquals(denmark, session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); //
should create a locale object
     }
@@ -104,30 +104,30 @@ public class I18nInterceptorTest extends TestCase {
     }
 
     public void testWithVariant() throws Exception {
-        params.put(I18nInterceptor.DEFAULT_PARAMETER, "fr_CA_xx");
+        params.put(I18nInterceptor.DEFAULT_PARAMETER, "ja_JP_JP");
         interceptor.intercept(mai);
 
         assertNull(params.get(I18nInterceptor.DEFAULT_PARAMETER)); // should have been removed
 
-        Locale variant = new Locale("fr", "CA", "xx");
+        Locale variant = new Locale("ja", "JP", "JP");
         Locale locale = (Locale) session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE);
         assertNotNull(locale); // should be stored here
         assertEquals(variant, locale);
-        assertEquals("xx", locale.getVariant());
+        assertEquals("JP", locale.getVariant());
     }
 
     public void testWithVariantRequestOnly() throws Exception {
-        params.put(I18nInterceptor.DEFAULT_REQUESTONLY_PARAMETER, "fr_CA_xx");
+        params.put(I18nInterceptor.DEFAULT_REQUESTONLY_PARAMETER, "ja_JP_JP");
         interceptor.intercept(mai);
 
         assertNull(params.get(I18nInterceptor.DEFAULT_PARAMETER)); // should have been removed
         assertNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE));
 
-        Locale variant = new Locale("fr", "CA", "xx");
+        Locale variant = new Locale("ja", "JP", "JP");
         Locale locale = mai.getInvocationContext().getLocale();
         assertNotNull(locale); // should be stored here
         assertEquals(variant, locale);
-        assertEquals("xx", locale.getVariant());
+        assertEquals("JP", locale.getVariant());
     }
 
     public void testRealLocaleObjectInParams() throws Exception {


Mime
View raw message