Example usage for org.springframework.context.i18n LocaleContext LocaleContext

List of usage examples for org.springframework.context.i18n LocaleContext LocaleContext

Introduction

In this page you can find the example usage for org.springframework.context.i18n LocaleContext LocaleContext.

Prototype

LocaleContext

Source Link

Usage

From source file:com.mystudy.source.spring.mvc.DispatcherServlet.java

/**
 * Build a LocaleContext for the given request, exposing the request's primary locale as current locale.
 * <p>The default implementation uses the dispatcher's LocaleResolver to obtain the current locale,
 * which might change during a request.//w w  w.  jav a2 s  .c  o  m
 * @param request current HTTP request
 * @return the corresponding LocaleContext
 */
@Override
protected LocaleContext buildLocaleContext(final HttpServletRequest request) {
    return new LocaleContext() {
        public Locale getLocale() {
            return localeResolver.resolveLocale(request);
        }

        public String toString() {
            return getLocale().toString();
        }
    };
}

From source file:org.springframework.web.servlet.DispatcherServletMod.java

/**
 * Build a LocaleContext for the given request, exposing the request's
 * primary locale as current locale.//from  w  ww.ja  v  a  2s. c om
 * <p>
 * The default implementation uses the dispatcher's LocaleResolver to obtain
 * the current locale, which might change during a request.
 * 
 * @param request
 *            current HTTP request
 * @return the corresponding LocaleContext
 */
@Override
protected LocaleContext buildLocaleContext(final HttpServletRequest request) {
    if (this.localeResolver instanceof LocaleContextResolver) {
        return ((LocaleContextResolver) this.localeResolver).resolveLocaleContext(request);
    } else {
        return new LocaleContext() {
            @Override
            public Locale getLocale() {
                return localeResolver.resolveLocale(request);
            }
        };
    }
}

From source file:org.springframework.web.servlet.MyDispatcherServlet.java

/**
 * Build a LocaleContext for the given request, exposing the request's primary locale as current locale.
 * <p>The default implementation uses the dispatcher's LocaleResolver to obtain the current locale,
 * which might change during a request.// w  w  w. java  2 s  . c  o m
 * @param request current HTTP request
 * @return the corresponding LocaleContext
 */
@Override
protected LocaleContext buildLocaleContext(final HttpServletRequest request) {
    return new LocaleContext() {
        public Locale getLocale() {
            return localeResolver.resolveLocale(request);
        }

        @Override
        public String toString() {
            return getLocale().toString();
        }
    };
}