类 SessionLocaleResolver
- 所有已实现的接口:
LocaleContextResolver,LocaleResolver
LocaleResolver implementation that
uses a locale attribute in the user's session in case of a custom setting,
with a fallback to the configured default locale, the request's
Accept-Language header, or the default locale for the server.
This is most appropriate if the application needs user sessions anyway,
i.e. when the HttpSession does not have to be created just for storing
the user's locale. The session may optionally contain an associated time zone
attribute as well; alternatively, you may specify a default time zone.
In contrast to CookieLocaleResolver, this strategy stores locally
chosen locale settings in the Servlet container's HttpSession. As a
consequence, those settings are just temporary for each session and therefore
lost when each session terminates.
Note that there is no direct relationship with external session management
mechanisms such as the "Session" project. This LocaleResolver
will simply evaluate and modify corresponding HttpSession attributes
against the current RequestContext.
- 从以下版本开始:
- 4.0
- 作者:
- Juergen Hoeller
- 另请参阅:
-
字段概要
字段修饰符和类型字段说明static final StringDefault name of the session attribute that holds the Locale.private Stringprivate SessionManagerstatic final StringDefault name of the session attribute that holds the TimeZone.private String从接口继承的字段 cn.taketoday.web.LocaleResolver
BEAN_NAME -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected LocaledetermineDefaultLocale(RequestContext request) Determine the default locale for the given request, called if noLocalesession attribute has been found.protected TimeZonedetermineDefaultTimeZone(RequestContext request) Determine the default time zone for the given request, called if noTimeZonesession attribute has been found.private <T> TgetSessionAttribute(RequestContext request, String attributeName) private SessionManagergetSessionManager(RequestContext request) resolveLocale(RequestContext request) Resolve the current locale via the given request.cn.taketoday.core.i18n.LocaleContextresolveLocaleContext(RequestContext request) Resolve the current locale context via the given request.voidsetLocaleAttributeName(String localeAttributeName) Specify the name of the corresponding attribute in theHttpSession, holding the currentLocalevalue.voidsetLocaleContext(RequestContext request, cn.taketoday.core.i18n.LocaleContext localeContext) Set the current locale context to the given one, potentially including a locale with associated time zone information.private voidsetSessionAttribute(RequestContext request, String attributeName, Object attribute) voidsetSessionManager(SessionManager sessionManager) voidsetTimeZoneAttributeName(String timeZoneAttributeName) Specify the name of the corresponding attribute in theHttpSession, holding the currentTimeZonevalue.从类继承的方法 cn.taketoday.web.i18n.AbstractLocaleContextResolver
getDefaultTimeZone, setDefaultTimeZone, setLocale从类继承的方法 cn.taketoday.web.i18n.AbstractLocaleResolver
getDefaultLocale, setDefaultLocale
-
字段详细资料
-
LOCALE_SESSION_ATTRIBUTE_NAME
Default name of the session attribute that holds the Locale. Only used internally by this implementation.Use
RequestContext(Utils).getLocale()to retrieve the current locale in controllers or views. -
TIME_ZONE_SESSION_ATTRIBUTE_NAME
Default name of the session attribute that holds the TimeZone. Only used internally by this implementation.Use
RequestContext(Utils).getTimeZone()to retrieve the current time zone in controllers or views. -
localeAttributeName
-
timeZoneAttributeName
-
sessionManager
-
-
构造器详细资料
-
SessionLocaleResolver
public SessionLocaleResolver()
-
-
方法详细资料
-
setLocaleAttributeName
Specify the name of the corresponding attribute in theHttpSession, holding the currentLocalevalue.The default is an internal
LOCALE_SESSION_ATTRIBUTE_NAME. -
setTimeZoneAttributeName
Specify the name of the corresponding attribute in theHttpSession, holding the currentTimeZonevalue.The default is an internal
TIME_ZONE_SESSION_ATTRIBUTE_NAME. -
setSessionManager
-
getSessionManager
-
resolveLocale
从接口复制的说明:LocaleResolverResolve the current locale via the given request. Can return a default locale as fallback in any case.- 指定者:
resolveLocale在接口中LocaleResolver- 覆盖:
resolveLocale在类中AbstractLocaleContextResolver- 参数:
request- the request to resolve the locale for- 返回:
- the current locale (never
null)
-
resolveLocaleContext
从接口复制的说明:LocaleContextResolverResolve the current locale context via the given request.This is primarily intended for framework-level processing; consider using
RequestContextUtilsorRequestContextfor application-level access to the current locale and/or time zone.The returned context may be a
TimeZoneAwareLocaleContext, containing a locale with associated time zone information. Simply apply aninstanceofcheck and downcast accordingly.Custom resolver implementations may also return extra settings in the returned context, which again can be accessed through downcasting.
- 参数:
request- the request to resolve the locale context for- 返回:
- the current locale context (never
null - 另请参阅:
-
setLocaleContext
public void setLocaleContext(RequestContext request, @Nullable cn.taketoday.core.i18n.LocaleContext localeContext) 从接口复制的说明:LocaleContextResolverSet the current locale context to the given one, potentially including a locale with associated time zone information.- 参数:
request- the request to be used for locale modificationlocaleContext- the new locale context, ornullto clear the locale- 另请参阅:
-
LocaleResolver.setLocale(RequestContext, Locale)SimpleLocaleContextSimpleTimeZoneAwareLocaleContext
-
getSessionAttribute
-
setSessionAttribute
private void setSessionAttribute(RequestContext request, String attributeName, @Nullable Object attribute) -
getSessionManager
-
determineDefaultLocale
Determine the default locale for the given request, called if noLocalesession attribute has been found.The default implementation returns the configured default locale, if any, and otherwise falls back to the request's
Accept-Languageheader locale or the default locale for the server.- 参数:
request- the request to resolve the locale for- 返回:
- the default locale (never
null) - 另请参阅:
-
determineDefaultTimeZone
Determine the default time zone for the given request, called if noTimeZonesession attribute has been found.The default implementation returns the configured default time zone, if any, or
nullotherwise.- 参数:
request- the request to resolve the time zone for- 返回:
- the default time zone (or
nullif none defined) - 另请参阅:
-