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


Java LocaleContext.getLocale方法代码示例

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


在下文中一共展示了LocaleContext.getLocale方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例4: 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());
	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:lamsfoundation,项目名称:lams,代码行数:24,代码来源:HttpComponentsHttpInvokerRequestExecutor.java

示例5: 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();
		}
	}
	WebUtils.setSessionAttribute(request, LOCALE_SESSION_ATTRIBUTE_NAME, locale);
	WebUtils.setSessionAttribute(request, TIME_ZONE_SESSION_ATTRIBUTE_NAME, timeZone);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:SessionLocaleResolver.java

示例6: initContext

import org.springframework.context.i18n.LocaleContext; //导入方法依赖的package包/类
/**
 * Initialize this context with the given request, using the given model attributes for Errors retrieval.
 * <p>Delegates to {@code getFallbackLocale} and {@code getFallbackTheme} for determining the fallback
 * locale and theme, respectively, if no LocaleResolver and/or ThemeResolver can be found in the request.
 * @param request current HTTP request
 * @param servletContext the servlet context of the web application (can be {@code null}; necessary for
 * fallback to root WebApplicationContext)
 * @param model the model attributes for the current view (can be {@code null}, using the request attributes
 * for Errors retrieval)
 * @see #getFallbackLocale
 * @see #getFallbackTheme
 * @see org.springframework.web.servlet.DispatcherServlet#LOCALE_RESOLVER_ATTRIBUTE
 * @see org.springframework.web.servlet.DispatcherServlet#THEME_RESOLVER_ATTRIBUTE
 */
protected void initContext(HttpServletRequest request, HttpServletResponse response, ServletContext servletContext,
		Map<String, Object> model) {

	this.request = request;
	this.response = response;
	this.model = model;

	// Fetch WebApplicationContext, either from DispatcherServlet or the root context.
	// ServletContext needs to be specified to be able to fall back to the root context!
	this.webApplicationContext = (WebApplicationContext) request.getAttribute(WEB_APPLICATION_CONTEXT_ATTRIBUTE);
	if (this.webApplicationContext == null) {
		this.webApplicationContext = RequestContextUtils.findWebApplicationContext(request, servletContext);
		if (this.webApplicationContext == null) {
			throw new IllegalStateException("No WebApplicationContext found: not in a DispatcherServlet " +
					"request and no ContextLoaderListener registered?");
		}
	}

	// Determine locale to use for this RequestContext.
	LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
	if (localeResolver instanceof LocaleContextResolver) {
		LocaleContext localeContext = ((LocaleContextResolver) localeResolver).resolveLocaleContext(request);
		this.locale = localeContext.getLocale();
		if (localeContext instanceof TimeZoneAwareLocaleContext) {
			this.timeZone = ((TimeZoneAwareLocaleContext) localeContext).getTimeZone();
		}
	}
	else if (localeResolver != null) {
		// Try LocaleResolver (we're within a DispatcherServlet request).
		this.locale = localeResolver.resolveLocale(request);
	}

	// Try JSTL fallbacks if necessary.
	if (this.locale == null) {
		this.locale = getFallbackLocale();
	}
	if (this.timeZone == null) {
		this.timeZone = getFallbackTimeZone();
	}

	// Determine default HTML escape setting from the "defaultHtmlEscape"
	// context-param in web.xml, if any.
	this.defaultHtmlEscape = WebUtils.getDefaultHtmlEscape(this.webApplicationContext.getServletContext());

	// Determine response-encoded HTML escape setting from the "responseEncodedHtmlEscape"
	// context-param in web.xml, if any.
	this.responseEncodedHtmlEscape = WebUtils.getResponseEncodedHtmlEscape(this.webApplicationContext.getServletContext());

	this.urlPathHelper = new UrlPathHelper();

	if (this.webApplicationContext.containsBean(RequestContextUtils.REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME)) {
		this.requestDataValueProcessor = this.webApplicationContext.getBean(
				RequestContextUtils.REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME, RequestDataValueProcessor.class);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:70,代码来源:RequestContext.java


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