org.springframework.web.servlet.theme

## Class CookieThemeResolver

- java.lang.Object
- - org.springframework.web.util.CookieGenerator
  - - org.springframework.web.servlet.theme.CookieThemeResolver

- All Implemented Interfaces:
    ThemeResolver

      public class CookieThemeResolver
      extends CookieGenerator
      implements ThemeResolver

  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 particularly 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

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `DEFAULT_COOKIE_NAME`
    `static String` | `ORIGINAL_DEFAULT_THEME_NAME`
    `static String` | `THEME_REQUEST_ATTRIBUTE_NAME` Name of the request attribute that holds the theme name.

    - ### Fields inherited from class org.springframework.web.util.CookieGenerator

      `DEFAULT_COOKIE_MAX_AGE, DEFAULT_COOKIE_PATH, logger`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CookieThemeResolver()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `getDefaultThemeName()` Return the name of the default theme.
    `String` | `resolveThemeName(HttpServletRequest request)` Resolve the current theme name via the given request.
    `void` | `setDefaultThemeName(String defaultThemeName)` Set the name of the default theme.
    `void` | `setThemeName(HttpServletRequest request, HttpServletResponse response, String themeName)` Set the current theme name to the given one.

    - ### Methods inherited from class org.springframework.web.util.CookieGenerator

      `addCookie, createCookie, getCookieDomain, getCookieMaxAge, getCookieName, getCookiePath, isCookieHttpOnly, isCookieSecure, removeCookie, setCookieDomain, setCookieHttpOnly, setCookieMaxAge, setCookieName, setCookiePath, setCookieSecure`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### ORIGINAL_DEFAULT_THEME_NAME

          public static final String ORIGINAL_DEFAULT_THEME_NAME

      See Also:
        Constant Field Values

    - #### 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

  - ### Constructor Detail

    - #### CookieThemeResolver

          public CookieThemeResolver()

  - ### Method Detail

    - #### setDefaultThemeName

          public void setDefaultThemeName(String defaultThemeName)

      Set the name of the default theme.

    - #### getDefaultThemeName

          public String getDefaultThemeName()

      Return the name of the default theme.

    - #### 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.
      Specified by:
        `resolveThemeName` in interface `ThemeResolver`
      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.
      Specified by:
        `setThemeName` in interface `ThemeResolver`
      Parameters:
        `request` - request to be used for theme name modification
        `response` - response to be used for theme name modification
        `themeName` - the new theme name