List of usage examples for org.springframework.context.i18n LocaleContextHolder setLocale
public static void setLocale(@Nullable Locale locale, boolean inheritable)
From source file:at.porscheinformatik.common.spring.web.extended.locale.LocaleHandlerInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { for (LocaleSource source : sources) { Locale locale = source.getLocale(request, response); if (locale != null) { LocaleContextHolder.setLocale(locale, true); return true; }//from ww w .j a v a 2 s .c o m } // If no Locale is available we simply use the one from the request if (availableLocales == null || availableLocales.size() == 0) { return true; } // If no locale was found we check if the one from the request is // supported Locale locale = LocaleUtils.closestSupportedLocale(availableLocales, LocaleContextHolder.getLocale()); if (locale != null) { LocaleContextHolder.setLocale(locale); return true; } // If the locale from the request is not supported we use the first // supported locale LocaleContextHolder.setLocale(availableLocales.get(0)); return true; }
From source file:io.neba.core.spring.web.filter.NebaRequestContextFilter.java
private void initContextHolders(HttpServletRequest request, ServletRequestAttributes requestAttributes) { LocaleContextHolder.setLocale(request.getLocale(), this.threadContextInheritable); RequestContextHolder.setRequestAttributes(requestAttributes, this.threadContextInheritable); if (logger.isDebugEnabled()) { logger.debug("Bound request context to thread: " + request); }//from w ww . j a va 2s. co m }