[seam-commits] Seam SVN: r12797 - in modules/international/trunk: api/src/main/java/org/jboss/seam/international/locale and 6 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue May 25 16:40:10 EDT 2010


Author: kenfinni
Date: 2010-05-25 16:40:09 -0400 (Tue, 25 May 2010)
New Revision: 12797

Added:
   modules/international/trunk/api/src/main/java/org/jboss/seam/international/locale/
   modules/international/trunk/api/src/main/java/org/jboss/seam/international/locale/UserLocale.java
   modules/international/trunk/impl/src/main/java/org/jboss/seam/international/locale/
   modules/international/trunk/impl/src/main/java/org/jboss/seam/international/locale/AvailableLocales.java
   modules/international/trunk/impl/src/main/java/org/jboss/seam/international/locale/DefaultLocaleProducer.java
   modules/international/trunk/impl/src/main/java/org/jboss/seam/international/locale/LocaleUtils.java
   modules/international/trunk/impl/src/main/java/org/jboss/seam/international/locale/UserLocaleProducer.java
   modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/
   modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/AvailableLocalesTest.java
   modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/DefaultLocaleOverrideFailTest.java
   modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/DefaultLocaleOverrideLangCountryTest.java
   modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/DefaultLocaleOverrideLangCountryVariantTest.java
   modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/DefaultLocaleOverrideLangTest.java
   modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/DefaultLocaleTest.java
   modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/UserLocaleTest.java
   modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/locale/
   modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/locale/override-available.xml
   modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/locale/override-fail.xml
   modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/locale/override-lang-country-variant.xml
   modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/locale/override-lang-country.xml
   modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/locale/override-lang.xml
Log:
SEAMINTL-2 User, Application and Available Locale handling

Added: modules/international/trunk/api/src/main/java/org/jboss/seam/international/locale/UserLocale.java
===================================================================
--- modules/international/trunk/api/src/main/java/org/jboss/seam/international/locale/UserLocale.java	                        (rev 0)
+++ modules/international/trunk/api/src/main/java/org/jboss/seam/international/locale/UserLocale.java	2010-05-25 20:40:09 UTC (rev 12797)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.international.locale;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+/**
+ * User Locale
+ * 
+ * @author Ken Finnigan
+ */
+ at Target( { METHOD, PARAMETER, FIELD })
+ at Retention(RUNTIME)
+ at Documented
+ at Qualifier
+ at Inherited
+public @interface UserLocale
+{
+}

Added: modules/international/trunk/impl/src/main/java/org/jboss/seam/international/locale/AvailableLocales.java
===================================================================
--- modules/international/trunk/impl/src/main/java/org/jboss/seam/international/locale/AvailableLocales.java	                        (rev 0)
+++ modules/international/trunk/impl/src/main/java/org/jboss/seam/international/locale/AvailableLocales.java	2010-05-25 20:40:09 UTC (rev 12797)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.international.locale;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Locale;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+
+import org.slf4j.Logger;
+
+ at ApplicationScoped
+public class AvailableLocales
+{
+   private String[] supportedLocaleKeys;
+
+   @Inject
+   Logger log;
+
+   @Produces
+   private List<Locale> locales = null;
+
+   @PostConstruct
+   public void init()
+   {
+      locales = new ArrayList<Locale>();
+
+      for (String localeKey : supportedLocaleKeys)
+      {
+         try
+         {
+            Locale lc = LocaleUtils.toLocale(localeKey);
+            locales.add(lc);
+         }
+         catch (IllegalArgumentException e)
+         {
+            log.error("AvailableLocales: Supported Locale key of " + localeKey + " was not formatted correctly", e);
+         }
+      }
+
+      Collections.sort(locales, new Comparator<Locale>()
+      {
+         public int compare(final Locale a, final Locale b)
+         {
+            return a.toString().compareTo(b.toString());
+         }
+      });
+
+      locales = Collections.unmodifiableList(locales);
+   }
+}

Added: modules/international/trunk/impl/src/main/java/org/jboss/seam/international/locale/DefaultLocaleProducer.java
===================================================================
--- modules/international/trunk/impl/src/main/java/org/jboss/seam/international/locale/DefaultLocaleProducer.java	                        (rev 0)
+++ modules/international/trunk/impl/src/main/java/org/jboss/seam/international/locale/DefaultLocaleProducer.java	2010-05-25 20:40:09 UTC (rev 12797)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.international.locale;
+
+import java.io.Serializable;
+import java.util.Locale;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.slf4j.Logger;
+
+ at ApplicationScoped
+public class DefaultLocaleProducer implements Serializable
+{
+   private static final long serialVersionUID = -4534087316489937649L;
+
+   private String defaultLocaleKey;
+
+   @Inject
+   Logger log;
+
+   @Produces
+   @Named
+   private Locale defaultLocale;
+
+   @PostConstruct
+   public void init()
+   {
+      if (null != defaultLocaleKey)
+      {
+         try
+         {
+            defaultLocale = LocaleUtils.toLocale(defaultLocaleKey);
+         }
+         catch (IllegalArgumentException e)
+         {
+            log.error("DefaultLocaleProducer: Default Locale key of " + defaultLocale + " was not formatted correctly", e);
+         }
+      }
+      if (null == defaultLocale)
+      {
+         defaultLocale = Locale.getDefault();
+      }
+   }
+}

Added: modules/international/trunk/impl/src/main/java/org/jboss/seam/international/locale/LocaleUtils.java
===================================================================
--- modules/international/trunk/impl/src/main/java/org/jboss/seam/international/locale/LocaleUtils.java	                        (rev 0)
+++ modules/international/trunk/impl/src/main/java/org/jboss/seam/international/locale/LocaleUtils.java	2010-05-25 20:40:09 UTC (rev 12797)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.international.locale;
+
+import java.util.Locale;
+
+public final class LocaleUtils
+{
+   /**
+    * <p>
+    * Converts a String to a Locale.
+    * </p>
+    * 
+    * <p>
+    * This method takes the string format of a locale and creates the locale
+    * object from it.
+    * </p>
+    * 
+    * <pre>
+    *   LocaleUtils.toLocale("en")         = new Locale("en", "")
+    *   LocaleUtils.toLocale("en_GB")      = new Locale("en", "GB")
+    *   LocaleUtils.toLocale("en_GB_xxx")  = new Locale("en", "GB", "xxx")   (#)
+    * </pre>
+    * 
+    * <p>
+    * This method validates the input strictly. The language code must be
+    * lowercase. The country code must be uppercase. The separator must be an
+    * underscore. The length must be correct.
+    * </p>
+    * 
+    * @param str the locale String to convert, null returns null
+    * @return a Locale, null if null input
+    * @throws IllegalArgumentException if the string is an invalid format
+    */
+   public static Locale toLocale(String str)
+   {
+      if (str == null)
+      {
+         return null;
+      }
+      int len = str.length();
+      if (len != 2 && len != 5 && len < 7)
+      {
+         throw new IllegalArgumentException("Invalid locale format: " + str);
+      }
+      char ch0 = str.charAt(0);
+      char ch1 = str.charAt(1);
+      if (ch0 < 'a' || ch0 > 'z' || ch1 < 'a' || ch1 > 'z')
+      {
+         throw new IllegalArgumentException("Invalid locale format: " + str);
+      }
+      if (len == 2)
+      {
+         return new Locale(str, "");
+      }
+      else
+      {
+         if (str.charAt(2) != '_')
+         {
+            throw new IllegalArgumentException("Invalid locale format: " + str);
+         }
+         char ch3 = str.charAt(3);
+         if (ch3 == '_')
+         {
+            return new Locale(str.substring(0, 2), "", str.substring(4));
+         }
+         char ch4 = str.charAt(4);
+         if (ch3 < 'A' || ch3 > 'Z' || ch4 < 'A' || ch4 > 'Z')
+         {
+            throw new IllegalArgumentException("Invalid locale format: " + str);
+         }
+         if (len == 5)
+         {
+            return new Locale(str.substring(0, 2), str.substring(3, 5));
+         }
+         else
+         {
+            if (str.charAt(5) != '_')
+            {
+               throw new IllegalArgumentException("Invalid locale format: " + str);
+            }
+            return new Locale(str.substring(0, 2), str.substring(3, 5), str.substring(6));
+         }
+      }
+   }
+}

Added: modules/international/trunk/impl/src/main/java/org/jboss/seam/international/locale/UserLocaleProducer.java
===================================================================
--- modules/international/trunk/impl/src/main/java/org/jboss/seam/international/locale/UserLocaleProducer.java	                        (rev 0)
+++ modules/international/trunk/impl/src/main/java/org/jboss/seam/international/locale/UserLocaleProducer.java	2010-05-25 20:40:09 UTC (rev 12797)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.international.locale;
+
+import java.io.Serializable;
+import java.util.Locale;
+
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.jboss.seam.international.Changed;
+
+/**
+ * Locale for a User Session. Defaults to the Locale within DefaultLocale
+ * and is altered when it receives the @Changed event.
+ * 
+ * @author Ken Finnigan
+ */
+
+ at SessionScoped
+public class UserLocaleProducer implements Serializable
+{
+   private static final long serialVersionUID = -7602504535585397561L;
+
+   @Produces
+   @UserLocale
+   @Named
+   private Locale userLocale;
+
+   @Inject
+   public void init(Locale defaultLocale)
+   {
+      this.userLocale = defaultLocale;
+   }
+
+   public void changeLocale(@Observes @Changed Locale lc)
+   {
+      this.userLocale = lc;
+   }
+}

Added: modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/AvailableLocalesTest.java
===================================================================
--- modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/AvailableLocalesTest.java	                        (rev 0)
+++ modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/AvailableLocalesTest.java	2010-05-25 20:40:09 UTC (rev 12797)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.international.test.locale;
+
+import java.util.List;
+import java.util.Locale;
+
+import javax.inject.Inject;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.international.locale.AvailableLocales;
+import org.jboss.seam.international.test.MockLogger;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+ at RunWith(Arquillian.class)
+public class AvailableLocalesTest
+{
+   @Deployment
+   public static JavaArchive createTestArchive()
+   {
+      return ShrinkWrap.create("test.jar", JavaArchive.class).addClasses(AvailableLocales.class, MockLogger.class).addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml")).addManifestResource("org/jboss/seam/international/test/locale/override-available.xml", ArchivePaths.create("seam-beans.xml"));
+   }
+
+   @Inject
+   List<Locale> locales;
+
+   @Test
+   public void testAvailableLocalesProducer()
+   {
+      Assert.assertNotNull(locales);
+      Assert.assertEquals(2, locales.size());
+   }
+}

Added: modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/DefaultLocaleOverrideFailTest.java
===================================================================
--- modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/DefaultLocaleOverrideFailTest.java	                        (rev 0)
+++ modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/DefaultLocaleOverrideFailTest.java	2010-05-25 20:40:09 UTC (rev 12797)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.international.test.locale;
+
+import java.util.Locale;
+
+import javax.inject.Inject;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.international.locale.DefaultLocaleProducer;
+import org.jboss.seam.international.test.MockLogger;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+ at RunWith(Arquillian.class)
+public class DefaultLocaleOverrideFailTest
+{
+   @Deployment
+   public static JavaArchive createTestArchive()
+   {
+      return ShrinkWrap.create("test.jar", JavaArchive.class).addClasses(MockLogger.class, DefaultLocaleProducer.class).addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml")).addManifestResource("org/jboss/seam/international/test/locale/override-fail.xml", ArchivePaths.create("seam-beans.xml"));
+   }
+
+   @Inject
+   Locale locale;
+
+   @Test
+   public void testDefaultLocaleProducerDirect()
+   {
+      Assert.assertNotNull(locale);
+      Assert.assertEquals(Locale.getDefault().toString(), locale.toString());
+   }
+}

Added: modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/DefaultLocaleOverrideLangCountryTest.java
===================================================================
--- modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/DefaultLocaleOverrideLangCountryTest.java	                        (rev 0)
+++ modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/DefaultLocaleOverrideLangCountryTest.java	2010-05-25 20:40:09 UTC (rev 12797)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.international.test.locale;
+
+import java.util.Locale;
+
+import javax.inject.Inject;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.international.locale.DefaultLocaleProducer;
+import org.jboss.seam.international.test.MockLogger;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+ at RunWith(Arquillian.class)
+public class DefaultLocaleOverrideLangCountryTest
+{
+   @Deployment
+   public static JavaArchive createTestArchive()
+   {
+      return ShrinkWrap.create("test.jar", JavaArchive.class).addClasses(MockLogger.class, DefaultLocaleProducer.class).addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml")).addManifestResource("org/jboss/seam/international/test/locale/override-lang-country.xml", ArchivePaths.create("seam-beans.xml"));
+   }
+
+   @Inject
+   Locale locale;
+
+   @Test
+   public void testDefaultLocaleProducerDirect()
+   {
+      Assert.assertNotNull(locale);
+      Assert.assertEquals("en_US", locale.toString());
+   }
+}

Added: modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/DefaultLocaleOverrideLangCountryVariantTest.java
===================================================================
--- modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/DefaultLocaleOverrideLangCountryVariantTest.java	                        (rev 0)
+++ modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/DefaultLocaleOverrideLangCountryVariantTest.java	2010-05-25 20:40:09 UTC (rev 12797)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.international.test.locale;
+
+import java.util.Locale;
+
+import javax.inject.Inject;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.international.locale.DefaultLocaleProducer;
+import org.jboss.seam.international.test.MockLogger;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+ at RunWith(Arquillian.class)
+public class DefaultLocaleOverrideLangCountryVariantTest
+{
+   @Deployment
+   public static JavaArchive createTestArchive()
+   {
+      return ShrinkWrap.create("test.jar", JavaArchive.class).addClasses(MockLogger.class, DefaultLocaleProducer.class).addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml")).addManifestResource("org/jboss/seam/international/test/locale/override-lang-country-variant.xml", ArchivePaths.create("seam-beans.xml"));
+   }
+
+   @Inject
+   Locale locale;
+
+   @Test
+   public void testDefaultLocaleProducerDirect()
+   {
+      Assert.assertNotNull(locale);
+      Assert.assertEquals("en_US_UNIX", locale.toString());
+   }
+}

Added: modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/DefaultLocaleOverrideLangTest.java
===================================================================
--- modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/DefaultLocaleOverrideLangTest.java	                        (rev 0)
+++ modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/DefaultLocaleOverrideLangTest.java	2010-05-25 20:40:09 UTC (rev 12797)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.international.test.locale;
+
+import java.util.Locale;
+
+import javax.inject.Inject;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.international.locale.DefaultLocaleProducer;
+import org.jboss.seam.international.test.MockLogger;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+ at RunWith(Arquillian.class)
+public class DefaultLocaleOverrideLangTest
+{
+   @Deployment
+   public static JavaArchive createTestArchive()
+   {
+      return ShrinkWrap.create("test.jar", JavaArchive.class).addClasses(MockLogger.class, DefaultLocaleProducer.class).addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml")).addManifestResource("org/jboss/seam/international/test/locale/override-lang.xml", ArchivePaths.create("seam-beans.xml"));
+   }
+
+   @Inject
+   Locale locale;
+
+   @Test
+   public void testDefaultLocaleProducerDirect()
+   {
+      Assert.assertNotNull(locale);
+      Assert.assertEquals("fr", locale.toString());
+   }
+}

Added: modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/DefaultLocaleTest.java
===================================================================
--- modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/DefaultLocaleTest.java	                        (rev 0)
+++ modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/DefaultLocaleTest.java	2010-05-25 20:40:09 UTC (rev 12797)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.international.test.locale;
+
+import java.util.Locale;
+
+import javax.inject.Inject;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.international.locale.DefaultLocaleProducer;
+import org.jboss.seam.international.test.MockLogger;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+ at RunWith(Arquillian.class)
+public class DefaultLocaleTest
+{
+   @Deployment
+   public static JavaArchive createTestArchive()
+   {
+      return ShrinkWrap.create("defaultlocaletest.jar", JavaArchive.class).addClasses(MockLogger.class, DefaultLocaleProducer.class).addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml"));
+   }
+
+   @Inject
+   Locale lc;
+
+   @Test
+   public void testDefaultLocaleProducerDirect()
+   {
+      Assert.assertNotNull(lc);
+   }
+}

Added: modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/UserLocaleTest.java
===================================================================
--- modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/UserLocaleTest.java	                        (rev 0)
+++ modules/international/trunk/impl/src/test/java/org/jboss/seam/international/test/locale/UserLocaleTest.java	2010-05-25 20:40:09 UTC (rev 12797)
@@ -0,0 +1,83 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.international.test.locale;
+
+import java.util.Locale;
+
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.international.Changed;
+import org.jboss.seam.international.locale.DefaultLocaleProducer;
+import org.jboss.seam.international.locale.UserLocale;
+import org.jboss.seam.international.locale.UserLocaleProducer;
+import org.jboss.seam.international.test.MockLogger;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+ at RunWith(Arquillian.class)
+public class UserLocaleTest
+{
+   @Deployment
+   public static JavaArchive createTestArchive()
+   {
+      return ShrinkWrap.create("userlocaletest.jar", JavaArchive.class).addClasses(MockLogger.class, UserLocaleProducer.class, UserLocale.class, DefaultLocaleProducer.class).addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml"));
+   }
+
+   @Inject
+   @UserLocale
+   Locale locale;
+
+   @Inject
+   @Changed
+   Event<Locale> localeEvent;
+
+   @Inject
+   @UserLocale
+   Instance<Locale> localeSource;
+
+   @Test
+   public void testUserLocaleProducerDirect()
+   {
+      Assert.assertNotNull(locale);
+   }
+
+   @Test
+   public void testUserLocaleEvent()
+   {
+      Locale canada = Locale.CANADA;
+      Assert.assertNotNull(locale);
+      Assert.assertFalse(locale.equals(canada));
+      localeEvent.fire(canada);
+      Locale lc = localeSource.get();
+      Assert.assertNotNull(lc);
+      Assert.assertTrue(lc.equals(canada));
+   }
+}

Added: modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/locale/override-available.xml
===================================================================
--- modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/locale/override-available.xml	                        (rev 0)
+++ modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/locale/override-available.xml	2010-05-25 20:40:09 UTC (rev 12797)
@@ -0,0 +1,37 @@
+<!--
+JBoss, Home of Professional Open Source
+Copyright 2010, Red Hat, Inc., and individual contributors
+by the @authors tag. See the copyright.txt in the distribution for a
+full listing of individual contributors.
+
+This is free software; you can redistribute it and/or modify it
+under the terms of the GNU Lesser General Public License as
+published by the Free Software Foundation; either version 2.1 of
+the License, or (at your option) any later version.
+
+This software is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this software; if not, write to the Free
+Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+02110-1301 USA, or see the FSF site: http://www.fsf.org.
+-->
+<beans xmlns="http://java.sun.com/xml/ns/javaee"
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   xmlns:s="urn:java:seam:core" 
+   xmlns:lc="urn:java:org.jboss.seam.international.locale"
+   xsi:schemaLocation="
+      http://java.sun.com/xml/ns/javaee 
+      http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+
+    <lc:AvailableLocales>
+    	<s:specializes/>
+        <lc:supportedLocaleKeys>
+            <s:value>en</s:value>
+            <s:value>fr</s:value>
+        </lc:supportedLocaleKeys>
+    </lc:AvailableLocales>
+</beans>
\ No newline at end of file

Added: modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/locale/override-fail.xml
===================================================================
--- modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/locale/override-fail.xml	                        (rev 0)
+++ modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/locale/override-fail.xml	2010-05-25 20:40:09 UTC (rev 12797)
@@ -0,0 +1,34 @@
+<!--
+JBoss, Home of Professional Open Source
+Copyright 2010, Red Hat, Inc., and individual contributors
+by the @authors tag. See the copyright.txt in the distribution for a
+full listing of individual contributors.
+
+This is free software; you can redistribute it and/or modify it
+under the terms of the GNU Lesser General Public License as
+published by the Free Software Foundation; either version 2.1 of
+the License, or (at your option) any later version.
+
+This software is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this software; if not, write to the Free
+Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+02110-1301 USA, or see the FSF site: http://www.fsf.org.
+-->
+<beans xmlns="http://java.sun.com/xml/ns/javaee"
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   xmlns:s="urn:java:seam:core" 
+   xmlns:lc="urn:java:org.jboss.seam.international.locale"
+   xsi:schemaLocation="
+      http://java.sun.com/xml/ns/javaee 
+      http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+
+    <lc:DefaultLocaleProducer>
+    	<s:specializes/>
+        <lc:defaultLocaleKey>z</lc:defaultLocaleKey>
+    </lc:DefaultLocaleProducer>
+</beans>
\ No newline at end of file

Added: modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/locale/override-lang-country-variant.xml
===================================================================
--- modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/locale/override-lang-country-variant.xml	                        (rev 0)
+++ modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/locale/override-lang-country-variant.xml	2010-05-25 20:40:09 UTC (rev 12797)
@@ -0,0 +1,34 @@
+<!--
+JBoss, Home of Professional Open Source
+Copyright 2010, Red Hat, Inc., and individual contributors
+by the @authors tag. See the copyright.txt in the distribution for a
+full listing of individual contributors.
+
+This is free software; you can redistribute it and/or modify it
+under the terms of the GNU Lesser General Public License as
+published by the Free Software Foundation; either version 2.1 of
+the License, or (at your option) any later version.
+
+This software is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this software; if not, write to the Free
+Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+02110-1301 USA, or see the FSF site: http://www.fsf.org.
+-->
+<beans xmlns="http://java.sun.com/xml/ns/javaee"
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   xmlns:s="urn:java:seam:core" 
+   xmlns:lc="urn:java:org.jboss.seam.international.locale"
+   xsi:schemaLocation="
+      http://java.sun.com/xml/ns/javaee 
+      http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+
+    <lc:DefaultLocaleProducer>
+    	<s:specializes/>
+        <lc:defaultLocaleKey>en_US_UNIX</lc:defaultLocaleKey>
+    </lc:DefaultLocaleProducer>
+</beans>
\ No newline at end of file

Added: modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/locale/override-lang-country.xml
===================================================================
--- modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/locale/override-lang-country.xml	                        (rev 0)
+++ modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/locale/override-lang-country.xml	2010-05-25 20:40:09 UTC (rev 12797)
@@ -0,0 +1,34 @@
+<!--
+JBoss, Home of Professional Open Source
+Copyright 2010, Red Hat, Inc., and individual contributors
+by the @authors tag. See the copyright.txt in the distribution for a
+full listing of individual contributors.
+
+This is free software; you can redistribute it and/or modify it
+under the terms of the GNU Lesser General Public License as
+published by the Free Software Foundation; either version 2.1 of
+the License, or (at your option) any later version.
+
+This software is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this software; if not, write to the Free
+Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+02110-1301 USA, or see the FSF site: http://www.fsf.org.
+-->
+<beans xmlns="http://java.sun.com/xml/ns/javaee"
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   xmlns:s="urn:java:seam:core" 
+   xmlns:lc="urn:java:org.jboss.seam.international.locale"
+   xsi:schemaLocation="
+      http://java.sun.com/xml/ns/javaee 
+      http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+
+    <lc:DefaultLocaleProducer>
+    	<s:specializes/>
+        <lc:defaultLocaleKey>en_US</lc:defaultLocaleKey>
+    </lc:DefaultLocaleProducer>
+</beans>
\ No newline at end of file

Added: modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/locale/override-lang.xml
===================================================================
--- modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/locale/override-lang.xml	                        (rev 0)
+++ modules/international/trunk/impl/src/test/resources/org/jboss/seam/international/test/locale/override-lang.xml	2010-05-25 20:40:09 UTC (rev 12797)
@@ -0,0 +1,34 @@
+<!--
+JBoss, Home of Professional Open Source
+Copyright 2010, Red Hat, Inc., and individual contributors
+by the @authors tag. See the copyright.txt in the distribution for a
+full listing of individual contributors.
+
+This is free software; you can redistribute it and/or modify it
+under the terms of the GNU Lesser General Public License as
+published by the Free Software Foundation; either version 2.1 of
+the License, or (at your option) any later version.
+
+This software is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this software; if not, write to the Free
+Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+02110-1301 USA, or see the FSF site: http://www.fsf.org.
+-->
+<beans xmlns="http://java.sun.com/xml/ns/javaee"
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   xmlns:s="urn:java:seam:core" 
+   xmlns:lc="urn:java:org.jboss.seam.international.locale"
+   xsi:schemaLocation="
+      http://java.sun.com/xml/ns/javaee 
+      http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+
+    <lc:DefaultLocaleProducer>
+    	<s:specializes/>
+        <lc:defaultLocaleKey>fr</lc:defaultLocaleKey>
+    </lc:DefaultLocaleProducer>
+</beans>
\ No newline at end of file



More information about the seam-commits mailing list