當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。