當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。