
clime.messadmin.providers.spi.LocaleProvider Maven / Gradle / Ivy
The newest version!
/**
*
*/
package clime.messadmin.providers.spi;
import java.util.Iterator;
import java.util.Locale;
import javax.servlet.http.HttpSession;
import clime.messadmin.providers.ProviderUtils;
/**
* @author Cédrik LIME
*/
public interface LocaleProvider extends BaseProvider {
public static class Util {
/**
* Try to get user locale from the session, if possible.
* @param httpSession
* @return Locale
*/
public static Locale guessLocaleFromSession(final HttpSession httpSession, ClassLoader cl) {
if (null == httpSession) {
return null;
}
try {
Iterator ps = ProviderUtils.getProviders(LocaleProvider.class, cl).iterator();
while (ps.hasNext()) {
LocaleProvider provider = (LocaleProvider) ps.next();
Locale locale = provider.guessLocaleFromSession(httpSession);
if (locale != null)
return locale;
}
return null;
} catch (IllegalStateException ise) {
//ignore: invalidated session
return null;
}
}
}
/**
* @param httpSession
* @return user locale for given HttpSession, or null if it can be determined
*/
public Locale guessLocaleFromSession(HttpSession httpSession);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy