Class LocaleUtils

java.lang.Object
com.aspectran.utils.LocaleUtils

public class LocaleUtils extends Object
This class has utility methods useful for parsing locale and timezone strings.
  • Constructor Details

    • LocaleUtils

      public LocaleUtils()
  • Method Details

    • parseLocale

      public static Locale parseLocale(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:
      IllegalArgumentException - in case of an invalid locale specification
      See Also:
    • parseLocaleString

      public static Locale parseLocaleString(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:
      IllegalArgumentException - in case of an invalid locale specification
    • parseTimeZoneString

      @NonNull public static TimeZone parseTimeZoneString(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:
      IllegalArgumentException - in case of an invalid time zone specification