|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.context.i18n.LocaleContextHolder
public abstract class LocaleContextHolder
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.
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 |
resetLocaleContext()
Reset the LocaleContext for the current thread. |
static void |
setLocale(Locale locale)
Associate the given Locale with the current thread. |
static void |
setLocale(Locale locale,
boolean inheritable)
Associate the given Locale with the current thread. |
static void |
setLocaleContext(LocaleContext localeContext)
Associate the given LocaleContext with the current thread, not exposing it as inheritable for child threads. |
static void |
setLocaleContext(LocaleContext localeContext,
boolean inheritable)
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 |
---|
public LocaleContextHolder()
Method Detail |
---|
public static void resetLocaleContext()
public static void setLocaleContext(LocaleContext localeContext)
localeContext
- the current LocaleContext, or null
to reset
the thread-bound contextpublic static void setLocaleContext(LocaleContext localeContext, boolean inheritable)
localeContext
- the current LocaleContext, or null
to reset
the thread-bound contextinheritable
- whether to expose the LocaleContext as inheritable
for child threads (using an InheritableThreadLocal
)public static LocaleContext getLocaleContext()
null
if nonepublic static void setLocale(Locale locale)
Will implicitly create a LocaleContext for the given Locale, not exposing it as inheritable for child threads.
locale
- the current Locale, or null
to reset
the thread-bound contextSimpleLocaleContext.SimpleLocaleContext(java.util.Locale)
public static void setLocale(Locale locale, boolean inheritable)
Will implicitly create a LocaleContext for the given Locale.
locale
- the current Locale, or null
to reset
the thread-bound contextinheritable
- whether to expose the LocaleContext as inheritable
for child threads (using an InheritableThreadLocal
)SimpleLocaleContext.SimpleLocaleContext(java.util.Locale)
public static Locale getLocale()
LocaleContext.getLocale()
,
Locale.getDefault()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |