本文整理匯總了Java中org.springframework.context.i18n.TimeZoneAwareLocaleContext類的典型用法代碼示例。如果您正苦於以下問題:Java TimeZoneAwareLocaleContext類的具體用法?Java TimeZoneAwareLocaleContext怎麽用?Java TimeZoneAwareLocaleContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TimeZoneAwareLocaleContext類屬於org.springframework.context.i18n包,在下文中一共展示了TimeZoneAwareLocaleContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setLocaleContext
import org.springframework.context.i18n.TimeZoneAwareLocaleContext; //導入依賴的package包/類
@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();
}
addCookie(response, (locale != null ? locale : "-") + (timeZone != null ? ' ' + timeZone.getID() : ""));
}
else {
removeCookie(response);
}
request.setAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME,
(locale != null ? locale: determineDefaultLocale(request)));
request.setAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME,
(timeZone != null ? timeZone : determineDefaultTimeZone(request)));
}
示例2: resolveLocaleContext
import org.springframework.context.i18n.TimeZoneAwareLocaleContext; //導入依賴的package包/類
@Override
public LocaleContext resolveLocaleContext(final HttpServletRequest request) {
return new TimeZoneAwareLocaleContext() {
@Override
public Locale getLocale() {
Locale locale = (Locale) WebUtils.getSessionAttribute(request, LOCALE_SESSION_ATTRIBUTE_NAME);
if (locale == null) {
locale = determineDefaultLocale(request);
}
return locale;
}
@Override
public TimeZone getTimeZone() {
TimeZone timeZone = (TimeZone) WebUtils.getSessionAttribute(request, TIME_ZONE_SESSION_ATTRIBUTE_NAME);
if (timeZone == null) {
timeZone = determineDefaultTimeZone(request);
}
return timeZone;
}
};
}
示例3: testSetAndResolveLocaleContext
import org.springframework.context.i18n.TimeZoneAwareLocaleContext; //導入依賴的package包/類
@Test
public void testSetAndResolveLocaleContext() {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
CookieLocaleResolver resolver = new CookieLocaleResolver();
resolver.setLocaleContext(request, response, new SimpleLocaleContext(new Locale("nl", "")));
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);
assertNull(((TimeZoneAwareLocaleContext) loc).getTimeZone());
}
示例4: testSetAndResolveLocaleContextWithTimeZone
import org.springframework.context.i18n.TimeZoneAwareLocaleContext; //導入依賴的package包/類
@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());
}
示例5: testSetAndResolveLocaleContextWithTimeZoneOnly
import org.springframework.context.i18n.TimeZoneAwareLocaleContext; //導入依賴的package包/類
@Test
public void testSetAndResolveLocaleContextWithTimeZoneOnly() {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
CookieLocaleResolver resolver = new CookieLocaleResolver();
resolver.setLocaleContext(request, response,
new SimpleTimeZoneAwareLocaleContext(null, TimeZone.getTimeZone("GMT+1")));
Cookie cookie = response.getCookie(CookieLocaleResolver.DEFAULT_COOKIE_NAME);
request = new MockHttpServletRequest();
request.addPreferredLocale(Locale.GERMANY);
request.setCookies(cookie);
resolver = new CookieLocaleResolver();
LocaleContext loc = resolver.resolveLocaleContext(request);
assertEquals(Locale.GERMANY, loc.getLocale());
assertTrue(loc instanceof TimeZoneAwareLocaleContext);
assertEquals(TimeZone.getTimeZone("GMT+1"), ((TimeZoneAwareLocaleContext) loc).getTimeZone());
}
示例6: testPresets
import org.springframework.context.i18n.TimeZoneAwareLocaleContext; //導入依賴的package包/類
@Test
public void testPresets() {
when(request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME)).thenReturn(LOCALE_DEFAULT);
when(request.getAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME)).thenReturn(TIMEZONE_DEFAULT);
LocaleContext context = resolver.resolveLocaleContext(request);
assertThat(context).isNotNull();
assertThat(context).isInstanceOf(TimeZoneAwareLocaleContext.class);
Locale locale = ((TimeZoneAwareLocaleContext) context).getLocale();
TimeZone zone = ((TimeZoneAwareLocaleContext) context).getTimeZone();
assertThat(locale).isNotNull();
assertThat(locale).isEqualTo(LOCALE_DEFAULT);
assertThat(zone).isEqualTo(TIMEZONE_DEFAULT);
List<Event> events = recorder.play();
assertThat(events).isEmpty();
}
示例7: testTimeZone
import org.springframework.context.i18n.TimeZoneAwareLocaleContext; //導入依賴的package包/類
@Test
public void testTimeZone() {
String value = "- " + TIMEZONE_CUSTOM.getID();
Cookie cookie = new Cookie(DEFAULT_COOKIE_NAME, value);
when(request.getCookies()).thenReturn(new Cookie[] { cookie });
LocaleContext context = resolver.resolveLocaleContext(request);
assertThat(context).isNotNull();
assertThat(context).isInstanceOf(TimeZoneAwareLocaleContext.class);
Locale locale = ((TimeZoneAwareLocaleContext) context).getLocale();
TimeZone zone = ((TimeZoneAwareLocaleContext) context).getTimeZone();
assertThat(locale).isEqualTo(LOCALE_DEFAULT);
assertThat(zone).isEqualTo(TIMEZONE_CUSTOM);
List<Event> events = recorder.play();
assertThat(events).isEmpty();
}
示例8: testTimeZoneWithQuotes
import org.springframework.context.i18n.TimeZoneAwareLocaleContext; //導入依賴的package包/類
@Test
public void testTimeZoneWithQuotes() {
String value = resolver.quote("- " + TIMEZONE_CUSTOM.getID());
Cookie cookie = new Cookie(DEFAULT_COOKIE_NAME, value);
when(request.getCookies()).thenReturn(new Cookie[] { cookie });
LocaleContext context = resolver.resolveLocaleContext(request);
assertThat(context).isNotNull();
assertThat(context).isInstanceOf(TimeZoneAwareLocaleContext.class);
Locale locale = ((TimeZoneAwareLocaleContext) context).getLocale();
TimeZone zone = ((TimeZoneAwareLocaleContext) context).getTimeZone();
assertThat(locale).isEqualTo(LOCALE_DEFAULT);
assertThat(zone).isEqualTo(TIMEZONE_CUSTOM);
List<Event> events = recorder.play();
assertThat(events).isEmpty();
}
示例9: testLocaleAndTimeZone
import org.springframework.context.i18n.TimeZoneAwareLocaleContext; //導入依賴的package包/類
@Test
public void testLocaleAndTimeZone() {
String value = LOCALE_CUSTOM + " " + TIMEZONE_CUSTOM.getID();
Cookie cookie = new Cookie(DEFAULT_COOKIE_NAME, value);
when(request.getCookies()).thenReturn(new Cookie[] { cookie });
LocaleContext context = resolver.resolveLocaleContext(request);
assertThat(context).isNotNull();
assertThat(context).isInstanceOf(TimeZoneAwareLocaleContext.class);
Locale locale = ((TimeZoneAwareLocaleContext) context).getLocale();
TimeZone zone = ((TimeZoneAwareLocaleContext) context).getTimeZone();
assertThat(locale).isEqualTo(LOCALE_CUSTOM);
assertThat(zone).isEqualTo(TIMEZONE_CUSTOM);
List<Event> events = recorder.play();
assertThat(events).isEmpty();
}
示例10: testLocaleAndTimeZoneWithQuotes
import org.springframework.context.i18n.TimeZoneAwareLocaleContext; //導入依賴的package包/類
@Test
public void testLocaleAndTimeZoneWithQuotes() {
String value = resolver.quote(LOCALE_CUSTOM.toString() + " " + TIMEZONE_CUSTOM.getID());
Cookie cookie = new Cookie(DEFAULT_COOKIE_NAME, value);
when(request.getCookies()).thenReturn(new Cookie[] { cookie });
LocaleContext context = resolver.resolveLocaleContext(request);
assertThat(context).isNotNull();
assertThat(context).isInstanceOf(TimeZoneAwareLocaleContext.class);
Locale locale = ((TimeZoneAwareLocaleContext) context).getLocale();
TimeZone zone = ((TimeZoneAwareLocaleContext) context).getTimeZone();
assertThat(locale).isEqualTo(LOCALE_CUSTOM);
assertThat(zone).isEqualTo(TIMEZONE_CUSTOM);
List<Event> events = recorder.play();
assertThat(events).isEmpty();
}
示例11: testTraceLogLocaleAndTimeZone
import org.springframework.context.i18n.TimeZoneAwareLocaleContext; //導入依賴的package包/類
@Test
public void testTraceLogLocaleAndTimeZone() {
recorder.release();
recorder.capture("TRACE");
String value = LOCALE_CUSTOM + " " + TIMEZONE_CUSTOM.getID();
Cookie cookie = new Cookie(DEFAULT_COOKIE_NAME, value);
when(request.getCookies()).thenReturn(new Cookie[] { cookie });
LocaleContext context = resolver.resolveLocaleContext(request);
assertThat(context).isInstanceOf(TimeZoneAwareLocaleContext.class);
Locale locale = ((TimeZoneAwareLocaleContext) context).getLocale();
TimeZone zone = ((TimeZoneAwareLocaleContext) context).getTimeZone();
List<Event> events = recorder.play();
assertThat(events).hasSize(1);
Event event = events.get(0);
assertThat(event.getLevel()).isEqualTo("TRACE");
assertThat(event.getMessage()).isEqualTo("Parsed cookie value [" + value + "] into locale '" + locale + "' " +
"and time zone '" + zone.getID() + "'");
assertThat(event.getThrown()).isNull();
}
示例12: resolveLocaleContext
import org.springframework.context.i18n.TimeZoneAwareLocaleContext; //導入依賴的package包/類
@Override
public LocaleContext resolveLocaleContext(final HttpServletRequest request) {
parseLocaleCookieIfNecessary(request);
return new TimeZoneAwareLocaleContext() {
@Override
public Locale getLocale() {
return (Locale) request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME);
}
@Override
public TimeZone getTimeZone() {
return (TimeZone) request.getAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME);
}
};
}
示例13: resolveLocaleContext
import org.springframework.context.i18n.TimeZoneAwareLocaleContext; //導入依賴的package包/類
@Override
public LocaleContext resolveLocaleContext(final HttpServletRequest request) {
parseLocaleCookieIfNecessary(request);
return new TimeZoneAwareLocaleContext() {
@Override
public Locale getLocale() {
return (Locale) request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME);
}
@Override
public TimeZone getTimeZone() {
return (TimeZone) request.getAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME);
}
};
}
示例14: resolveLocaleContext
import org.springframework.context.i18n.TimeZoneAwareLocaleContext; //導入依賴的package包/類
@Override
public LocaleContext resolveLocaleContext(final HttpServletRequest request) {
parseLocaleCookieIfNecessary(request);
return new TimeZoneAwareLocaleContext() {
@Override
public Locale getLocale() {
return (Locale) request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME);
}
@Override
public TimeZone getTimeZone() {
return (TimeZone) request.getAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME);
}
};
}
示例15: setLocaleContext
import org.springframework.context.i18n.TimeZoneAwareLocaleContext; //導入依賴的package包/類
@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);
}