Class LocaleUtil


  • public class LocaleUtil
    extends java.lang.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 java.util.Locale parseLocale​(java.lang.String locale)
      See parseLocale(String, String) for details.
      static java.util.Locale parseLocale​(java.lang.String locale, java.lang.String variant)
      Parses the given locale string into its language and (optionally) country components, and returns the corresponding Locale object.
      static java.util.Locale parseLocaleAttributeValue​(java.lang.Object stringOrLocale)
      Handles Locales that can be passed to tags as instances of String or Locale.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LocaleUtil

        public LocaleUtil()
    • Method Detail

      • parseLocaleAttributeValue

        public static java.util.Locale parseLocaleAttributeValue​(java.lang.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 java.util.Locale parseLocale​(java.lang.String locale)
        See parseLocale(String, String) for details.
      • parseLocale

        public static java.util.Locale parseLocale​(java.lang.String locale,
                                                   java.lang.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:
        java.lang.IllegalArgumentException - if the given locale does not have a language component or has an empty country component