Class LocaleContextHolder


  • public final class LocaleContextHolder
    extends Object
    Simple holder class that associates a LocaleContext instance with the current thread. The LocaleContext will be inherited by any child threads spawned by the current thread if the inheritable flag is set to true.

    Used as a central holder for the current Locale in Spring, wherever necessary: for example, in MessageSourceAccessor. DispatcherServlet automatically exposes its current Locale here. Other applications can expose theirs too, to make classes like MessageSourceAccessor automatically use that Locale.

    Since:
    1.2
    Author:
    Juergen Hoeller, Nicholas Williams
    See Also:
    LocaleContext, MessageSourceAccessor, DispatcherServlet
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and TypeMethodDescription
      static LocalegetLocale()
      Return the Locale associated with the current thread, if any, or the system default Locale otherwise.
      static LocalegetLocale​(LocaleContext localeContext)
      Return the Locale associated with the given user context, if any, or the system default Locale otherwise.
      static LocaleContextgetLocaleContext()
      Return the LocaleContext associated with the current thread, if any.
      static TimeZonegetTimeZone()
      Return the TimeZone associated with the current thread, if any, or the system default TimeZone otherwise.
      static TimeZonegetTimeZone​(LocaleContext localeContext)
      Return the TimeZone associated with the given user context, if any, or the system default TimeZone otherwise.
      static voidresetLocaleContext()
      Reset the LocaleContext for the current thread.
      static voidsetDefaultLocale​(Locale locale)
      Set a shared default locale at the framework level, as an alternative to the JVM-wide default locale.
      static voidsetDefaultTimeZone​(TimeZone timeZone)
      Set a shared default time zone at the framework level, as an alternative to the JVM-wide default time zone.
      static voidsetLocale​(Locale locale)
      Associate the given Locale with the current thread, preserving any TimeZone that may have been set already.
      static voidsetLocale​(Locale locale, boolean inheritable)
      Associate the given Locale with the current thread, preserving any TimeZone that may have been set already.
      static voidsetLocaleContext​(LocaleContext localeContext)
      Associate the given LocaleContext with the current thread, not exposing it as inheritable for child threads.
      static voidsetLocaleContext​(LocaleContext localeContext, boolean inheritable)
      Associate the given LocaleContext with the current thread.
      static voidsetTimeZone​(TimeZone timeZone)
      Associate the given TimeZone with the current thread, preserving any Locale that may have been set already.
      static voidsetTimeZone​(TimeZone timeZone, boolean inheritable)
      Associate the given TimeZone with the current thread, preserving any Locale that may have been set already.