当前位置: 首页>>代码示例>>Java>>正文


Java LocaleContext类代码示例

本文整理汇总了Java中org.springframework.context.i18n.LocaleContext的典型用法代码示例。如果您正苦于以下问题:Java LocaleContext类的具体用法?Java LocaleContext怎么用?Java LocaleContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LocaleContext类属于org.springframework.context.i18n包,在下文中一共展示了LocaleContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: prepareConnection

import org.springframework.context.i18n.LocaleContext; //导入依赖的package包/类
/**
 * Prepare the given HTTP connection.
 * <p>The default implementation specifies POST as method,
 * "application/x-java-serialized-object" as "Content-Type" header,
 * and the given content length as "Content-Length" header.
 * @param connection the HTTP connection to prepare
 * @param contentLength the length of the content to send
 * @throws IOException if thrown by HttpURLConnection methods
 * @see java.net.HttpURLConnection#setRequestMethod
 * @see java.net.HttpURLConnection#setRequestProperty
 */
protected void prepareConnection(HttpURLConnection connection, int contentLength) throws IOException {
	if (this.connectTimeout >= 0) {
		connection.setConnectTimeout(this.connectTimeout);
	}
	if (this.readTimeout >= 0) {
		connection.setReadTimeout(this.readTimeout);
	}
	connection.setDoOutput(true);
	connection.setRequestMethod(HTTP_METHOD_POST);
	connection.setRequestProperty(HTTP_HEADER_CONTENT_TYPE, getContentType());
	connection.setRequestProperty(HTTP_HEADER_CONTENT_LENGTH, Integer.toString(contentLength));

	LocaleContext localeContext = LocaleContextHolder.getLocaleContext();
	if (localeContext != null) {
		Locale locale = localeContext.getLocale();
		if (locale != null) {
			connection.setRequestProperty(HTTP_HEADER_ACCEPT_LANGUAGE, StringUtils.toLanguageTag(locale));
		}
	}
	if (isAcceptGzipEncoding()) {
		connection.setRequestProperty(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:35,代码来源:SimpleHttpInvokerRequestExecutor.java

示例2: setLocaleContext

import org.springframework.context.i18n.LocaleContext; //导入依赖的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)));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:CookieLocaleResolver.java

示例3: resolveLocaleContext

import org.springframework.context.i18n.LocaleContext; //导入依赖的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;
		}
	};
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:SessionLocaleResolver.java

示例4: testSetAndResolveLocaleContext

import org.springframework.context.i18n.LocaleContext; //导入依赖的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());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:CookieLocaleResolverTests.java

示例5: testSetAndResolveLocaleContextWithTimeZone

import org.springframework.context.i18n.LocaleContext; //导入依赖的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());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:CookieLocaleResolverTests.java

示例6: testSetAndResolveLocaleContextWithTimeZoneOnly

import org.springframework.context.i18n.LocaleContext; //导入依赖的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());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:CookieLocaleResolverTests.java

示例7: createHttpPost

import org.springframework.context.i18n.LocaleContext; //导入依赖的package包/类
/**
 * Create a HttpPost for the given configuration.
 * <p>The default implementation creates a standard HttpPost with
 * "application/x-java-serialized-object" as "Content-Type" header.
 * @param config the HTTP invoker configuration that specifies the
 * target service
 * @return the HttpPost instance
 * @throws java.io.IOException if thrown by I/O methods
 */
protected HttpPost createHttpPost(HttpInvokerClientConfiguration config) throws IOException {
	HttpPost httpPost = new HttpPost(config.getServiceUrl());
	RequestConfig requestConfig = createRequestConfig(config);
	if (requestConfig != null) {
		httpPost.setConfig(requestConfig);
	}
	LocaleContext localeContext = LocaleContextHolder.getLocaleContext();
	if (localeContext != null) {
		Locale locale = localeContext.getLocale();
		if (locale != null) {
			httpPost.addHeader(HTTP_HEADER_ACCEPT_LANGUAGE, StringUtils.toLanguageTag(locale));
		}
	}
	if (isAcceptGzipEncoding()) {
		httpPost.addHeader(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
	}
	return httpPost;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:28,代码来源:HttpComponentsHttpInvokerRequestExecutor.java

示例8: testPresets

import org.springframework.context.i18n.LocaleContext; //导入依赖的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();
}
 
开发者ID:jhipster,项目名称:jhipster,代码行数:20,代码来源:AngularCookieLocaleResolverTest.java

示例9: testTimeZone

import org.springframework.context.i18n.LocaleContext; //导入依赖的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();
}
 
开发者ID:jhipster,项目名称:jhipster,代码行数:19,代码来源:AngularCookieLocaleResolverTest.java

示例10: testTimeZoneWithQuotes

import org.springframework.context.i18n.LocaleContext; //导入依赖的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();
}
 
开发者ID:jhipster,项目名称:jhipster,代码行数:19,代码来源:AngularCookieLocaleResolverTest.java

示例11: testLocaleAndTimeZone

import org.springframework.context.i18n.LocaleContext; //导入依赖的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();
}
 
开发者ID:jhipster,项目名称:jhipster,代码行数:19,代码来源:AngularCookieLocaleResolverTest.java

示例12: testLocaleAndTimeZoneWithQuotes

import org.springframework.context.i18n.LocaleContext; //导入依赖的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();
}
 
开发者ID:jhipster,项目名称:jhipster,代码行数:19,代码来源:AngularCookieLocaleResolverTest.java

示例13: testTraceLogLocaleAndTimeZone

import org.springframework.context.i18n.LocaleContext; //导入依赖的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();
}
 
开发者ID:jhipster,项目名称:jhipster,代码行数:25,代码来源:AngularCookieLocaleResolverTest.java

示例14: prepareConnection

import org.springframework.context.i18n.LocaleContext; //导入依赖的package包/类
/**
 * Prepare the given HTTP connection.
 * <p>
 * The default implementation specifies POST as method,
 * "application/x-java-serialized-object" as "Content-Type" header,
 * and the given content length as "Content-Length" header.
 *
 * @param connection the HTTP connection to prepare
 * @param contentLength the length of the content to send
 * @throws IOException if thrown by HttpURLConnection methods
 * @see java.net.HttpURLConnection#setRequestMethod
 * @see java.net.HttpURLConnection#setRequestProperty
 */
protected void prepareConnection(HttpURLConnection connection, int contentLength) throws IOException {
    if (this.connectTimeout >= 0)
        connection.setConnectTimeout(this.connectTimeout);
    if (this.readTimeout >= 0)
        connection.setReadTimeout(this.readTimeout);
    connection.setDoOutput(true);
    connection.setRequestMethod(HTTP_METHOD_POST);
    connection.setRequestProperty(HTTP_HEADER_CONTENT_TYPE, getContentType());
    connection.setRequestProperty(HTTP_HEADER_CONTENT_LENGTH, Integer.toString(contentLength));
    LocaleContext locale = LocaleContextHolder.getLocaleContext();
    if (locale != null)
        connection.setRequestProperty(HTTP_HEADER_ACCEPT_LANGUAGE, StringUtils.toLanguageTag(locale.getLocale()));
    if (isAcceptGzipEncoding())
        connection.setRequestProperty(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
}
 
开发者ID:shevek,项目名称:simple-xml-serializers,代码行数:29,代码来源:SimpleXmlInvokerRequestExecutor.java

示例15: testValidActionRequestWithExistingThreadLocalRequestContext

import org.springframework.context.i18n.LocaleContext; //导入依赖的package包/类
public void testValidActionRequestWithExistingThreadLocalRequestContext() throws IOException, PortletException {
		MockActionRequest request = new MockActionRequest();
		MockActionResponse response = new MockActionResponse();
		request.addPreferredLocale(Locale.GERMAN);
		request.setParameter("action", "form");
		request.setParameter("age", "29");

// see RequestContextListener.requestInitialized()
		try {
			LocaleContextHolder.setLocale(request.getLocale());
			RequestContextHolder.setRequestAttributes(new PortletRequestAttributes(request));

			LocaleContext servletLocaleContext = LocaleContextHolder.getLocaleContext();
			RequestAttributes servletRequestAttrs = RequestContextHolder.getRequestAttributes();

			simpleDispatcherPortlet.processAction(request, response);

			assertSame(servletLocaleContext, LocaleContextHolder.getLocaleContext());
			assertSame(servletRequestAttrs, RequestContextHolder.getRequestAttributes());
		}
		finally {
			RequestContextHolder.resetRequestAttributes();
			LocaleContextHolder.resetLocaleContext();
		}
	}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:26,代码来源:DispatcherPortletTests.java


注:本文中的org.springframework.context.i18n.LocaleContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。