Java 类org.springframework.web.servlet.theme.SessionThemeResolver 实例源码

项目:class-guard    文件:ComplexWebApplicationContext.java   
@Override
public void doSomething(HttpServletRequest request) throws ServletException, IllegalAccessException {
    WebApplicationContext wac = RequestContextUtils.getWebApplicationContext(request);
    if (!(wac instanceof ComplexWebApplicationContext)) {
        throw new ServletException("Incorrect WebApplicationContext");
    }
    if (!(request instanceof MultipartHttpServletRequest)) {
        throw new ServletException("Not in a MultipartHttpServletRequest");
    }
    if (!(RequestContextUtils.getLocaleResolver(request) instanceof SessionLocaleResolver)) {
        throw new ServletException("Incorrect LocaleResolver");
    }
    if (!Locale.CANADA.equals(RequestContextUtils.getLocale(request))) {
        throw new ServletException("Incorrect Locale");
    }
    if (!Locale.CANADA.equals(LocaleContextHolder.getLocale())) {
        throw new ServletException("Incorrect Locale");
    }
    if (!(RequestContextUtils.getThemeResolver(request) instanceof SessionThemeResolver)) {
        throw new ServletException("Incorrect ThemeResolver");
    }
    if (!"theme".equals(RequestContextUtils.getThemeResolver(request).resolveThemeName(request))) {
        throw new ServletException("Incorrect theme name");
    }
    if (request.getParameter("fail") != null) {
        throw new ModelAndViewDefiningException(new ModelAndView("failed1"));
    }
    if (request.getParameter("access") != null) {
        throw new IllegalAccessException("illegal access");
    }
    if (request.getParameter("servlet") != null) {
        throw new ServletRequestBindingException("servlet");
    }
    if (request.getParameter("exception") != null) {
        throw new RuntimeException("servlet");
    }
}
项目:spring4-understanding    文件:ComplexWebApplicationContext.java   
@Override
@SuppressWarnings("deprecation")
public void doSomething(HttpServletRequest request) throws ServletException, IllegalAccessException {
    WebApplicationContext wac = RequestContextUtils.getWebApplicationContext(request);
    if (!(wac instanceof ComplexWebApplicationContext)) {
        throw new ServletException("Incorrect WebApplicationContext");
    }
    if (WebUtils.getNativeRequest(request, MultipartHttpServletRequest.class) == null) {
        throw new ServletException("Not in a MultipartHttpServletRequest");
    }
    if (request.getParameter("fail") != null) {
        throw new ModelAndViewDefiningException(new ModelAndView("failed1"));
    }
    if (request.getParameter("access") != null) {
        throw new IllegalAccessException("illegal access");
    }
    if (request.getParameter("servlet") != null) {
        throw new ServletRequestBindingException("servlet");
    }
    if (request.getParameter("exception") != null) {
        throw new RuntimeException("servlet");
    }
    if (!(RequestContextUtils.getLocaleResolver(request) instanceof SessionLocaleResolver)) {
        throw new ServletException("Incorrect LocaleResolver");
    }
    if (!Locale.CANADA.equals(RequestContextUtils.getLocale(request))) {
        throw new ServletException("Incorrect Locale");
    }
    if (!Locale.CANADA.equals(LocaleContextHolder.getLocale())) {
        throw new ServletException("Incorrect Locale");
    }
    if (RequestContextUtils.getTimeZone(request) != null) {
        throw new ServletException("Incorrect TimeZone");
    }
    if (!TimeZone.getDefault().equals(LocaleContextHolder.getTimeZone())) {
        throw new ServletException("Incorrect TimeZone");
    }
    if (!(RequestContextUtils.getThemeResolver(request) instanceof SessionThemeResolver)) {
        throw new ServletException("Incorrect ThemeResolver");
    }
    if (!"theme".equals(RequestContextUtils.getThemeResolver(request).resolveThemeName(request))) {
        throw new ServletException("Incorrect theme name");
    }
    RequestContext rc = new RequestContext(request);
    rc.changeLocale(Locale.US, TimeZone.getTimeZone("GMT+1"));
    rc.changeTheme("theme2");
    if (!Locale.US.equals(RequestContextUtils.getLocale(request))) {
        throw new ServletException("Incorrect Locale");
    }
    if (!Locale.US.equals(LocaleContextHolder.getLocale())) {
        throw new ServletException("Incorrect Locale");
    }
    if (!TimeZone.getTimeZone("GMT+1").equals(RequestContextUtils.getTimeZone(request))) {
        throw new ServletException("Incorrect TimeZone");
    }
    if (!TimeZone.getTimeZone("GMT+1").equals(LocaleContextHolder.getTimeZone())) {
        throw new ServletException("Incorrect TimeZone");
    }
    if (!"theme2".equals(RequestContextUtils.getThemeResolver(request).resolveThemeName(request))) {
        throw new ServletException("Incorrect theme name");
    }
}