Package com.aspectran.core.util
Class LocaleUtils
- java.lang.Object
-
- com.aspectran.core.util.LocaleUtils
-
public class LocaleUtils extends java.lang.Object
This 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.Locale
parseLocale(java.lang.String localeValue)
Parse the givenString
value into aLocale
, accepting theLocale.toString()
format as well as BCP 47 language tags.static java.util.Locale
parseLocaleString(java.lang.String localeString)
Parse the givenString
representation into aLocale
.static java.util.TimeZone
parseTimeZoneString(java.lang.String timeZoneString)
Parse the giventimeZoneString
value into aTimeZone
.
-
-
-
Method Detail
-
parseLocale
public static java.util.Locale parseLocale(java.lang.String localeValue)
Parse the givenString
value into aLocale
, accepting theLocale.toString()
format as well as BCP 47 language tags.- Parameters:
localeValue
- the locale value: following eitherLocale's
toString()
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
Locale
instance, ornull
if 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 givenString
representation 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 strictLocale
design 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's
toString()
format ("en", "en_UK", etc), also accepting spaces as separators (as an alternative to underscores)- Returns:
- a corresponding
Locale
instance, ornull
if 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 giventimeZoneString
value into aTimeZone
.- Parameters:
timeZoneString
- the time zoneString
, followingTimeZone.getTimeZone(String)
but throwingIllegalArgumentException
in case of an invalid time zone specification- Returns:
- a corresponding
TimeZone
instance - Throws:
java.lang.IllegalArgumentException
- in case of an invalid time zone specification
-
-