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


Java LocaleContextHolder.getLocaleContext方法代码示例

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


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

示例1: prepareConnection

import org.springframework.context.i18n.LocaleContextHolder; //导入方法依赖的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: createHttpPost

import org.springframework.context.i18n.LocaleContextHolder; //导入方法依赖的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

示例3: createHttpPost

import org.springframework.context.i18n.LocaleContextHolder; //导入方法依赖的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

示例4: doFilter

import org.springframework.context.i18n.LocaleContextHolder; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 * 
 */
@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
        throws IOException, ServletException {

    HttpServletRequest request = (HttpServletRequest) req;

    Locale newLocale = extractLocale(request);
    if (newLocale != null) {
        if (getMasterDataManagement().isAvailableLanguage(newLocale)) {
            SessionHandler.instance().overrideCurrentUserLocale(request, newLocale);
        } else {
            LOGGER.debug("Locale/Language parameter was given in request but is not an "
                    + "registered language! locale={}", newLocale);
        }
    }

    LocaleContext oldLocaleContext = LocaleContextHolder.getLocaleContext();
    // expose a locale context which can access the SessionHandler so that the current locale
    // can be retrieved even at places where the current request is not available
    LocaleContextHolder.setLocaleContext(new SessionHandlerAwareLocaleContext(request));
    try {
        chain.doFilter(req, resp);
    } finally {
        LocaleContextHolder.setLocaleContext(oldLocaleContext);
    }

    // set the session locale for error pages (there no user is available)
    // request.setAttribute("overwrittenLocale",
    // SessionHandler.instance().getCurrentUserLocale(request));
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:35,代码来源:LanguageFilter.java


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