org.springframework.context.i18n
Class LocaleContextHolder

java.lang.Object
  extended by org.springframework.context.i18n.LocaleContextHolder

public abstract 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.

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
See Also:
LocaleContext, MessageSourceAccessor, DispatcherServlet

Constructor Summary
LocaleContextHolder()
           
 
Method Summary
static Locale getLocale()
          Return the Locale associated with the current thread, if any, or the system default Locale else.
static LocaleContext getLocaleContext()
          Return the LocaleContext associated with the current thread, if any.
static void setLocale(Locale locale)
          Associate the given Locale with the current thread.
static void setLocaleContext(LocaleContext localeContext)
          Associate the given LocaleContext with the current thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocaleContextHolder

public LocaleContextHolder()
Method Detail

setLocaleContext

public static void setLocaleContext(LocaleContext localeContext)
Associate the given LocaleContext with the current thread.

Parameters:
localeContext - the current LocaleContext, or null to reset the thread-bound context

getLocaleContext

public static LocaleContext getLocaleContext()
Return the LocaleContext associated with the current thread, if any.

Returns:
the current LocaleContext, or null if none

setLocale

public static void setLocale(Locale locale)
Associate the given Locale with the current thread. Will implicitly create a LocaleContext for the given Locale.

Parameters:
locale - the current Locale, or null to reset the thread-bound context
See Also:
SimpleLocaleContext.SimpleLocaleContext(java.util.Locale)

getLocale

public static Locale getLocale()
Return the Locale associated with the current thread, if any, or the system default Locale else.

Returns:
the current Locale, or the system default Locale if no specific Locale has been associated with the current thread
See Also:
LocaleContext.getLocale(), Locale.getDefault()


Copyright (c) 2002-2006 The Spring Framework Project.