當前位置: 首頁>>代碼示例>>Java>>正文


Java CookieLocaleResolver類代碼示例

本文整理匯總了Java中org.springframework.web.servlet.i18n.CookieLocaleResolver的典型用法代碼示例。如果您正苦於以下問題:Java CookieLocaleResolver類的具體用法?Java CookieLocaleResolver怎麽用?Java CookieLocaleResolver使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CookieLocaleResolver類屬於org.springframework.web.servlet.i18n包,在下文中一共展示了CookieLocaleResolver類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testResolveLocaleByCookie

import org.springframework.web.servlet.i18n.CookieLocaleResolver; //導入依賴的package包/類
@Test
public void testResolveLocaleByCookie() {
  // Arrange
  AngularCookieLocaleResolver resolver = new AngularCookieLocaleResolver();
  HttpServletRequest servlet = Mockito.mock(HttpServletRequest.class);
  Cookie cookie = new Cookie("locale", "de");
  Cookie[] cookies = new Cookie[1];
  cookies[0] = cookie;
  when(servlet.getAttribute(CookieLocaleResolver.LOCALE_REQUEST_ATTRIBUTE_NAME)).thenReturn(null);
  when(servlet.getCookies()).thenReturn(cookies);
  resolver.setCookieName("locale");

  // Act
  Locale locale = resolver.resolveLocale(servlet);

  // Assert
  assertThat(locale, is(nullValue()));
}
 
開發者ID:dzhw,項目名稱:metadatamanagement,代碼行數:19,代碼來源:AngularCookieLocaleResolverTest.java

示例2: preHandle

import org.springframework.web.servlet.i18n.CookieLocaleResolver; //導入依賴的package包/類
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
		throws Exception {
	LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);

	// Check if it's our case
	if (localeResolver == null) {
		throw new IllegalStateException("No LocaleResolver found: not in a DispatcherServlet request?");
	}
	if (!(localeResolver instanceof CookieLocaleResolver)) {
		return true;
	}

	// Check if locale not in cookie.
	// If so, then force it to store in cookie
	CookieLocaleResolver cookieLocaleResolver = (CookieLocaleResolver) localeResolver;
	Cookie cookie = WebUtils.getCookie(request, cookieLocaleResolver.getCookieName());
	if (cookie == null) {
		cookieLocaleResolver.setLocale(request, response, localeResolver.resolveLocale(request));
	}

	return true;
}
 
開發者ID:skarpushin,項目名稱:summerb,代碼行數:24,代碼來源:ForceLocaleToCoockieInterceptor.java

示例3: setInitLocale

import org.springframework.web.servlet.i18n.CookieLocaleResolver; //導入依賴的package包/類
/**
 * 根據當前request對象中的locale(Header的Accept屬性)初始化係統國際化語言區域環境
 *
 * @param request  當前請求對象
 * @param response 當前響應對象
 */
public static void setInitLocale(final HttpServletRequest request, final HttpServletResponse response) {
    final Locale locale = request.getLocale();
    log.info("Init locale from user request,country:{},lang:{}", locale.getCountry(), locale.toLanguageTag());

    if (localeResolver instanceof CookieLocaleResolver) {
        final CookieLocaleResolver cookieLocaleResolver = (CookieLocaleResolver)localeResolver;
        final Cookie cookie = WebUtils.getCookie(request, cookieLocaleResolver.getCookieName());
        if (cookie == null) {
            setLocale(locale.toLanguageTag(), request, response);
        }
    }
    if (localeResolver instanceof SessionLocaleResolver) {
        final Locale sessionLocale = (Locale)WebUtils.getRequiredSessionAttribute(
            request, SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME);
        if (sessionLocale == null) {
            setLocale(locale.toLanguageTag(), request, response);
        }
    }
}
 
開發者ID:xianrendzw,項目名稱:EasyReport,代碼行數:26,代碼來源:LocaleUtils.java

示例4: localeResolver

import org.springframework.web.servlet.i18n.CookieLocaleResolver; //導入依賴的package包/類
@Bean
public CookieLocaleResolver localeResolver() {
    return new CookieLocaleResolver() {
        @Override
        protected Locale determineDefaultLocale(final HttpServletRequest request) {
            final Locale locale = request.getLocale();
            if (StringUtils.isEmpty(casProperties.getMgmt().getDefaultLocale())
                    || !locale.getLanguage().equals(casProperties.getMgmt().getDefaultLocale())) {
                return locale;
            }
            return new Locale(casProperties.getMgmt().getDefaultLocale());
        }
    };
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:15,代碼來源:CasManagementWebAppConfiguration.java

示例5: localeResolver

import org.springframework.web.servlet.i18n.CookieLocaleResolver; //導入依賴的package包/類
@Bean
public CookieLocaleResolver localeResolver() {
    final CookieLocaleResolver bean = new CookieLocaleResolver() {
        @Override
        protected Locale determineDefaultLocale(final HttpServletRequest request) {
            final Locale locale = request.getLocale();
            if (StringUtils.isBlank(casProperties.getLocale().getDefaultValue())
                    || !locale.getLanguage().equals(casProperties.getLocale().getDefaultValue())) {
                return locale;
            }
            return new Locale(casProperties.getLocale().getDefaultValue());
        }
    };
    return bean;
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:16,代碼來源:CasWebAppConfiguration.java

示例6: localeResolver

import org.springframework.web.servlet.i18n.CookieLocaleResolver; //導入依賴的package包/類
@Bean
public LocaleResolver localeResolver() {
	CookieLocaleResolver resolver = new CookieLocaleResolver();
	resolver.setDefaultLocale(new Locale("en"));
	resolver.setCookieName("SPRING_LOCALE");
	resolver.setCookieMaxAge(4800);
	return resolver;
}
 
開發者ID:mychalvlcek,項目名稱:spring-rest-skeleton,代碼行數:9,代碼來源:WebMvcConfiguration.java

示例7: localeResolver

import org.springframework.web.servlet.i18n.CookieLocaleResolver; //導入依賴的package包/類
@Bean(name = "localeResolver")
public LocaleResolver localeResolver() {
	CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver();
	cookieLocaleResolver.setCookieMaxAge(Integer.MAX_VALUE);
	// The default is taken from the request header
	// cookieLocaleResolver.setDefaultLocale(Locale.ENGLISH);
	return cookieLocaleResolver;
}
 
開發者ID:xtianus,項目名稱:yadaframework,代碼行數:9,代碼來源:YadaWebConfig.java

示例8: localeResolver

import org.springframework.web.servlet.i18n.CookieLocaleResolver; //導入依賴的package包/類
@Bean
public LocaleResolver localeResolver() {
	// Options: SessionLocaleResolver, AcceptHeaderLocaleResolver, FixedLocaleResolver
	CookieLocaleResolver lr = new CookieLocaleResolver();
	lr.setCookieName("LOCALE");	// if not set, default `org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE`
	return lr;
}
 
開發者ID:bndynet,項目名稱:web-framework-for-java,代碼行數:8,代碼來源:MvcConfig.java

示例9: localeResolver

import org.springframework.web.servlet.i18n.CookieLocaleResolver; //導入依賴的package包/類
@Bean
public LocaleResolver localeResolver(){
    CookieLocaleResolver resolver = new CookieLocaleResolver();
    resolver.setDefaultLocale(new Locale("en"));
    resolver.setCookieName("myLocaleCookie");
    resolver.setCookieMaxAge(4800);
    return resolver;
}
 
開發者ID:csokafor,項目名稱:spring-security-angularjs,代碼行數:9,代碼來源:MvcConfig.java

示例10: setup

import org.springframework.web.servlet.i18n.CookieLocaleResolver; //導入依賴的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

示例11: localeResolver

import org.springframework.web.servlet.i18n.CookieLocaleResolver; //導入依賴的package包/類
/**
 * Creates new LocaleResolver.
 *
 * @return Created LocalResolver.
 */
@Bean
public LocaleResolver localeResolver() {
  CookieLocaleResolver lr = new CookieLocaleResolver();
  lr.setCookieName("lang");
  lr.setDefaultLocale(locale);
  return lr;
}
 
開發者ID:OpenLMIS,項目名稱:openlmis-stockmanagement,代碼行數:13,代碼來源:Application.java

示例12: localeResolver

import org.springframework.web.servlet.i18n.CookieLocaleResolver; //導入依賴的package包/類
@Bean
public LocaleResolver localeResolver() {
	CookieLocaleResolver resolver = new CookieLocaleResolver();
	resolver.setDefaultLocale(new Locale("en"));
	resolver.setCookieName("bgLoginLocaleCookie");
	resolver.setCookieMaxAge(4800);
	return resolver;
}
 
開發者ID:gvincenzi,項目名稱:bglogin,代碼行數:9,代碼來源:SpringMvcConfig.java

示例13: localeResolver

import org.springframework.web.servlet.i18n.CookieLocaleResolver; //導入依賴的package包/類
/**
 * Creates a locale resolver. This is used to identify which language is currently configured to be used
 * for a user
 * @return A new cookie locale resolver
 */
@Bean
public LocaleResolver localeResolver() {
    final CookieLocaleResolver ret = new CookieLocaleResolver();
    ret.setDefaultLocale(new Locale("en"));
    return ret;
}
 
開發者ID:castlemock,項目名稱:castlemock,代碼行數:12,代碼來源:MvcConfig.java

示例14: localeResolver

import org.springframework.web.servlet.i18n.CookieLocaleResolver; //導入依賴的package包/類
@Bean
public LocaleResolver localeResolver() {
    final CookieLocaleResolver rv = new CookieLocaleResolver();
    rv.setDefaultLocale(Locale.ENGLISH);
    rv.setDefaultTimeZone(TimeZone.getTimeZone("Europe/Berlin"));
    rv.setLanguageTagCompliant(true);
    rv.setCookieMaxAge((int) Duration.ofDays(365).getSeconds());
    return rv;
}
 
開發者ID:EuregJUG-Maas-Rhine,項目名稱:site,代碼行數:10,代碼來源:WebConfig.java

示例15: localeResolver

import org.springframework.web.servlet.i18n.CookieLocaleResolver; //導入依賴的package包/類
@Bean
public CookieLocaleResolver localeResolver() {
    CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver();
    cookieLocaleResolver.setCookieName(LOCALE_PARAM_NAME);
    cookieLocaleResolver.setDefaultLocale(new Locale(environment.getProperty(Constants.Property.LANGUAGE_DEFAULT), environment.getProperty(Constants.Property.COUNTRY_DEFAULT)));
    return cookieLocaleResolver;
}
 
開發者ID:saltykovdg,項目名稱:java-spring-jspx-hibernate-template,代碼行數:8,代碼來源:WebConfiguration.java


注:本文中的org.springframework.web.servlet.i18n.CookieLocaleResolver類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。