Package com.aspectran.core.util
Class LocaleUtils
- java.lang.Object
-
- com.aspectran.core.util.LocaleUtils
-
public class LocaleUtils extends java.lang.ObjectThis class has utility methods useful for parsing locale and timezone strings.
-
-
Constructor Summary
Constructors Constructor Description LocaleUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.LocaleparseLocale(java.lang.String localeValue)Parse the givenStringvalue into aLocale, accepting theLocale.toString()format as well as BCP 47 language tags.static java.util.LocaleparseLocaleString(java.lang.String localeString)Parse the givenStringrepresentation into aLocale.static java.util.TimeZoneparseTimeZoneString(java.lang.String timeZoneString)Parse the giventimeZoneStringvalue into aTimeZone.
-
-
-
Method Detail
-
parseLocale
public static java.util.Locale parseLocale(java.lang.String localeValue)
Parse the givenStringvalue into aLocale, accepting theLocale.toString()format as well as BCP 47 language tags.- Parameters:
localeValue- the locale value: following eitherLocale'stoString()format ("en", "en_UK", etc), also accepting spaces as separators (as an alternative to underscores), or BCP 47 (e.g. "en-UK") as specified byLocale.forLanguageTag(java.lang.String)on Java 7+- Returns:
- a corresponding
Localeinstance, ornullif none - Throws:
java.lang.IllegalArgumentException- in case of an invalid locale specification- See Also:
parseLocaleString(java.lang.String),Locale.forLanguageTag(java.lang.String)
-
parseLocaleString
public static java.util.Locale parseLocaleString(java.lang.String localeString)
Parse the givenStringrepresentation into aLocale.For many parsing scenarios, this is an inverse operation of
Locale's toString, in a lenient sense. This method does not aim for strictLocaledesign compliance; it is rather specifically tailored for typical Spring parsing needs.Note: This delegate does not accept the BCP 47 language tag format. Please use
parseLocale(java.lang.String)for lenient parsing of both formats.- Parameters:
localeString- the localeString: followingLocale'stoString()format ("en", "en_UK", etc), also accepting spaces as separators (as an alternative to underscores)- Returns:
- a corresponding
Localeinstance, ornullif none - Throws:
java.lang.IllegalArgumentException- in case of an invalid locale specification
-
parseTimeZoneString
public static java.util.TimeZone parseTimeZoneString(java.lang.String timeZoneString)
Parse the giventimeZoneStringvalue into aTimeZone.- Parameters:
timeZoneString- the time zoneString, followingTimeZone.getTimeZone(String)but throwingIllegalArgumentExceptionin case of an invalid time zone specification- Returns:
- a corresponding
TimeZoneinstance - Throws:
java.lang.IllegalArgumentException- in case of an invalid time zone specification
-
-