01: /**
02: *
03: */package clime.messadmin.providers.spi;
04:
05: import java.util.Iterator;
06: import java.util.Locale;
07:
08: import javax.servlet.http.HttpSession;
09:
10: import clime.messadmin.providers.ProviderUtils;
11:
12: /**
13: * @author Cédrik LIME
14: */
15: public interface LocaleProvider extends BaseProvider {
16: public static class Util {
17: /**
18: * Try to get user locale from the session, if possible.
19: * @param httpSession
20: * @return Locale
21: */
22: public static Locale guessLocaleFromSession(
23: final HttpSession httpSession, ClassLoader cl) {
24: if (null == httpSession) {
25: return null;
26: }
27: try {
28: Iterator ps = ProviderUtils.getProviders(
29: LocaleProvider.class, cl).iterator();
30: while (ps.hasNext()) {
31: LocaleProvider provider = (LocaleProvider) ps
32: .next();
33: Locale locale = provider
34: .guessLocaleFromSession(httpSession);
35: if (locale != null)
36: return locale;
37: }
38: return null;
39: } catch (IllegalStateException ise) {
40: //ignore: invalidated session
41: return null;
42: }
43: }
44: }
45:
46: /**
47: * @param httpSession
48: * @return user locale for given HttpSession, or null if it can be determined
49: */
50: public Locale guessLocaleFromSession(HttpSession httpSession);
51: }
|