01: package clime.messadmin.providers.locale;
02:
03: import java.lang.reflect.Method;
04: import java.util.Locale;
05:
06: import javax.servlet.http.HttpSession;
07:
08: import clime.messadmin.providers.spi.LocaleProvider;
09:
10: /**
11: * Note: this provider implementation uses reflexion, to avoid linking against Seam libs.
12: *
13: * @author @author Cédrik LIME
14: * @since 4.1
15: */
16: public class ReflectionJBossSeamProvider implements LocaleProvider {
17: protected static final String SEAM_LOCALE_KEY = "org.jboss.seam.core.localeSelector";//$NON-NLS-1$
18:
19: public ReflectionJBossSeamProvider() {
20: super ();
21: }
22:
23: /**
24: * @see clime.messadmin.providers.spi.BaseProvider#getPriority()
25: */
26: public int getPriority() {
27: return 40;
28: }
29:
30: /**
31: * @see clime.messadmin.providers.spi.UserNameProvider#guessUserFromSession(javax.servlet.http.HttpSession)
32: */
33: public Locale guessLocaleFromSession(HttpSession httpSession) {
34: Object identity = httpSession.getAttribute(SEAM_LOCALE_KEY);
35: if (identity != null) {
36: try {
37: Method getLocaleMethod = identity.getClass().getMethod(
38: "getLocale", null);//$NON-NLS-1$
39: return (Locale) getLocaleMethod.invoke(identity, null);
40: } catch (Exception e) {
41: // not a chance...
42: }
43: }
44: return null;
45: }
46:
47: }
|