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 default theme. This is especially useful for stateless applications without user sessions.

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

Since:
17.06.2003
Author:
Jean-Pierre Pawlak, Juergen Hoeller
See Also:
setThemeName(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String)

Field Summary
static int DEFAULT_COOKIE_MAX_AGE
           
static String DEFAULT_COOKIE_NAME
           
static String DEFAULT_COOKIE_PATH
           
static 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()
          Return the maximum age for locale cookies.
 String getCookieName()
          Return the name for theme cookies.
 String getCookiePath()
          Return the path for theme cookies.
 String resolveThemeName(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(String cookieName)
          Use the given name for theme cookies, containing the theme name.
 void setCookiePath(String cookiePath)
          Use the given path for theme cookies.
 void setThemeName(HttpServletRequest request, HttpServletResponse response, String themeName)
          Set the current theme name to the given one.
 
Methods inherited from class org.springframework.web.servlet.theme.AbstractThemeResolver
getDefaultThemeName, 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 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 String DEFAULT_COOKIE_NAME

DEFAULT_COOKIE_PATH

public static final 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(String cookieName)
Use the given name for theme cookies, containing the theme name.


getCookieName

public String getCookieName()
Return the name for theme cookies.


setCookiePath

public void setCookiePath(String cookiePath)
Use the given path for theme cookies. The cookie is only visible for URLs in the path and below.


getCookiePath

public String getCookiePath()
Return the path for theme cookies.


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()
Return the maximum age for locale cookies.


resolveThemeName

public String resolveThemeName(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(HttpServletRequest request,
                         HttpServletResponse response,
                         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.