org.springframework.web.servlet.theme
Class CookieThemeResolver

java.lang.Object
  extended byorg.springframework.web.servlet.theme.AbstractThemeResolver
      extended byorg.springframework.web.servlet.theme.CookieThemeResolver
All Implemented Interfaces:
ThemeResolver

public class CookieThemeResolver
extends AbstractThemeResolver

Implementation of ThemeResolver that uses a cookie sent back to the user in case of a custom setting, with a fallback to the fixed locale. This is especially useful for stateless applications without user sessions.

Custom controllers can thus override the user's theme by calling setTheme, e.g. responding to a certain theme change request.

Since:
17.06.2003
Author:
Jean-Pierre Pawlak, Juergen Hoeller

Field Summary
static int DEFAULT_COOKIE_MAX_AGE
           
static java.lang.String DEFAULT_COOKIE_NAME
           
static java.lang.String DEFAULT_COOKIE_PATH
           
static java.lang.String THEME_REQUEST_ATTRIBUTE_NAME
          Name of the request attribute that holds the theme name.
 
Fields inherited from class org.springframework.web.servlet.theme.AbstractThemeResolver
ORIGINAL_DEFAULT_THEME_NAME
 
Constructor Summary
CookieThemeResolver()
           
 
Method Summary
 int getCookieMaxAge()
           
 java.lang.String getCookieName()
           
 java.lang.String getCookiePath()
          Use the given path for theme cookies.
 java.lang.String resolveThemeName(javax.servlet.http.HttpServletRequest request)
          Resolve the current theme name via the given request.
 void setCookieMaxAge(int cookieMaxAge)
          Use the given maximum age, specified in seconds, for locale cookies.
 void setCookieName(java.lang.String cookieName)
          Use the given name for theme cookies, containing the theme name.
 void setCookiePath(java.lang.String cookiePath)
           
 void setThemeName(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String themeName)
          Set the current theme name to the given one.
 
Methods inherited from class org.springframework.web.servlet.theme.AbstractThemeResolver
getDefaultThemeName, makeThemeNameAvailable, setDefaultThemeName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

THEME_REQUEST_ATTRIBUTE_NAME

public static final java.lang.String THEME_REQUEST_ATTRIBUTE_NAME
Name of the request attribute that holds the theme name. Only used for overriding a cookie value if the theme has been changed in the course of the current request! Use RequestContext.getTheme() to retrieve the current theme in controllers or views.

See Also:
RequestContext.getTheme()

DEFAULT_COOKIE_NAME

public static final java.lang.String DEFAULT_COOKIE_NAME

DEFAULT_COOKIE_PATH

public static final java.lang.String DEFAULT_COOKIE_PATH
See Also:
Constant Field Values

DEFAULT_COOKIE_MAX_AGE

public static final int DEFAULT_COOKIE_MAX_AGE
See Also:
Constant Field Values
Constructor Detail

CookieThemeResolver

public CookieThemeResolver()
Method Detail

setCookieName

public void setCookieName(java.lang.String cookieName)
Use the given name for theme cookies, containing the theme name.


getCookieName

public java.lang.String getCookieName()

getCookiePath

public java.lang.String getCookiePath()
Use the given path for theme cookies. The cookie is only visible for URLs in the path and below.


setCookiePath

public void setCookiePath(java.lang.String cookiePath)

setCookieMaxAge

public void setCookieMaxAge(int cookieMaxAge)
Use the given maximum age, specified in seconds, for locale cookies. Useful special value: -1 ... not persistent, deleted when client shuts down


getCookieMaxAge

public int getCookieMaxAge()

resolveThemeName

public java.lang.String resolveThemeName(javax.servlet.http.HttpServletRequest request)
Description copied from interface: ThemeResolver
Resolve the current theme name via the given request. Should return a default theme as fallback in any case.

Parameters:
request - request to be used for resolution
Returns:
the current theme name

setThemeName

public void setThemeName(javax.servlet.http.HttpServletRequest request,
                         javax.servlet.http.HttpServletResponse response,
                         java.lang.String themeName)
Description copied from interface: ThemeResolver
Set the current theme name to the given one.

Parameters:
request - request to be used for theme name modification
response - response to be used for theme name modification
themeName - the new theme name


Copyright (C) 2003-2004 The Spring Framework Project.