当前位置: 首页>>代码示例>>Java>>正文


Java LocaleChangeInterceptor类代码示例

本文整理汇总了Java中org.springframework.web.servlet.i18n.LocaleChangeInterceptor的典型用法代码示例。如果您正苦于以下问题:Java LocaleChangeInterceptor类的具体用法?Java LocaleChangeInterceptor怎么用?Java LocaleChangeInterceptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LocaleChangeInterceptor类属于org.springframework.web.servlet.i18n包,在下文中一共展示了LocaleChangeInterceptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: verifyStartAuthentication

import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
@Test
public void verifyStartAuthentication() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.setParameter(ThemeChangeInterceptor.DEFAULT_PARAM_NAME, MY_THEME);
    mockRequest.setParameter(LocaleChangeInterceptor.DEFAULT_PARAM_NAME, MY_LOCALE);
    mockRequest.setParameter(CasProtocolConstants.PARAMETER_METHOD, MY_METHOD);

    final MockHttpSession mockSession = new MockHttpSession();
    mockRequest.setSession(mockSession);

    final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class);
    when(servletExternalContext.getNativeRequest()).thenReturn(mockRequest);

    final MockRequestContext mockRequestContext = new MockRequestContext();
    mockRequestContext.setExternalContext(servletExternalContext);
    mockRequestContext.getFlowScope().put(CasProtocolConstants.PARAMETER_SERVICE,
            org.jasig.cas.services.TestUtils.getService(MY_SERVICE));

    final FacebookClient facebookClient = new FacebookClient(MY_KEY, MY_SECRET);
    final TwitterClient twitterClient = new TwitterClient(MY_KEY, MY_SECRET);
    final Clients clients = new Clients(MY_LOGIN_URL, facebookClient, twitterClient);
    final ClientAction action = new ClientAction();
    action.setCentralAuthenticationService(mock(CentralAuthenticationService.class));
    action.setClients(clients);

    final Event event = action.execute(mockRequestContext);
    assertEquals("error", event.getId());
    assertEquals(MY_THEME, mockSession.getAttribute(ThemeChangeInterceptor.DEFAULT_PARAM_NAME));
    assertEquals(MY_LOCALE, mockSession.getAttribute(LocaleChangeInterceptor.DEFAULT_PARAM_NAME));
    assertEquals(MY_METHOD, mockSession.getAttribute(CasProtocolConstants.PARAMETER_METHOD));
    final MutableAttributeMap flowScope = mockRequestContext.getFlowScope();
    final Map<String, String> urls = (Map<String, String>) flowScope.get(ClientAction.PAC4J_URLS);
    assertTrue((urls.get("Facebook"))
            .startsWith("https://www.facebook.com/v2.2/dialog/oauth?client_id=my_key&redirect_uri=http%3A%2F%2Fcasserver%2Flogin%3F"
                    + Clients.DEFAULT_CLIENT_NAME_PARAMETER + "%3DFacebookClient&state="));
    assertEquals(MY_LOGIN_URL + '?' + Clients.DEFAULT_CLIENT_NAME_PARAMETER
            + "=TwitterClient&needs_client_redirection=true", urls.get("Twitter"));
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:39,代码来源:ClientActionTests.java

示例2: testBeanDecoration

import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
@Test
public void testBeanDecoration() throws Exception {
	loadBeanDefinitions("mvc-config-bean-decoration.xml", 16);

	RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
	assertNotNull(mapping);
	mapping.setDefaultHandler(handlerMethod);

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");

	HandlerExecutionChain chain = mapping.getHandler(request);
	assertEquals(3, chain.getInterceptors().length);
	assertTrue(chain.getInterceptors()[0] instanceof ConversionServiceExposingInterceptor);
	assertTrue(chain.getInterceptors()[1] instanceof LocaleChangeInterceptor);
	assertTrue(chain.getInterceptors()[2] instanceof ThemeChangeInterceptor);
	LocaleChangeInterceptor interceptor = (LocaleChangeInterceptor) chain.getInterceptors()[1];
	assertEquals("lang", interceptor.getParamName());
	ThemeChangeInterceptor interceptor2 = (ThemeChangeInterceptor) chain.getInterceptors()[2];
	assertEquals("style", interceptor2.getParamName());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:MvcNamespaceTests.java

示例3: doFilterInternal

import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {

		String newLocale = request.getParameter(LocaleChangeInterceptor.DEFAULT_PARAM_NAME);
		if(localeResolver != null && newLocale != null){
			Locale locale = StringUtils.parseLocaleString(newLocale);
	    	logger.warn("setLocale : "+locale.toString());
			localeResolver.setLocale(request, response, locale);
            LocaleContextHolder.setLocale(locale);
		}
		
        chain.doFilter(request, response);
        
        if (localeResolver != null) {
        	LocaleContextHolder.resetLocaleContext();
        }
    }
 
开发者ID:u2ware,项目名称:springfield,代码行数:17,代码来源:LocaleChangeFilter.java

示例4: testBeanDecoration

import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
@Test
public void testBeanDecoration() throws Exception {
	loadBeanDefinitions("mvc-config-bean-decoration.xml", 14);

	RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
	assertNotNull(mapping);
	mapping.setDefaultHandler(handlerMethod);

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");

	HandlerExecutionChain chain = mapping.getHandler(request);
	assertEquals(3, chain.getInterceptors().length);
	assertTrue(chain.getInterceptors()[0] instanceof ConversionServiceExposingInterceptor);
	assertTrue(chain.getInterceptors()[1] instanceof LocaleChangeInterceptor);
	assertTrue(chain.getInterceptors()[2] instanceof ThemeChangeInterceptor);
	LocaleChangeInterceptor interceptor = (LocaleChangeInterceptor) chain.getInterceptors()[1];
	assertEquals("lang", interceptor.getParamName());
	ThemeChangeInterceptor interceptor2 = (ThemeChangeInterceptor) chain.getInterceptors()[2];
	assertEquals("style", interceptor2.getParamName());
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:21,代码来源:MvcNamespaceTests.java

示例5: prepareForLoginPage

import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
/**
 * Prepare the data for the login page.
 *
 * @param context The current webflow context
 */
protected void prepareForLoginPage(final RequestContext context) {
    final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
    final HttpServletResponse response = WebUtils.getHttpServletResponse(context);
    final HttpSession session = request.getSession();

    // web context
    final WebContext webContext = new J2EContext(request, response);

    // save parameters in web session
    final WebApplicationService service = WebUtils.getService(context);
    logger.debug("save service: {}", service);
    session.setAttribute(CasProtocolConstants.PARAMETER_SERVICE, service);
    saveRequestParameter(request, session, ThemeChangeInterceptor.DEFAULT_PARAM_NAME);
    saveRequestParameter(request, session, LocaleChangeInterceptor.DEFAULT_PARAM_NAME);
    saveRequestParameter(request, session, CasProtocolConstants.PARAMETER_METHOD);

    final LinkedHashMap<String, String> urls = new LinkedHashMap<>();
    // for all clients, generate redirection urls
    for (final Client client : this.clients.findAllClients()) {
        final IndirectClient indirectClient = (IndirectClient) client;
        // clean Client suffix for default names
        final String name = client.getName().replace("Client", "");
        final String redirectionUrl = indirectClient.getRedirectionUrl(webContext);
        logger.debug("{} -> {}", name, redirectionUrl);
        urls.put(name, redirectionUrl);
    }
    context.getFlowScope().put(PAC4J_URLS, urls);
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:34,代码来源:ClientAction.java

示例6: localeChangeInterceptor

import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
@RefreshScope
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
    final LocaleChangeInterceptor bean = new LocaleChangeInterceptor();
    bean.setParamName(this.casProperties.getLocale().getParamName());
    return bean;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:8,代码来源:CasManagementWebAppConfiguration.java

示例7: verifyStartAuthentication

import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
@Test
public void verifyStartAuthentication() throws Exception {
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.setParameter(ThemeChangeInterceptor.DEFAULT_PARAM_NAME, MY_THEME);
    mockRequest.setParameter(LocaleChangeInterceptor.DEFAULT_PARAM_NAME, MY_LOCALE);
    mockRequest.setParameter(CasProtocolConstants.PARAMETER_METHOD, MY_METHOD);

    final MockHttpSession mockSession = new MockHttpSession();
    mockRequest.setSession(mockSession);

    final ServletExternalContext servletExternalContext = mock(ServletExternalContext.class);
    when(servletExternalContext.getNativeRequest()).thenReturn(mockRequest);
    when(servletExternalContext.getNativeResponse()).thenReturn(mockResponse);

    final MockRequestContext mockRequestContext = new MockRequestContext();
    mockRequestContext.setExternalContext(servletExternalContext);
    mockRequestContext.getFlowScope().put(CasProtocolConstants.PARAMETER_SERVICE,
            RegisteredServiceTestUtils.getService(MY_SERVICE));

    final FacebookClient facebookClient = new FacebookClient(MY_KEY, MY_SECRET);
    final TwitterClient twitterClient = new TwitterClient("3nJPbVTVRZWAyUgoUKQ8UA", "h6LZyZJmcW46Vu8R47MYfeXTSYGI30EqnWaSwVhFkbA");
    final Clients clients = new Clients(MY_LOGIN_URL, facebookClient, twitterClient);
    final DelegatedClientAuthenticationAction action = new DelegatedClientAuthenticationAction(clients,
            null, mock(CentralAuthenticationService.class),
            "theme", "locale", false);

    final Event event = action.execute(mockRequestContext);
    assertEquals("error", event.getId());
    assertEquals(MY_THEME, mockSession.getAttribute(ThemeChangeInterceptor.DEFAULT_PARAM_NAME));
    assertEquals(MY_LOCALE, mockSession.getAttribute(LocaleChangeInterceptor.DEFAULT_PARAM_NAME));
    assertEquals(MY_METHOD, mockSession.getAttribute(CasProtocolConstants.PARAMETER_METHOD));
    final MutableAttributeMap flowScope = mockRequestContext.getFlowScope();
    final Set<DelegatedClientAuthenticationAction.ProviderLoginPageConfiguration> urls =
            (Set<DelegatedClientAuthenticationAction.ProviderLoginPageConfiguration>) flowScope.get(DelegatedClientAuthenticationAction.PAC4J_URLS);

    assertFalse(urls.isEmpty());
    assertSame(2, urls.size());
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:40,代码来源:DelegatedClientAuthenticationActionTests.java

示例8: localeChangeInterceptor

import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
@RefreshScope
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
    LocaleChangeInterceptor bean = new LocaleChangeInterceptor();
    bean.setParamName(this.casProperties.getLocale().getParamName());
    return bean;
}
 
开发者ID:e-gov,项目名称:TARA-Server,代码行数:8,代码来源:CasWebflowContextConfiguration.java

示例9: localeChangeInterceptor

import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
   LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
   lci.setParamName("lang");

   return lci;
}
 
开发者ID:chen0040,项目名称:spring-boot-slingshot,代码行数:8,代码来源:WebMvcConfig.java

示例10: localeInterceptor

import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
/**
 * Set up locale configuration by url parameter
 *
 * @return
 */
@Bean
public LocaleChangeInterceptor localeInterceptor() {
    LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor();
    interceptor.setParamName(LANG_PARAMETER_NAME);
    return interceptor;
}
 
开发者ID:remipassmoilesel,项目名称:simple-hostel-management,代码行数:12,代码来源:SpringConfiguration.java

示例11: localeInterceptor

import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
/**
 * Set up locale configuration by url parameter
 *
 * @return
 */
@Bean
public LocaleChangeInterceptor localeInterceptor() {
    LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor();
    interceptor.setParamName("lang");
    return interceptor;
}
 
开发者ID:remipassmoilesel,项目名称:simple-hostel-management,代码行数:12,代码来源:LocaleConfiguration.java

示例12: localeChangeInterceptor

import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
    LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
    // 参数名
    lci.setParamName("lang");
    return lci;
}
 
开发者ID:kawhii,项目名称:wolf,代码行数:8,代码来源:LocaleConfig.java

示例13: addInterceptors

import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
@Override
public void addInterceptors(InterceptorRegistry registry) {
    LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
    localeChangeInterceptor.setParamName("lang");
    localeChangeInterceptor.setIgnoreInvalidLocale(true);
    localeChangeInterceptor.setLanguageTagCompliant(true);
    registry.addInterceptor(localeChangeInterceptor);
}
 
开发者ID:zjnu-acm,项目名称:judge,代码行数:9,代码来源:LocaleConfiguration.java

示例14: testInterceptors

import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
@Test
public void testInterceptors() throws Exception {
	loadBeanDefinitions("mvc-config-interceptors.xml", 21);

	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(5, chain.getInterceptors().length);
	assertTrue(chain.getInterceptors()[0] instanceof ConversionServiceExposingInterceptor);
	assertTrue(chain.getInterceptors()[1] instanceof LocaleChangeInterceptor);
	assertTrue(chain.getInterceptors()[2] instanceof WebRequestHandlerInterceptorAdapter);
	assertTrue(chain.getInterceptors()[3] instanceof ThemeChangeInterceptor);
	assertTrue(chain.getInterceptors()[4] instanceof UserRoleAuthorizationInterceptor);

	request.setRequestURI("/admin/users");
	chain = mapping.getHandler(request);
	assertEquals(3, chain.getInterceptors().length);

	request.setRequestURI("/logged/accounts/12345");
	chain = mapping.getHandler(request);
	assertEquals(5, chain.getInterceptors().length);
	assertTrue(chain.getInterceptors()[4] instanceof WebRequestHandlerInterceptorAdapter);

	request.setRequestURI("/foo/logged");
	chain = mapping.getHandler(request);
	assertEquals(5, chain.getInterceptors().length);
	assertTrue(chain.getInterceptors()[4] instanceof WebRequestHandlerInterceptorAdapter);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:36,代码来源:MvcNamespaceTests.java

示例15: setup

import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; //导入依赖的package包/类
@Before
public void setup() {
	CookieLocaleResolver localeResolver = new CookieLocaleResolver();
	localeResolver.setCookieDomain("domain");

	this.mockMvc = standaloneSetup(new SimpleController())
			.addInterceptors(new LocaleChangeInterceptor())
			.setLocaleResolver(localeResolver)
			.defaultRequest(get("/").param("locale", "en_US"))
			.alwaysExpect(status().isOk())
			.build();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:CookieAssertionTests.java


注:本文中的org.springframework.web.servlet.i18n.LocaleChangeInterceptor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。