Class 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 given String value into a Locale, accepting the Locale.toString() format as well as BCP 47 language tags.
      static java.util.Locale parseLocaleString​(java.lang.String localeString)
      Parse the given String representation into a Locale.
      static java.util.TimeZone parseTimeZoneString​(java.lang.String timeZoneString)
      Parse the given timeZoneString value into a TimeZone.
      • Methods inherited from class java.lang.Object

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

      • LocaleUtils

        public LocaleUtils()
    • Method Detail

      • parseLocale

        public static java.util.Locale parseLocale​(java.lang.String localeValue)
        Parse the given String value into a Locale, accepting the Locale.toString() format as well as BCP 47 language tags.
        Parameters:
        localeValue - the locale value: following either Locale'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 by Locale.forLanguageTag(java.lang.String) on Java 7+
        Returns:
        a corresponding Locale instance, or null 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 given String representation into a Locale.

        For many parsing scenarios, this is an inverse operation of Locale's toString, in a lenient sense. This method does not aim for strict Locale 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 locale String: following Locale's toString() format ("en", "en_UK", etc), also accepting spaces as separators (as an alternative to underscores)
        Returns:
        a corresponding Locale instance, or null 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 given timeZoneString value into a TimeZone.
        Parameters:
        timeZoneString - the time zone String, following TimeZone.getTimeZone(String) but throwing IllegalArgumentException 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