You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by or...@apache.org on 2005/09/01 03:02:51 UTC

svn commit: r265609 - /myfaces/share/trunk/src/java/org/apache/myfaces/util/LocaleUtils.java

Author: oros
Date: Wed Aug 31 18:02:47 2005
New Revision: 265609

URL: http://svn.apache.org/viewcvs?rev=265609&view=rev
Log:
fixed all signature issues so now all API classes/interfaces comply with the spec

Modified:
    myfaces/share/trunk/src/java/org/apache/myfaces/util/LocaleUtils.java

Modified: myfaces/share/trunk/src/java/org/apache/myfaces/util/LocaleUtils.java
URL: http://svn.apache.org/viewcvs/myfaces/share/trunk/src/java/org/apache/myfaces/util/LocaleUtils.java?rev=265609&r1=265608&r2=265609&view=diff
==============================================================================
--- myfaces/share/trunk/src/java/org/apache/myfaces/util/LocaleUtils.java (original)
+++ myfaces/share/trunk/src/java/org/apache/myfaces/util/LocaleUtils.java Wed Aug 31 18:02:47 2005
@@ -16,6 +16,7 @@
 package org.apache.myfaces.util;
 
 import java.util.Locale;
+import java.util.StringTokenizer;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -85,5 +86,41 @@
         }
 
         return new Locale(language, country, variant);
+    }
+
+
+    /**
+     * Convert locale string used by converter tags to locale.
+     *
+     * @param name name of the locale
+     * @return locale specified by the given String
+     *
+     * @see org.apache.myfaces.taglib.core.ConvertDateTimeTag#setConverterLocale
+     * @see org.apache.myfaces.taglib.core.ConvertNumberTag#setConverterLocale
+     */
+    public static Locale converterTagLocaleFromString(String name)
+    {
+        try
+        {
+            Locale locale;
+            StringTokenizer st = new StringTokenizer(name, "_");
+            String language = st.nextToken();
+            String country = st.nextToken();
+            if(st.hasMoreTokens())
+            {
+                String variant = st.nextToken();
+                locale = new Locale(language, country, variant);
+            }
+            else
+            {
+                locale = new Locale(language, country);
+            }
+            return locale;
+        }
+        catch(Exception e)
+        {
+            throw new IllegalArgumentException("Locale parsing exception - " +
+                "invalid string representation '" + name + "'");
+        }
     }
 }