use of org.springframework.web.servlet.theme.FixedThemeResolver in project cas by apereo.
the class CasThemesConfiguration method themeResolver.
@ConditionalOnMissingBean(name = "casThemeResolver")
@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
public ThemeResolver themeResolver(@Qualifier("serviceThemeResolverSupportedBrowsers") final Supplier<Map<String, String>> serviceThemeResolverSupportedBrowsers, final CasConfigurationProperties casProperties, @Qualifier(AuthenticationServiceSelectionPlan.BEAN_NAME) final AuthenticationServiceSelectionPlan authenticationRequestServiceSelectionStrategies, @Qualifier(ServicesManager.BEAN_NAME) final ServicesManager servicesManager) {
val defaultThemeName = casProperties.getTheme().getDefaultThemeName();
val fixedResolver = new FixedThemeResolver();
fixedResolver.setDefaultThemeName(defaultThemeName);
val sessionThemeResolver = new SessionThemeResolver();
sessionThemeResolver.setDefaultThemeName(defaultThemeName);
val tgc = casProperties.getTgc();
val cookieThemeResolver = new CookieThemeResolver();
cookieThemeResolver.setDefaultThemeName(defaultThemeName);
cookieThemeResolver.setCookieDomain(tgc.getDomain());
cookieThemeResolver.setCookieHttpOnly(tgc.isHttpOnly());
cookieThemeResolver.setCookieMaxAge(tgc.getMaxAge());
cookieThemeResolver.setCookiePath(tgc.getPath());
cookieThemeResolver.setCookieSecure(tgc.isSecure());
val serviceThemeResolver = new RegisteredServiceThemeResolver(servicesManager, authenticationRequestServiceSelectionStrategies, casProperties, serviceThemeResolverSupportedBrowsers.get().entrySet().stream().collect(Collectors.toMap(entry -> Pattern.compile(entry.getKey()), Map.Entry::getValue)));
serviceThemeResolver.setDefaultThemeName(defaultThemeName);
val header = new RequestHeaderThemeResolver(casProperties.getTheme().getParamName());
header.setDefaultThemeName(defaultThemeName);
val chainingThemeResolver = new ChainingThemeResolver();
chainingThemeResolver.addResolver(cookieThemeResolver).addResolver(sessionThemeResolver).addResolver(header).addResolver(serviceThemeResolver).addResolver(fixedResolver);
chainingThemeResolver.setDefaultThemeName(defaultThemeName);
return chainingThemeResolver;
}
use of org.springframework.web.servlet.theme.FixedThemeResolver in project spring-framework by spring-projects.
the class ViewResolverTests method xmlViewResolver.
@Test
@SuppressWarnings("deprecation")
public void xmlViewResolver() throws Exception {
this.wac.registerSingleton("testBean", TestBean.class);
this.wac.refresh();
TestBean testBean = (TestBean) this.wac.getBean("testBean");
org.springframework.web.servlet.view.XmlViewResolver vr = new org.springframework.web.servlet.view.XmlViewResolver();
vr.setLocation(new ClassPathResource("org/springframework/web/servlet/view/views.xml"));
vr.setApplicationContext(this.wac);
View view1 = vr.resolveViewName("example1", Locale.getDefault());
assertThat(TestView.class.equals(view1.getClass())).as("Correct view class").isTrue();
assertThat("/example1.jsp".equals(((InternalResourceView) view1).getUrl())).as("Correct URL").isTrue();
View view2 = vr.resolveViewName("example2", Locale.getDefault());
assertThat(JstlView.class.equals(view2.getClass())).as("Correct view class").isTrue();
assertThat("/example2new.jsp".equals(((InternalResourceView) view2).getUrl())).as("Correct URL").isTrue();
Map<String, Object> model = new HashMap<>();
TestBean tb = new TestBean();
model.put("tb", tb);
this.request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.wac);
this.request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
this.request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver());
view1.render(model, this.request, this.response);
assertThat(tb.equals(this.request.getAttribute("tb"))).as("Correct tb attribute").isTrue();
assertThat("testvalue1".equals(this.request.getAttribute("test1"))).as("Correct test1 attribute").isTrue();
assertThat(testBean.equals(this.request.getAttribute("test2"))).as("Correct test2 attribute").isTrue();
this.request.clearAttributes();
this.request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.wac);
this.request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
this.request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver());
view2.render(model, this.request, this.response);
assertThat(tb.equals(this.request.getAttribute("tb"))).as("Correct tb attribute").isTrue();
assertThat("testvalue1".equals(this.request.getAttribute("test1"))).as("Correct test1 attribute").isTrue();
assertThat("testvalue2".equals(this.request.getAttribute("test2"))).as("Correct test2 attribute").isTrue();
}
use of org.springframework.web.servlet.theme.FixedThemeResolver in project spring-framework by spring-projects.
the class ViewResolverTests method doTestUrlBasedViewResolverWithoutPrefixes.
private void doTestUrlBasedViewResolverWithoutPrefixes(UrlBasedViewResolver vr) throws Exception {
this.wac.refresh();
vr.setApplicationContext(this.wac);
vr.setContentType("myContentType");
vr.setRequestContextAttribute("rc");
View view = vr.resolveViewName("example1", Locale.getDefault());
assertThat(view).isInstanceOf(JstlView.class);
assertThat(((InternalResourceView) view).getUrl()).as("Correct URL").isEqualTo("example1");
assertThat(((InternalResourceView) view).getContentType()).as("Correct textContentType").isEqualTo("myContentType");
view = vr.resolveViewName("example2", Locale.getDefault());
assertThat(view).isInstanceOf(JstlView.class);
assertThat(((InternalResourceView) view).getUrl()).as("Correct URL").isEqualTo("example2");
assertThat(((InternalResourceView) view).getContentType()).as("Correct textContentType").isEqualTo("myContentType");
this.request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.wac);
this.request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
this.request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver());
Map<String, Object> model = new HashMap<>();
TestBean tb = new TestBean();
model.put("tb", tb);
view.render(model, this.request, this.response);
assertThat(tb.equals(this.request.getAttribute("tb"))).as("Correct tb attribute").isTrue();
boolean condition = this.request.getAttribute("rc") instanceof RequestContext;
assertThat(condition).as("Correct rc attribute").isTrue();
view = vr.resolveViewName("redirect:myUrl", Locale.getDefault());
assertThat(view.getClass()).as("Correct view class").isEqualTo(RedirectView.class);
assertThat(((RedirectView) view).getUrl()).as("Correct URL").isEqualTo("myUrl");
assertThat(((RedirectView) view).getApplicationContext()).as("View not initialized as bean").isSameAs(this.wac);
view = vr.resolveViewName("forward:myUrl", Locale.getDefault());
assertThat(view.getClass()).as("Correct view class").isEqualTo(InternalResourceView.class);
assertThat(((InternalResourceView) view).getUrl()).as("Correct URL").isEqualTo("myUrl");
}
Aggregations