Java Code Examples for org.springframework.context.i18n.TimeZoneAwareLocaleContext

The following examples show how to use org.springframework.context.i18n.TimeZoneAwareLocaleContext. These examples are extracted from open source projects. 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 Project: spring-analysis-note   Source File: RequestContext.java    License: 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 2
Source Project: spring-analysis-note   Source File: CookieLocaleResolver.java    License: 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 3
Source Project: spring-analysis-note   Source File: CookieLocaleResolver.java    License: 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 4
Source Project: spring-analysis-note   Source File: SessionLocaleResolver.java    License: 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 5
Source Project: spring-analysis-note   Source File: CookieLocaleResolverTests.java    License: 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 6
Source Project: java-technology-stack   Source File: RequestContext.java    License: 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 7
Source Project: java-technology-stack   Source File: CookieLocaleResolver.java    License: 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 8
Source Project: java-technology-stack   Source File: CookieLocaleResolver.java    License: 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 Project: java-technology-stack   Source File: SessionLocaleResolver.java    License: 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 10
Source Project: java-technology-stack   Source File: CookieLocaleResolverTests.java    License: 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 11
Source Project: lams   Source File: CookieLocaleResolver.java    License: 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 12
Source Project: lams   Source File: SessionLocaleResolver.java    License: 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 13
@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 14
@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 15
Source Project: jhipster   Source File: AngularCookieLocaleResolver.java    License: 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 16
Source Project: jhipster   Source File: AngularCookieLocaleResolverTest.java    License: 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 17
Source Project: jhipster   Source File: AngularCookieLocaleResolverTest.java    License: 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 18
Source Project: jhipster   Source File: AngularCookieLocaleResolverTest.java    License: 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 19
Source Project: jhipster   Source File: AngularCookieLocaleResolverTest.java    License: 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 20
Source Project: jhipster   Source File: AngularCookieLocaleResolverTest.java    License: 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 21
Source Project: jhipster   Source File: AngularCookieLocaleResolverTest.java    License: 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 22
@Nullable
private TimeZone getTimeZone(LocaleContext localeContext) {
	TimeZone timeZone = null;
	if (localeContext instanceof TimeZoneAwareLocaleContext) {
		timeZone = ((TimeZoneAwareLocaleContext) localeContext).getTimeZone();
	}
	return timeZone;
}
 
Example 23
Source Project: spring-analysis-note   Source File: SessionLocaleResolver.java    License: MIT License 5 votes vote down vote up
@Override
public void setLocaleContext(HttpServletRequest request, @Nullable HttpServletResponse response,
		@Nullable 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, this.localeAttributeName, locale);
	WebUtils.setSessionAttribute(request, this.timeZoneAttributeName, timeZone);
}
 
Example 24
Source Project: spring-analysis-note   Source File: FixedLocaleResolver.java    License: MIT License 5 votes vote down vote up
@Override
public LocaleContext resolveLocaleContext(HttpServletRequest request) {
	return new TimeZoneAwareLocaleContext() {
		@Override
		@Nullable
		public Locale getLocale() {
			return getDefaultLocale();
		}
		@Override
		public TimeZone getTimeZone() {
			return getDefaultTimeZone();
		}
	};
}
 
Example 25
Source Project: spring-analysis-note   Source File: CookieLocaleResolverTests.java    License: MIT License 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();
	resolver.setCookieName("LanguageKoekje");
	LocaleContext loc = resolver.resolveLocaleContext(request);
	assertEquals("nl", loc.getLocale().getLanguage());
	assertTrue(loc instanceof TimeZoneAwareLocaleContext);
	assertNull(((TimeZoneAwareLocaleContext) loc).getTimeZone());
}
 
Example 26
Source Project: spring-analysis-note   Source File: CookieLocaleResolverTests.java    License: MIT License 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();
	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 27
Source Project: spring-analysis-note   Source File: CookieLocaleResolverTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testResolveLocaleContextWithInvalidTimeZoneOnErrorDispatch() {
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE, new ServletException());
	Cookie cookie = new Cookie("LanguageKoekje", "nl X-MT");
	request.setCookies(cookie);

	CookieLocaleResolver resolver = new CookieLocaleResolver();
	resolver.setDefaultTimeZone(TimeZone.getTimeZone("GMT+2"));
	resolver.setCookieName("LanguageKoekje");
	LocaleContext loc = resolver.resolveLocaleContext(request);
	assertEquals("nl", loc.getLocale().getLanguage());
	assertTrue(loc instanceof TimeZoneAwareLocaleContext);
	assertEquals(TimeZone.getTimeZone("GMT+2"), ((TimeZoneAwareLocaleContext) loc).getTimeZone());
}
 
Example 28
Source Project: spring-analysis-note   Source File: CookieLocaleResolverTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testResolveLocaleContextWithoutCookie() {
	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());
}
 
Example 29
Source Project: spring-analysis-note   Source File: CookieLocaleResolverTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testResolveLocaleContextWithoutCookieAndDefaultLocale() {
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.addPreferredLocale(Locale.TAIWAN);

	CookieLocaleResolver resolver = new CookieLocaleResolver();
	resolver.setDefaultLocale(Locale.GERMAN);
	resolver.setDefaultTimeZone(TimeZone.getTimeZone("GMT+1"));

	LocaleContext loc = resolver.resolveLocaleContext(request);
	assertEquals(Locale.GERMAN, loc.getLocale());
	assertTrue(loc instanceof TimeZoneAwareLocaleContext);
	assertEquals(TimeZone.getTimeZone("GMT+1"), ((TimeZoneAwareLocaleContext) loc).getTimeZone());
}
 
Example 30
Source Project: spring-analysis-note   Source File: CookieLocaleResolverTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testResolveLocaleContextWithCookieWithoutLocale() {
	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());
}