use of org.springframework.context.i18n.TimeZoneAwareLocaleContext in project spring-framework by spring-projects.
the class CookieLocaleResolverTests method testResolveLocaleContextWithCookieWithoutLocale.
@Test
public void testResolveLocaleContextWithCookieWithoutLocale() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addPreferredLocale(Locale.TAIWAN);
Cookie cookie = new Cookie(CookieLocaleResolver.DEFAULT_COOKIE_NAME, "");
request.setCookies(cookie);
CookieLocaleResolver resolver = new CookieLocaleResolver();
LocaleContext loc = resolver.resolveLocaleContext(request);
assertEquals(request.getLocale(), loc.getLocale());
assertTrue(loc instanceof TimeZoneAwareLocaleContext);
assertNull(((TimeZoneAwareLocaleContext) loc).getTimeZone());
}
use of org.springframework.context.i18n.TimeZoneAwareLocaleContext in project spring-framework by spring-projects.
the class CookieLocaleResolverTests method testResolveLocaleContextWithoutCookie.
@Test
public void testResolveLocaleContextWithoutCookie() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addPreferredLocale(Locale.TAIWAN);
CookieLocaleResolver resolver = new CookieLocaleResolver();
LocaleContext loc = resolver.resolveLocaleContext(request);
assertEquals(request.getLocale(), loc.getLocale());
assertTrue(loc instanceof TimeZoneAwareLocaleContext);
assertNull(((TimeZoneAwareLocaleContext) loc).getTimeZone());
}
use of org.springframework.context.i18n.TimeZoneAwareLocaleContext in project spring-framework by spring-projects.
the class CookieLocaleResolverTests method testSetAndResolveLocaleContextWithTimeZone.
@Test
public void testSetAndResolveLocaleContextWithTimeZone() {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
CookieLocaleResolver resolver = new CookieLocaleResolver();
resolver.setLocaleContext(request, response, new SimpleTimeZoneAwareLocaleContext(new Locale("nl", ""), TimeZone.getTimeZone("GMT+1")));
Cookie cookie = response.getCookie(CookieLocaleResolver.DEFAULT_COOKIE_NAME);
request = new MockHttpServletRequest();
request.setCookies(cookie);
resolver = new CookieLocaleResolver();
LocaleContext loc = resolver.resolveLocaleContext(request);
assertEquals("nl", loc.getLocale().getLanguage());
assertTrue(loc instanceof TimeZoneAwareLocaleContext);
assertEquals(TimeZone.getTimeZone("GMT+1"), ((TimeZoneAwareLocaleContext) loc).getTimeZone());
}
use of org.springframework.context.i18n.TimeZoneAwareLocaleContext in project spring-framework by spring-projects.
the class SessionLocaleResolver method setLocaleContext.
@Override
public void setLocaleContext(HttpServletRequest request, HttpServletResponse response, LocaleContext localeContext) {
Locale locale = null;
TimeZone timeZone = null;
if (localeContext != null) {
locale = localeContext.getLocale();
if (localeContext instanceof TimeZoneAwareLocaleContext) {
timeZone = ((TimeZoneAwareLocaleContext) localeContext).getTimeZone();
}
}
WebUtils.setSessionAttribute(request, LOCALE_SESSION_ATTRIBUTE_NAME, locale);
WebUtils.setSessionAttribute(request, TIME_ZONE_SESSION_ATTRIBUTE_NAME, timeZone);
}
use of org.springframework.context.i18n.TimeZoneAwareLocaleContext in project spring-framework by spring-projects.
the class CookieLocaleResolverTests method testResolveLocaleContextWithInvalidLocaleOnErrorDispatch.
@Test
public void testResolveLocaleContextWithInvalidLocaleOnErrorDispatch() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addPreferredLocale(Locale.GERMAN);
request.setAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE, new ServletException());
Cookie cookie = new Cookie("LanguageKoekje", "n-x GMT+1");
request.setCookies(cookie);
CookieLocaleResolver resolver = new CookieLocaleResolver();
resolver.setDefaultTimeZone(TimeZone.getTimeZone("GMT+2"));
resolver.setCookieName("LanguageKoekje");
LocaleContext loc = resolver.resolveLocaleContext(request);
assertEquals(Locale.GERMAN, loc.getLocale());
assertTrue(loc instanceof TimeZoneAwareLocaleContext);
assertEquals(TimeZone.getTimeZone("GMT+2"), ((TimeZoneAwareLocaleContext) loc).getTimeZone());
}
Aggregations