use of org.springframework.web.servlet.i18n.LocaleChangeInterceptor in project spring-framework by spring-projects.
the class ComplexWebApplicationContext method refresh.
@Override
public void refresh() throws BeansException {
registerSingleton(DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME, SessionLocaleResolver.class);
registerSingleton(DispatcherServlet.THEME_RESOLVER_BEAN_NAME, SessionThemeResolver.class);
LocaleChangeInterceptor interceptor1 = new LocaleChangeInterceptor();
LocaleChangeInterceptor interceptor2 = new LocaleChangeInterceptor();
interceptor2.setParamName("locale2");
ThemeChangeInterceptor interceptor3 = new ThemeChangeInterceptor();
ThemeChangeInterceptor interceptor4 = new ThemeChangeInterceptor();
interceptor4.setParamName("theme2");
UserRoleAuthorizationInterceptor interceptor5 = new UserRoleAuthorizationInterceptor();
interceptor5.setAuthorizedRoles("role1", "role2");
List<Object> interceptors = new ArrayList<>();
interceptors.add(interceptor5);
interceptors.add(interceptor1);
interceptors.add(interceptor2);
interceptors.add(interceptor3);
interceptors.add(interceptor4);
interceptors.add(new MyHandlerInterceptor1());
interceptors.add(new MyHandlerInterceptor2());
interceptors.add(new MyWebRequestInterceptor());
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("mappings", "/view.do=viewHandler\n/locale.do=localeHandler\nloc.do=anotherLocaleHandler");
pvs.add("interceptors", interceptors);
registerSingleton("myUrlMapping1", SimpleUrlHandlerMapping.class, pvs);
pvs = new MutablePropertyValues();
pvs.add("mappings", "/form.do=localeHandler\n/unknown.do=unknownHandler\nservlet.do=myServlet");
pvs.add("order", "2");
registerSingleton("myUrlMapping2", SimpleUrlHandlerMapping.class, pvs);
pvs = new MutablePropertyValues();
pvs.add("mappings", "/head.do=headController\n" + "body.do=bodyController\n/noview*=noviewController\n/noview/simple*=noviewController");
pvs.add("order", "1");
registerSingleton("handlerMapping", SimpleUrlHandlerMapping.class, pvs);
registerSingleton("myDummyAdapter", MyDummyAdapter.class);
registerSingleton("myHandlerAdapter", MyHandlerAdapter.class);
registerSingleton("standardHandlerAdapter", SimpleControllerHandlerAdapter.class);
registerSingleton("noviewController", NoViewController.class);
pvs = new MutablePropertyValues();
pvs.add("order", 0);
pvs.add("basename", "org.springframework.web.servlet.complexviews");
registerSingleton("viewResolver", ResourceBundleViewResolver.class, pvs);
pvs = new MutablePropertyValues();
pvs.add("suffix", ".jsp");
registerSingleton("viewResolver2", InternalResourceViewResolver.class, pvs);
pvs = new MutablePropertyValues();
pvs.add("viewName", "form");
registerSingleton("viewHandler", ParameterizableViewController.class, pvs);
registerSingleton("localeHandler", ComplexLocaleChecker.class);
registerSingleton("anotherLocaleHandler", ComplexLocaleChecker.class);
registerSingleton("unknownHandler", Object.class);
registerSingleton("headController", HeadController.class);
registerSingleton("bodyController", BodyController.class);
registerSingleton("servletPostProcessor", SimpleServletPostProcessor.class);
registerSingleton("handlerAdapter", SimpleServletHandlerAdapter.class);
registerSingleton("myServlet", MyServlet.class);
pvs = new MutablePropertyValues();
pvs.add("order", "1");
pvs.add("exceptionMappings", "java.lang.IllegalAccessException=failed2\n" + "ServletRequestBindingException=failed3");
pvs.add("defaultErrorView", "failed0");
registerSingleton("exceptionResolver1", SimpleMappingExceptionResolver.class, pvs);
pvs = new MutablePropertyValues();
pvs.add("order", "0");
pvs.add("exceptionMappings", "java.lang.Exception=failed1");
List<RuntimeBeanReference> mappedHandlers = new ManagedList<>();
mappedHandlers.add(new RuntimeBeanReference("anotherLocaleHandler"));
pvs.add("mappedHandlers", mappedHandlers);
pvs.add("defaultStatusCode", "500");
pvs.add("defaultErrorView", "failed2");
registerSingleton("handlerExceptionResolver", SimpleMappingExceptionResolver.class, pvs);
registerSingleton("multipartResolver", MockMultipartResolver.class);
registerSingleton("testListener", TestApplicationListener.class);
addMessage("test", Locale.ENGLISH, "test message");
addMessage("test", Locale.CANADA, "Canadian & test message");
super.refresh();
}
use of org.springframework.web.servlet.i18n.LocaleChangeInterceptor in project spring-framework by spring-projects.
the class MvcNamespaceTests method testInterceptors.
@Test
public void testInterceptors() throws Exception {
loadBeanDefinitions("mvc-config-interceptors.xml", 18);
RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
assertNotNull(mapping);
mapping.setDefaultHandler(handlerMethod);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
request.setRequestURI("/accounts/12345");
request.addParameter("locale", "en");
request.addParameter("theme", "green");
HandlerExecutionChain chain = mapping.getHandler(request);
assertEquals(4, chain.getInterceptors().length);
assertTrue(chain.getInterceptors()[0] instanceof ConversionServiceExposingInterceptor);
assertTrue(chain.getInterceptors()[1] instanceof LocaleChangeInterceptor);
assertTrue(chain.getInterceptors()[2] instanceof ThemeChangeInterceptor);
assertTrue(chain.getInterceptors()[3] instanceof UserRoleAuthorizationInterceptor);
request.setRequestURI("/admin/users");
chain = mapping.getHandler(request);
assertEquals(2, chain.getInterceptors().length);
request.setRequestURI("/logged/accounts/12345");
chain = mapping.getHandler(request);
assertEquals(3, chain.getInterceptors().length);
request.setRequestURI("/foo/logged");
chain = mapping.getHandler(request);
assertEquals(3, chain.getInterceptors().length);
}
use of org.springframework.web.servlet.i18n.LocaleChangeInterceptor in project cas by apereo.
the class CasManagementWebAppConfiguration method localeChangeInterceptor.
@RefreshScope
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
final LocaleChangeInterceptor bean = new LocaleChangeInterceptor();
bean.setParamName(this.casProperties.getLocale().getParamName());
return bean;
}
use of org.springframework.web.servlet.i18n.LocaleChangeInterceptor in project nikita-noark5-core by HiOA-ABI.
the class AppWebMvcConfiguration method localeChangeInterceptor.
/**
* Set interceptor so that GUI portion of the applications
* can return pages with different languages. Take a look
* for a files called message_LANG.properties under the
* /src/main/resources/ folder to see which languages are
* supported at runtime.
*
* TODO: Check how this deals with accept-language in HTTP
* header
* lang=no, lang=en
* @return LocaleChangeInterceptor
*/
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
lci.setParamName("lang");
return lci;
}
use of org.springframework.web.servlet.i18n.LocaleChangeInterceptor in project cas by apereo.
the class CasWebflowContextConfiguration method localeChangeInterceptor.
@RefreshScope
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
final LocaleChangeInterceptor bean = new LocaleChangeInterceptor();
bean.setParamName(this.casProperties.getLocale().getParamName());
return bean;
}
Aggregations