*/
package org.mxchange.jjobs.beans.localization;
+import java.text.MessageFormat;
import java.util.Locale;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Observes;
import javax.faces.context.FacesContext;
import javax.inject.Named;
-import org.mxchange.jcoreee.database.BaseDatabaseBean;
+import org.mxchange.jjobs.beans.BaseJobsController;
+import org.mxchange.jusercore.events.login.UserLoggedInEvent;
+import org.mxchange.jusercore.events.logout.ObserveableUserLogoutEvent;
/**
* A session bean for handling localization/internationalization changes. This
*/
@Named ("localizationController")
@SessionScoped
-public class JobsLocalizationSessionBean extends BaseDatabaseBean implements JobsLocalizationSessionController {
+public class JobsLocalizationSessionBean extends BaseJobsController implements JobsLocalizationSessionController {
/**
* Serial number
*/
private Locale locale;
+ @Override
+ public void afterUserLoginEvent (@Observes final UserLoggedInEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getLoggedInUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.loggedInUser is null"); //NOI18N
+ } else if (event.getLoggedInUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
+ } else if (event.getLoggedInUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
+ }
+
+ // Is the locale set?
+ if (event.getLoggedInUser().getUserLocale() instanceof Locale) {
+ // Set locale here
+ this.setLocale(event.getLoggedInUser().getUserLocale());
+ }
+ }
+
+ @Override
+ public void afterUserLogoutEvent (@Observes final ObserveableUserLogoutEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getLoggedOutUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.loggedOutUser is null"); //NOI18N
+ } else if (event.getLoggedOutUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.loggedOutUser.userId is null"); //NOI18N
+ } else if (event.getLoggedOutUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedOutUser(), event.getLoggedOutUser().getUserId())); //NOI18N
+ }
+
+ // Trace message
+ //* NOISY-DEBUG: */ System.out.println("LandingLocalizationSessionBean:afterUserLogin - EXIT!"); //NOI18N
+ }
+
@Override
public String getLanguage () {
- //this.getLoggerBeanLocal().logTrace(MessageFormat.format("JobsLocalizationSessionBean::getLanguage(): locale.language={0} - EXIT!", this.getLocale().getLanguage())); //NOI18N
+ //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("JobsLocalizationSessionBean::getLanguage(): locale.language={0} - EXIT!", this.getLocale().getLanguage())); //NOI18N
return this.getLocale().getLanguage().toLowerCase();
}
@Override
public void setLanguage (final String language) {
// Log trace message
- //this.getLoggerBeanLocal().logTrace(MessageFormat.format("JobsLocalizationSessionBean::setLanguage: language={0} - CALLED!", language)); //NOI18N
+ //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("JobsLocalizationSessionBean::setLanguage: language={0} - CALLED!", language)); //NOI18N
// Is the language null?
if (null == language) {
Locale loc = new Locale(splits[0], splits[1]);
// Log debug message
- //this.getLoggerBeanLocal().logDebug(MessageFormat.format("JobsLocalizationSessionBean::setLanguage: loc={0}", loc)); //NOI18N
+ //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("JobsLocalizationSessionBean::setLanguage: loc={0}", loc)); //NOI18N
// Set it here and in the JSF context
this.setLocale(loc);
FacesContext.getCurrentInstance().getViewRoot().setLocale(loc);
// Log trace message
- //this.getLoggerBeanLocal().logTrace("JobsLocalizationSessionBean::setLanguage: EXIT!"); //NOI18N
+ //* NOISY-DEBUG: */ System.out.println("JobsLocalizationSessionBean::setLanguage: EXIT!"); //NOI18N
}
@Override
public Locale getLocale () {
- //this.getLoggerBeanLocal().logTrace(MessageFormat.format("JobsLocalizationSessionBean::getLocale(): locale={0} - EXIT!", this.locale)); //NOI18N
+ //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("JobsLocalizationSessionBean::getLocale(): locale={0} - EXIT!", this.locale)); //NOI18N
return this.locale;
}
@Override
public void setLocale (final Locale locale) {
- //this.getLoggerBeanLocal().logTrace(MessageFormat.format("JobsLocalizationSessionBean::setLocale(): locale={0} - CALLED!", locale)); //NOI18N
+ //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("JobsLocalizationSessionBean::setLocale(): locale={0} - CALLED!", locale)); //NOI18N
this.locale = locale;
}
@PostConstruct
public void init () {
// Log trace message
- //this.getLoggerBeanLocal().logTrace("JobsLocalizationSessionBean::init: CALLED!"); //NOI18N
+ //* NOISY-DEBUG: */ System.out.println("JobsLocalizationSessionBean::init: CALLED!"); //NOI18N
// Create locale instance from context
Locale loc = FacesContext.getCurrentInstance().getExternalContext().getRequestLocale();
// Log debug message
- //this.getLoggerBeanLocal().logDebug(MessageFormat.format("JobsLocalizationSessionBean::init: loc={0}", loc)); //NOI18N
+ //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("JobsLocalizationSessionBean::init: loc={0}", loc)); //NOI18N
// Set it here
this.setLocale(loc);
// Log trace message
- //this.getLoggerBeanLocal().logTrace("JobsLocalizationSessionBean::init: EXIT!"); //NOI18N
+ //* NOISY-DEBUG: */ System.out.println("JobsLocalizationSessionBean::init: EXIT!"); //NOI18N
}
}