org.springframework.context.i18n.TimeZoneAwareLocaleContext Java Examples

The following examples show how to use org.springframework.context.i18n.TimeZoneAwareLocaleContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SessionLocaleResolver.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public LocaleContext resolveLocaleContext(final HttpServletRequest request) {
	return new TimeZoneAwareLocaleContext() {
		@Override
		public Locale getLocale() {
			Locale locale = (Locale) WebUtils.getSessionAttribute(request, localeAttributeName);
			if (locale == null) {
				locale = determineDefaultLocale(request);
			}
			return locale;
		}
		@Override
		public TimeZone getTimeZone() {
			TimeZone timeZone = (TimeZone) WebUtils.getSessionAttribute(request, timeZoneAttributeName);
			if (timeZone == null) {
				timeZone = determineDefaultTimeZone(request);
			}
			return timeZone;
		}
	};
}
 
Example #2
Source File: AngularCookieLocaleResolverTest.java    From jhipster with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #3
Source File: AngularCookieLocaleResolverTest.java    From jhipster with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #4
Source File: AngularCookieLocaleResolverTest.java    From jhipster with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #5
Source File: AngularCookieLocaleResolverTest.java    From jhipster with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #6
Source File: CookieLocaleResolver.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public LocaleContext resolveLocaleContext(final HttpServletRequest request) {
	parseLocaleCookieIfNecessary(request);
	return new TimeZoneAwareLocaleContext() {
		@Override
		@Nullable
		public Locale getLocale() {
			return (Locale) request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME);
		}
		@Override
		@Nullable
		public TimeZone getTimeZone() {
			return (TimeZone) request.getAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME);
		}
	};
}
 
Example #7
Source File: SessionLocaleResolver.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public LocaleContext resolveLocaleContext(final HttpServletRequest request) {
	return new TimeZoneAwareLocaleContext() {
		@Override
		public Locale getLocale() {
			Locale locale = (Locale) WebUtils.getSessionAttribute(request, localeAttributeName);
			if (locale == null) {
				locale = determineDefaultLocale(request);
			}
			return locale;
		}
		@Override
		@Nullable
		public TimeZone getTimeZone() {
			TimeZone timeZone = (TimeZone) WebUtils.getSessionAttribute(request, timeZoneAttributeName);
			if (timeZone == null) {
				timeZone = determineDefaultTimeZone(request);
			}
			return timeZone;
		}
	};
}
 
Example #8
Source File: CookieLocaleResolver.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public void setLocaleContext(HttpServletRequest request, @Nullable HttpServletResponse response,
		@Nullable LocaleContext localeContext) {

	Assert.notNull(response, "HttpServletResponse is required for CookieLocaleResolver");

	Locale locale = null;
	TimeZone timeZone = null;
	if (localeContext != null) {
		locale = localeContext.getLocale();
		if (localeContext instanceof TimeZoneAwareLocaleContext) {
			timeZone = ((TimeZoneAwareLocaleContext) localeContext).getTimeZone();
		}
		addCookie(response,
				(locale != null ? toLocaleValue(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)));
}
 
Example #9
Source File: CookieLocaleResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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", "++ 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());
}
 
Example #10
Source File: AngularCookieLocaleResolverTest.java    From jhipster with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #11
Source File: AngularCookieLocaleResolverTest.java    From jhipster with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #12
Source File: RequestContext.java    From java-technology-stack with MIT License 6 votes vote down vote up
public RequestContext(ServerWebExchange exchange, Map<String, Object> model, MessageSource messageSource,
		@Nullable RequestDataValueProcessor dataValueProcessor) {

	Assert.notNull(exchange, "ServerWebExchange is required");
	Assert.notNull(model, "Model is required");
	Assert.notNull(messageSource, "MessageSource is required");
	this.exchange = exchange;
	this.model = model;
	this.messageSource = messageSource;

	LocaleContext localeContext = exchange.getLocaleContext();
	Locale locale = localeContext.getLocale();
	this.locale = (locale != null ? locale : Locale.getDefault());
	TimeZone timeZone = (localeContext instanceof TimeZoneAwareLocaleContext ?
			((TimeZoneAwareLocaleContext) localeContext).getTimeZone() : null);
	this.timeZone = (timeZone != null ? timeZone : TimeZone.getDefault());

	this.defaultHtmlEscape = null;  // TODO
	this.dataValueProcessor = dataValueProcessor;
}
 
Example #13
Source File: CookieLocaleResolver.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public LocaleContext resolveLocaleContext(final HttpServletRequest request) {
	parseLocaleCookieIfNecessary(request);
	return new TimeZoneAwareLocaleContext() {
		@Override
		@Nullable
		public Locale getLocale() {
			return (Locale) request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME);
		}
		@Override
		@Nullable
		public TimeZone getTimeZone() {
			return (TimeZone) request.getAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME);
		}
	};
}
 
Example #14
Source File: CookieLocaleResolver.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public void setLocaleContext(HttpServletRequest request, @Nullable HttpServletResponse response,
		@Nullable LocaleContext localeContext) {

	Assert.notNull(response, "HttpServletResponse is required for CookieLocaleResolver");

	Locale locale = null;
	TimeZone timeZone = null;
	if (localeContext != null) {
		locale = localeContext.getLocale();
		if (localeContext instanceof TimeZoneAwareLocaleContext) {
			timeZone = ((TimeZoneAwareLocaleContext) localeContext).getTimeZone();
		}
		addCookie(response,
				(locale != null ? toLocaleValue(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)));
}
 
Example #15
Source File: SessionLocaleResolver.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public LocaleContext resolveLocaleContext(final HttpServletRequest request) {
	return new TimeZoneAwareLocaleContext() {
		@Override
		public Locale getLocale() {
			Locale locale = (Locale) WebUtils.getSessionAttribute(request, localeAttributeName);
			if (locale == null) {
				locale = determineDefaultLocale(request);
			}
			return locale;
		}
		@Override
		@Nullable
		public TimeZone getTimeZone() {
			TimeZone timeZone = (TimeZone) WebUtils.getSessionAttribute(request, timeZoneAttributeName);
			if (timeZone == null) {
				timeZone = determineDefaultTimeZone(request);
			}
			return timeZone;
		}
	};
}
 
Example #16
Source File: CookieLocaleResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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", "++ 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());
}
 
Example #17
Source File: SessionLocaleResolver.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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;
		}
	};
}
 
Example #18
Source File: CookieLocaleResolver.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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)));
}
 
Example #19
Source File: AngularCookieLocaleResolver.java    From jhipster with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public LocaleContext resolveLocaleContext(final HttpServletRequest request) {
    parseAngularCookieIfNecessary(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);
        }
    };
}
 
Example #20
Source File: RequestContext.java    From spring-analysis-note with MIT License 6 votes vote down vote up
public RequestContext(ServerWebExchange exchange, Map<String, Object> model, MessageSource messageSource,
		@Nullable RequestDataValueProcessor dataValueProcessor) {

	Assert.notNull(exchange, "ServerWebExchange is required");
	Assert.notNull(model, "Model is required");
	Assert.notNull(messageSource, "MessageSource is required");
	this.exchange = exchange;
	this.model = model;
	this.messageSource = messageSource;

	LocaleContext localeContext = exchange.getLocaleContext();
	Locale locale = localeContext.getLocale();
	this.locale = (locale != null ? locale : Locale.getDefault());
	TimeZone timeZone = (localeContext instanceof TimeZoneAwareLocaleContext ?
			((TimeZoneAwareLocaleContext) localeContext).getTimeZone() : null);
	this.timeZone = (timeZone != null ? timeZone : TimeZone.getDefault());

	this.defaultHtmlEscape = null;  // TODO
	this.dataValueProcessor = dataValueProcessor;
}
 
Example #21
Source File: CookieLocaleResolver.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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 ? toLocaleValue(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)));
}
 
Example #22
Source File: SessionLocaleResolver.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #23
Source File: CookieLocaleResolver.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
		}
	};
}
 
Example #24
Source File: AngularCookieLocaleResolver.java    From klask-io with GNU General Public License v3.0 5 votes vote down vote up
@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);
        }
    };
}
 
Example #25
Source File: AngularCookieLocaleResolver.java    From ServiceCutter with Apache License 2.0 5 votes vote down vote up
@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);
        }
    };
}
 
Example #26
Source File: FixedLocaleResolver.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public LocaleContext resolveLocaleContext(HttpServletRequest request) {
	return new TimeZoneAwareLocaleContext() {
		@Override
		public Locale getLocale() {
			return getDefaultLocale();
		}
		@Override
		public TimeZone getTimeZone() {
			return getDefaultTimeZone();
		}
	};
}
 
Example #27
Source File: CookieLocaleResolverTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testResolveLocaleContext() {
	MockHttpServletRequest request = new MockHttpServletRequest();
	Cookie cookie = new Cookie("LanguageKoekje", "nl");
	request.setCookies(cookie);

	CookieLocaleResolver resolver = new CookieLocaleResolver();
	// yup, koekje is the Dutch name for Cookie ;-)
	resolver.setCookieName("LanguageKoekje");
	LocaleContext loc = resolver.resolveLocaleContext(request);
	assertEquals("nl", loc.getLocale().getLanguage());
	assertTrue(loc instanceof TimeZoneAwareLocaleContext);
	assertNull(((TimeZoneAwareLocaleContext) loc).getTimeZone());
}
 
Example #28
Source File: CookieLocaleResolverTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testResolveLocaleContextWithTimeZone() {
	MockHttpServletRequest request = new MockHttpServletRequest();
	Cookie cookie = new Cookie("LanguageKoekje", "nl GMT+1");
	request.setCookies(cookie);

	CookieLocaleResolver resolver = new CookieLocaleResolver();
	// yup, koekje is the Dutch name for Cookie ;-)
	resolver.setCookieName("LanguageKoekje");
	LocaleContext loc = resolver.resolveLocaleContext(request);
	assertEquals("nl", loc.getLocale().getLanguage());
	assertTrue(loc instanceof TimeZoneAwareLocaleContext);
	assertEquals(TimeZone.getTimeZone("GMT+1"), ((TimeZoneAwareLocaleContext) loc).getTimeZone());
}
 
Example #29
Source File: FixedLocaleResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public LocaleContext resolveLocaleContext(HttpServletRequest request) {
	return new TimeZoneAwareLocaleContext() {
		@Override
		public Locale getLocale() {
			return getDefaultLocale();
		}
		@Override
		public TimeZone getTimeZone() {
			return getDefaultTimeZone();
		}
	};
}
 
Example #30
Source File: ServerWebExchangeMethodArgumentResolver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Nullable
private TimeZone getTimeZone(LocaleContext localeContext) {
	TimeZone timeZone = null;
	if (localeContext instanceof TimeZoneAwareLocaleContext) {
		timeZone = ((TimeZoneAwareLocaleContext) localeContext).getTimeZone();
	}
	return timeZone;
}