|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.web.servlet.i18n.CookieLocaleResolver
Implementation of LocaleResolver that uses a cookie sent back to the user in case of a custom setting, with a fallback to the accept header locale. This is especially useful for stateless applications without user sessions.
Custom controllers can thus override the user's locale by calling
setLocale
, e.g. responding to a certain locale change request.
setLocale(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.util.Locale)
Field Summary | |
static int |
DEFAULT_COOKIE_MAX_AGE
|
static String |
DEFAULT_COOKIE_NAME
|
static String |
DEFAULT_COOKIE_PATH
|
static String |
LOCALE_REQUEST_ATTRIBUTE_NAME
Name of the request attribute that holds the locale. |
Constructor Summary | |
CookieLocaleResolver()
|
Method Summary | |
int |
getCookieMaxAge()
Return the maximum age for locale cookies. |
String |
getCookieName()
Return the given name for locale cookies. |
String |
getCookiePath()
Return the path for locale cookies. |
Locale |
resolveLocale(HttpServletRequest request)
Resolve the current locale via the given request. |
void |
setCookieMaxAge(int cookieMaxAge)
Use the given maximum age, specified in seconds, for locale cookies. |
void |
setCookieName(String cookieName)
Use the given name for locale cookies. |
void |
setCookiePath(String cookiePath)
Use the given path for locale cookies. |
void |
setLocale(HttpServletRequest request,
HttpServletResponse response,
Locale locale)
Set the current locale to the given one. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String LOCALE_REQUEST_ATTRIBUTE_NAME
RequestContext.getLocale()
public static final String DEFAULT_COOKIE_NAME
public static final String DEFAULT_COOKIE_PATH
public static final int DEFAULT_COOKIE_MAX_AGE
Constructor Detail |
public CookieLocaleResolver()
Method Detail |
public void setCookieName(String cookieName)
public String getCookieName()
public void setCookiePath(String cookiePath)
public String getCookiePath()
public void setCookieMaxAge(int cookieMaxAge)
public int getCookieMaxAge()
public Locale resolveLocale(HttpServletRequest request)
LocaleResolver
resolveLocale
in interface LocaleResolver
request
- request to be used for resolution
public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale)
LocaleResolver
setLocale
in interface LocaleResolver
request
- request to be used for locale modificationresponse
- response to be used for locale modificationlocale
- the new locale
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |