Package com.aspectran.utils
Class LocaleUtils
java.lang.Object
com.aspectran.utils.LocaleUtils
This class has utility methods useful for parsing locale and timezone strings.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Locale
parseLocale
(String localeValue) Parse the givenString
value into aLocale
, accepting theLocale.toString()
format as well as BCP 47 language tags.static Locale
parseLocaleString
(String localeString) Parse the givenString
representation into aLocale
.static TimeZone
parseTimeZoneString
(String timeZoneString) Parse the giventimeZoneString
value into aTimeZone
.
-
Constructor Details
-
LocaleUtils
public LocaleUtils()
-
-
Method Details
-
parseLocale
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:
IllegalArgumentException
- in case of an invalid locale specification- See Also:
-
parseLocaleString
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:
IllegalArgumentException
- in case of an invalid locale specification
-
parseTimeZoneString
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:
IllegalArgumentException
- in case of an invalid time zone specification
-