@Override public void setThemeName( HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable String themeName) { Assert.notNull(response, "HttpServletResponse is required for CookieThemeResolver"); if (StringUtils.hasText(themeName)) { // Set request attribute and add cookie. request.setAttribute(THEME_REQUEST_ATTRIBUTE_NAME, themeName); addCookie(response, themeName); } else { // Set request attribute to fallback theme and remove cookie. request.setAttribute(THEME_REQUEST_ATTRIBUTE_NAME, getDefaultThemeName()); removeCookie(response); } }
@Override public String resolveThemeName(HttpServletRequest request) { // Check request for preparsed or preset theme. String themeName = (String) request.getAttribute(THEME_REQUEST_ATTRIBUTE_NAME); if (themeName != null) { return themeName; } // Retrieve cookie value from request. String cookieName = getCookieName(); if (cookieName != null) { Cookie cookie = WebUtils.getCookie(request, cookieName); if (cookie != null) { String value = cookie.getValue(); if (StringUtils.hasText(value)) { themeName = value; } } } // Fall back to default theme. if (themeName == null) { themeName = getDefaultThemeName(); } request.setAttribute(THEME_REQUEST_ATTRIBUTE_NAME, themeName); return themeName; }
@Override public void setThemeName( HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable String themeName) { Assert.notNull(response, "HttpServletResponse is required for CookieThemeResolver"); if (StringUtils.hasText(themeName)) { // Set request attribute and add cookie. request.setAttribute(THEME_REQUEST_ATTRIBUTE_NAME, themeName); addCookie(response, themeName); } else { // Set request attribute to fallback theme and remove cookie. request.setAttribute(THEME_REQUEST_ATTRIBUTE_NAME, getDefaultThemeName()); removeCookie(response); } }
@Override public String resolveThemeName(HttpServletRequest request) { // Check request for preparsed or preset theme. String themeName = (String) request.getAttribute(THEME_REQUEST_ATTRIBUTE_NAME); if (themeName != null) { return themeName; } // Retrieve cookie value from request. String cookieName = getCookieName(); if (cookieName != null) { Cookie cookie = WebUtils.getCookie(request, cookieName); if (cookie != null) { String value = cookie.getValue(); if (StringUtils.hasText(value)) { themeName = value; } } } // Fall back to default theme. if (themeName == null) { themeName = getDefaultThemeName(); } request.setAttribute(THEME_REQUEST_ATTRIBUTE_NAME, themeName); return themeName; }
@Override public void setThemeName(HttpServletRequest request, HttpServletResponse response, String themeName) { if (StringUtils.hasText(themeName)) { // Set request attribute and add cookie. request.setAttribute(THEME_REQUEST_ATTRIBUTE_NAME, themeName); addCookie(response, themeName); } else { // Set request attribute to fallback theme and remove cookie. request.setAttribute(THEME_REQUEST_ATTRIBUTE_NAME, getDefaultThemeName()); removeCookie(response); } }