Class LocaleUtil
- java.lang.Object
-
- org.apache.taglibs.standard.tag.common.fmt.LocaleUtil
-
public class LocaleUtil extends Object
Utility functions for working with Locales. This implementation sticks with the Locale parsing rules defined by the JSTL Specification. When permitted, this should be updated to use the richer Locale parsing rules provided in Java 7 and later.
-
-
Constructor Summary
Constructors Constructor Description LocaleUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Locale
parseLocale(String locale)
See parseLocale(String, String) for details.static Locale
parseLocale(String locale, String variant)
Parses the given locale string into its language and (optionally) country components, and returns the correspondingLocale
object.static Locale
parseLocaleAttributeValue(Object stringOrLocale)
Handles Locales that can be passed to tags as instances of String or Locale.
-
-
-
Method Detail
-
parseLocaleAttributeValue
public static Locale parseLocaleAttributeValue(Object stringOrLocale)
Handles Locales that can be passed to tags as instances of String or Locale. If the parameter is an instance of Locale, it is simply returned. If the parameter is a String and is not empty, then it is parsed to a Locale usingparseLocale(String)
. Otherwise null will be returned.- Parameters:
stringOrLocale
- locale represented as an instance of Locale or as a String- Returns:
- the locale represented by the parameter, or null if the parameter is undefined
-
parseLocale
public static Locale parseLocale(String locale)
See parseLocale(String, String) for details.
-
parseLocale
public static Locale parseLocale(String locale, String variant)
Parses the given locale string into its language and (optionally) country components, and returns the correspondingLocale
object.- Parameters:
locale
- the locale string to parse; must not be null or emptyvariant
- the variant- Returns:
- the specified Locale
- Throws:
IllegalArgumentException
- if the given locale does not have a language component or has an empty country component
-
-