All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.apetrelli.gwtintegration.spring.web.SessionLocaleHolder Maven / Gradle / Ivy

The newest version!
package com.github.apetrelli.gwtintegration.spring.web;

import java.util.Locale;

import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

import com.github.apetrelli.gwtintegration.locale.server.LocaleHolder;

@Component
public class SessionLocaleHolder implements LocaleHolder {

	private static final String ATTRIBUTE_NAME = SessionLocaleHolder.class
			.getName() + ".ATTRIBUTE_NAME";

	@Override
	public void setLocale(Locale locale) {
		RequestContextHolder.getRequestAttributes().setAttribute(
				ATTRIBUTE_NAME, locale, RequestAttributes.SCOPE_SESSION);
	}

	@Override
	public Locale getLocale() {
		Locale locale = (Locale) RequestContextHolder.getRequestAttributes()
				.getAttribute(ATTRIBUTE_NAME, RequestAttributes.SCOPE_SESSION);
		if (locale == null) {
			locale = Locale.ROOT;
		}
		return locale;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy