public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
      throws ServletException {
    boolean result = super.preHandle(request, response, handler);

    ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(request);

    String newTheme = themeResolver.resolveThemeName(request);

    if (!validThemes.contains(newTheme)) {
      // not found.
      logger.error("Invalid theme passed in: " + newTheme);
      try {
        response.sendRedirect("accessDenied.jsp");

        return false;
      } catch (IOException e) {
        throw new ServletException("Could not redirect to accessDenied page.", e);
      }
    } else if (request.getParameter(this.paramName) != null) {
      // found.  redirect to page without "param=.." extension.
      logger.warn("New theme set: " + newTheme + ".  Redirecting to login.htm");
      try {
        response.sendRedirect("login.htm");
      } catch (IOException e) {
        throw new ServletException("Could not redirect to login page.", e);
      }
    }

    return result;
  }
 /**
  * Change the current theme to the specified theme by name, storing the new theme name through the
  * configured {@link ThemeResolver}.
  *
  * @param themeName the name of the new theme
  * @see ThemeResolver#setThemeName
  */
 public void changeTheme(String themeName) {
   ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(this.request);
   if (themeResolver == null) {
     throw new IllegalStateException("Cannot change theme if no ThemeResolver configured");
   }
   themeResolver.setThemeName(this.request, this.response, themeName);
   // Ask for re-resolution on next getTheme call.
   this.theme = null;
 }
 /**
  * Change the current theme to the specified one, storing the new theme name through the
  * configured {@link ThemeResolver}.
  *
  * @param theme the new theme
  * @see ThemeResolver#setThemeName
  */
 public void changeTheme(Theme theme) {
   ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(this.request);
   if (themeResolver == null) {
     throw new IllegalStateException("Cannot change theme if no ThemeResolver configured");
   }
   themeResolver.setThemeName(
       this.request, this.response, (theme != null ? theme.getName() : null));
   this.theme = theme;
 }