List of usage examples for org.springframework.web.servlet.support RequestContextUtils getThemeResolver
@Nullable public static ThemeResolver getThemeResolver(HttpServletRequest request)
From source file:org.dspace.webmvc.theme.SpringThemeContextUtils.java
/** * Set the current theme/*w w w . j a v a2 s . c om*/ * * @param themeName * @param request * @param response */ public static void setThemeName(String themeName, HttpServletRequest request, HttpServletResponse response) { ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(request); themeResolver.setThemeName(request, response, themeName); SpringThemeHolder themeHolder = SpringThemeHolder.getCurrentTheme(); if (!themeName.equals(themeHolder.getName())) { SpringThemeHolder.resetCurrentTheme(); } }
From source file:jetx.ext.springmvc.SpringMvcFunctions.java
/** * ?ThemeResolver/*from w w w. j ava2 s . c om*/ */ public static ThemeResolver getThemeResolver(JetPageContext ctx) { HttpServletRequest request = ExtendUtils.getHttpServletRequest(ctx); return RequestContextUtils.getThemeResolver(request); }
From source file:org.dspace.webmvc.theme.ThemeChangeInterceptor.java
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(request); if (themeResolver == null) { throw new IllegalStateException("No ThemeResolver found: not in a DispatcherServlet request?"); }/*from w ww.j a v a2 s . co m*/ String newTheme = request.getParameter(this.paramName); if (newTheme != null) { themeResolver.setThemeName(request, response, newTheme); response.addCookie(new Cookie("themeName", newTheme)); } else { ThemeMapEntry bestMatch = null; for (ThemeMapEntry entry : themeMappings) { if (entry.mapType == MapType.VIEW || entry.mapType == MapType.ANY) { if (modelAndView != null && pathMatcher.match(entry.path, modelAndView.getViewName())) { if (entry.isBestMatch(bestMatch)) { bestMatch = entry; } } } if (entry.mapType == MapType.URL || entry.mapType == MapType.ANY) { String path = urlPathHelper.getLookupPathForRequest(request); if (pathMatcher.match(entry.path, path)) { if (entry.isBestMatch(bestMatch)) { bestMatch = entry; } } } if (entry.mapType == MapType.CONTROLLER || entry.mapType == MapType.ANY) { } } if (bestMatch != null) { themeResolver.setThemeName(request, response, bestMatch.themeName); } else if (request.getCookies() != null) { for (Cookie cookie : request.getCookies()) { if ("themeName".equals(cookie.getName())) { themeResolver.setThemeName(request, response, cookie.getValue()); } } } } super.postHandle(request, response, handler, modelAndView); }