]> git.mxchange.org Git - jjobs-war.git/blobdiff - src/java/org/mxchange/jjobs/beans/localization/JobsLocalizationSessionBean.java
Continued a bit:
[jjobs-war.git] / src / java / org / mxchange / jjobs / beans / localization / JobsLocalizationSessionBean.java
index 5deb38bdfb11cd590ba8e03a2b7d4bcbbdcb81ba..6219df0cd58293126d34bb52f4ece77a1537ac22 100644 (file)
@@ -2,26 +2,26 @@
  * Copyright (C) 2016 Roland Haeder
  *
  * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * GNU Affero General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
+ * You should have received a copy of the GNU Affero General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 package org.mxchange.jjobs.beans.localization;
 
 import java.util.Locale;
 import javax.annotation.PostConstruct;
-import javax.faces.bean.SessionScoped;
+import javax.enterprise.context.SessionScoped;
 import javax.faces.context.FacesContext;
 import javax.inject.Named;
-import org.mxchange.jcoreee.database.BaseDatabaseBean;
+import org.mxchange.jjobs.beans.BaseJobsController;
 
 /**
  * A session bean for handling localization/internationalization changes. This
@@ -31,9 +31,9 @@ import org.mxchange.jcoreee.database.BaseDatabaseBean;
  * <p>
  * @author Roland Haeder<roland@mxchange.org>
  */
-@Named ("localization")
+@Named ("localizationController")
 @SessionScoped
-public class JobsLocalizationSessionBean extends BaseDatabaseBean implements LocalizationSessionController {
+public class JobsLocalizationSessionBean extends BaseJobsController implements JobsLocalizationSessionController {
 
        /**
         * Serial number
@@ -45,26 +45,83 @@ public class JobsLocalizationSessionBean extends BaseDatabaseBean implements Loc
         */
        private Locale locale;
 
+       @Override
+       public String getLanguage () {
+               //this.getLoggerBeanLocal().logTrace(MessageFormat.format("RecruiterLocalizationSessionBean::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("RecruiterLocalizationSessionBean::setLanguage: language={0} - CALLED!", language)); //NOI18N
+
+               // Is the language null?
+               if (null == language) {
+                       // This may sometimes happen, so abort here
+                       return;
+               }
+
+               // Language splits
+               String[] splits = language.split("_"); //NOI18N
+               if (null == splits[1]) {
+                       splits[1] = ""; //NOI18N
+               }
+
+               // Get new locale with upper-case country code
+               Locale loc = new Locale(splits[0], splits[1]);
+
+               // Log debug message
+               //this.getLoggerBeanLocal().logDebug(MessageFormat.format("RecruiterLocalizationSessionBean::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("RecruiterLocalizationSessionBean::setLanguage: EXIT!"); //NOI18N
+       }
+
        @Override
        public Locale getLocale () {
+               //this.getLoggerBeanLocal().logTrace(MessageFormat.format("RecruiterLocalizationSessionBean::getLocale(): locale={0} - EXIT!", this.locale)); //NOI18N
                return this.locale;
        }
 
        @Override
        public void setLocale (final Locale locale) {
+               //this.getLoggerBeanLocal().logTrace(MessageFormat.format("RecruiterLocalizationSessionBean::setLocale(): locale={0} - CALLED!", locale)); //NOI18N
                this.locale = locale;
        }
 
+       @Override
+       public Locale[] getSelectableLocalizations () {
+               Locale[] locales = {
+                       Locale.GERMANY,
+                       Locale.US
+               };
+               return locales;
+       }
+
        /**
         * Initializer for this bean
         */
        @PostConstruct
        public void init () {
+               // Log trace message
+               //this.getLoggerBeanLocal().logTrace("RecruiterLocalizationSessionBean::init: CALLED!"); //NOI18N
+
                // Create locale instance from context
                Locale loc = FacesContext.getCurrentInstance().getExternalContext().getRequestLocale();
 
+               // Log debug message
+               //this.getLoggerBeanLocal().logDebug(MessageFormat.format("RecruiterLocalizationSessionBean::init: loc={0}", loc)); //NOI18N
+
                // Set it here
                this.setLocale(loc);
+
+               // Log trace message
+               //this.getLoggerBeanLocal().logTrace("RecruiterLocalizationSessionBean::init: EXIT!"); //NOI18N
        }
 
 }