本文整理匯總了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()));
}
示例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;
}
示例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);
}
}
}
示例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());
}
};
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}