org.jboss.seam.international.locale
Class LocaleUtils

java.lang.Object
  extended by org.jboss.seam.international.locale.LocaleUtils

public final class LocaleUtils
extends Object


Constructor Summary
LocaleUtils()
           
 
Method Summary
static Locale toLocale(String str)
           Converts a String to a Locale.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocaleUtils

public LocaleUtils()
Method Detail

toLocale

public static Locale toLocale(String str)

Converts a String to a Locale.

This method takes the string format of a locale and creates the locale object from it.

   LocaleUtils.toLocale("en")         = new Locale("en", "")
   LocaleUtils.toLocale("en_GB")      = new Locale("en", "GB")
   LocaleUtils.toLocale("en-GB")      = new Locale("en", "GB")
   LocaleUtils.toLocale("en_GB_xxx")  = new Locale("en", "GB", "xxx")   (#)
   LocaleUtils.toLocale("en-GB-xxx")  = new Locale("en", "GB", "xxx")   (#)
   LocaleUtils.toLocale("en__xxx")    = new Locale("en", "", "xxx")     (#)
   LocaleUtils.toLocale("en--xxx")    = new Locale("en", "", "xxx")     (#)
 

This method validates the input strictly. The language code must be lowercase. The country code must be uppercase. The separator must be an underscore or hyphen. The length must be correct.

Parameters:
str - the locale String to convert, null returns null
Returns:
a Locale, null if null input
Throws:
IllegalArgumentException - if the string is an invalid format


Copyright © 2011 Seam Framework. All Rights Reserved.