]> git.mxchange.org Git - jjobs-war.git/blobdiff - src/java/org/mxchange/jjobs/beans/BaseJobsController.java
Please cherry-pick:
[jjobs-war.git] / src / java / org / mxchange / jjobs / beans / BaseJobsController.java
index d57534b76c89b355af79576a8013eee0de5918e3..a9f461ab756ed5bbe2cb4c4b700634ff96dfe256 100644 (file)
@@ -17,7 +17,9 @@
 package org.mxchange.jjobs.beans;
 
 import java.io.Serializable;
+import java.security.Principal;
 import java.text.MessageFormat;
+import java.util.Locale;
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
 import javax.faces.application.FacesMessage;
@@ -35,6 +37,29 @@ public abstract class BaseJobsController implements Serializable {
         */
        private static final long serialVersionUID = 50_837_597_127_567_140L;
 
+       /**
+        * Determines principal's name or returns null if no principal (security) is
+        * set.
+        * <p>
+        * @return Principal's name or null
+        */
+       protected String determinePrincipalName () {
+               // Get principal
+               Principal userPrincipal = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal();
+
+               // Init with null
+               String principalName = null;
+
+               // Is the principal set?
+               if (userPrincipal instanceof Principal) {
+                       // Get principal's name
+                       principalName = userPrincipal.getName();
+               }
+
+               // Return it
+               return principalName;
+       }
+
        /**
         * Returns given property key or throws an exception if not found.
         * <p>
@@ -131,23 +156,23 @@ public abstract class BaseJobsController implements Serializable {
                // Both parameter must be valid
                if (null == clientId) {
                        // Throw NPE
-                       throw new NullPointerException("clientId is null");
+                       throw new NullPointerException("clientId is null"); //NOI18N
                } else if (clientId.isEmpty()) {
                        // Is empty
-                       throw new IllegalArgumentException("clientId is null");
+                       throw new IllegalArgumentException("clientId is null"); //NOI18N
                } else if (null == i18nKey) {
                        // Throw NPE
-                       throw new NullPointerException("i18nKey is null");
+                       throw new NullPointerException("i18nKey is null"); //NOI18N
                } else if (i18nKey.isEmpty()) {
                        // Is empty
-                       throw new IllegalArgumentException("i18nKey is null");
+                       throw new IllegalArgumentException("i18nKey is null"); //NOI18N
                }
 
-               // Get facet context
-               FacesContext context = FacesContext.getCurrentInstance();
+               // Get current locale
+               Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
 
-               // Get bundle
-               ResourceBundle bundle = context.getApplication().getResourceBundle(context, "msg"); //NOI18N
+               // Get bundle bundle
+               ResourceBundle bundle = ResourceBundle.getBundle("org.mxchange.localization.bundle", locale);
 
                // Default is i18nKey
                String message = i18nKey;
@@ -161,7 +186,7 @@ public abstract class BaseJobsController implements Serializable {
                }
 
                // Get context and add message
-               context.addMessage(clientId, new FacesMessage(message));
+               FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(message));
        }
 
 }