Repository: struts Updated Branches: refs/heads/master 3c68a3def -> fc2179cf1
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/fc2179cf Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/fc2179cf Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/fc2179cf Branch: refs/heads/master Commit: fc2179cf1ac9fbfb61e3430fa88b641d87253327 Parents: 3c68a3d Author: Lukasz Lenart <lukaszlen...@apache.org> Authored: Fri Mar 11 11:03:36 2016 +0100 Committer: Lukasz Lenart <lukaszlen...@apache.org> Committed: Fri Mar 11 11:04:14 2016 +0100 ---------------------------------------------------------------------- .../xwork2/interceptor/I18nInterceptor.java | 5 +++++ .../xwork2/interceptor/I18nInterceptorTest.java | 16 ++++++++-------- .../struts2/interceptor/I18nInterceptorTest.java | 16 ++++++++-------- 3 files changed, 21 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/struts/blob/fc2179cf/core/src/main/java/com/opensymphony/xwork2/interceptor/I18nInterceptor.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/I18nInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/I18nInterceptor.java index 186e42e..cf4995e 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/I18nInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/I18nInterceptor.java @@ -21,6 +21,7 @@ import com.opensymphony.xwork2.util.LocalizedTextUtil; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.util.Arrays; import java.util.Locale; import java.util.Map; @@ -218,6 +219,10 @@ public class I18nInterceptor extends AbstractInterceptor { LOG.debug("Applied request locale: {}", 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/fc2179cf/core/src/test/java/com/opensymphony/xwork2/interceptor/I18nInterceptorTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/com/opensymphony/xwork2/interceptor/I18nInterceptorTest.java b/core/src/test/java/com/opensymphony/xwork2/interceptor/I18nInterceptorTest.java index 5979e58..17c27aa 100644 --- a/core/src/test/java/com/opensymphony/xwork2/interceptor/I18nInterceptorTest.java +++ b/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 { http://git-wip-us.apache.org/repos/asf/struts/blob/fc2179cf/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