Class 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 Detail

      • LocaleUtil

        public LocaleUtil()
    • 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 using parseLocale(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 corresponding Locale object.
        Parameters:
        locale - the locale string to parse; must not be null or empty
        variant - the variant
        Returns:
        the specified Locale
        Throws:
        IllegalArgumentException - if the given locale does not have a language component or has an empty country component