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

clime.messadmin.providers.locale.ReflectionJBossSeamProvider Maven / Gradle / Ivy

Go to download

Notification system and Session administration for J2EE Web Applications

The newest version!
package clime.messadmin.providers.locale;

import java.lang.reflect.Method;
import java.util.Locale;

import javax.servlet.http.HttpSession;

import clime.messadmin.providers.spi.LocaleProvider;

/**
 * Note: this provider implementation uses reflexion, to avoid linking against Seam libs.
 * 
 * @author @author Cédrik LIME
 * @since 4.1
 */
public class ReflectionJBossSeamProvider implements LocaleProvider {
	protected static final String SEAM_LOCALE_KEY = "org.jboss.seam.core.localeSelector";//$NON-NLS-1$

	public ReflectionJBossSeamProvider() {
		super();
	}

	/**
	 * @see clime.messadmin.providers.spi.BaseProvider#getPriority()
	 */
	public int getPriority() {
		return 40;
	}

	/**
	 * @see clime.messadmin.providers.spi.UserNameProvider#guessUserFromSession(javax.servlet.http.HttpSession)
	 */
	public Locale guessLocaleFromSession(HttpSession httpSession) {
		Object identity = httpSession.getAttribute(SEAM_LOCALE_KEY);
		if (identity != null) {
			try {
				Method getLocaleMethod = identity.getClass().getMethod("getLocale", null);//$NON-NLS-1$
				return (Locale) getLocaleMethod.invoke(identity, null);
			} catch (Exception e) {
				// not a chance...
			}
		}
		return null;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy