From 6dd098bade83caaae9c4b3450c7f6d696337b16b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 7 Jun 2017 22:50:01 +0200 Subject: [PATCH] moved generic methods to BaseBean MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../jjobs/beans/BaseJobsController.java | 159 +----------------- 1 file changed, 2 insertions(+), 157 deletions(-) diff --git a/src/java/org/mxchange/jjobs/beans/BaseJobsController.java b/src/java/org/mxchange/jjobs/beans/BaseJobsController.java index 95e40efb..16ba02af 100644 --- a/src/java/org/mxchange/jjobs/beans/BaseJobsController.java +++ b/src/java/org/mxchange/jjobs/beans/BaseJobsController.java @@ -17,13 +17,7 @@ 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; -import javax.faces.context.FacesContext; +import org.mxchange.jcoreee.bean.BaseBean; import org.mxchange.jusercore.model.user.UserUtils; /** @@ -31,7 +25,7 @@ import org.mxchange.jusercore.model.user.UserUtils; *

* @author Roland Häder */ -public abstract class BaseJobsController implements Serializable { +public abstract class BaseJobsController extends BaseBean implements Serializable { /** * Serial number @@ -44,97 +38,6 @@ public abstract class BaseJobsController implements Serializable { protected BaseJobsController () { } - /** - * Determines principal's name or returns null if no principal (security) is - * set. - *

- * @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. - *

- * @param parameterKey Property key - *

- * @return Property value - *

- * @throws NullPointerException If given key is not found - * @throws NumberFormatException If no number is given in context parameter - */ - protected int getIntegerContextParameter (final String parameterKey) throws NullPointerException, NumberFormatException { - // Get context parameter - Integer contextValue = Integer.parseInt(this.getStringContextParameter(parameterKey)); - - // Return it - return contextValue; - } - - /** - * Returns given property key or throws an exception if not found. - *

- * @param parameterKey Property key - *

- * @return Property value - *

- * @throws NullPointerException If given key is not found - */ - protected String getStringContextParameter (final String parameterKey) throws NullPointerException { - // Get context parameter - String contextValue = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(parameterKey); - - // Is it null? - if (null == contextValue) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("parameterKey={0} is not set.", parameterKey)); //NOI18N - } - - // Return it - return contextValue; - } - - /** - * Checks whether debug mode is enabled for given controller - *

- * @param controllerName Name of controller - *

- * @return Whether debug mode is enabled - */ - protected boolean isDebugModeEnabled (final String controllerName) { - // Parameters should be valid - if (null == controllerName) { - // Throw NPE - throw new NullPointerException("controllerName is null"); //NOI18N - } else if (controllerName.isEmpty()) { - // Is empty - throw new IllegalArgumentException("controllerName is empty"); //NOI18N - } - - // Try to get context parameter - String contextParameter = this.getStringContextParameter(String.format("is_debug_%s_enabled", controllerName)); //NOI18N - - // Is it set and true? - boolean isEnabled = (Boolean.parseBoolean(contextParameter) == Boolean.TRUE); - - // Return it - return isEnabled; - } - /** * Checks if given password is to weak to be used *

@@ -159,62 +62,4 @@ public abstract class BaseJobsController implements Serializable { return isWeak; } - /** - * Shows a faces message for given causing exception. The message from the - * exception is being inserted into the message. - *

- * @param clientId Client id to send message to - * @param cause Causing exception - */ - protected void showFacesMessage (final String clientId, final Throwable cause) { - // Get context and add message - this.showFacesMessage(clientId, cause.getMessage()); - } - - /** - * Shows a faces message with given message (i18n) key. - *

- * @param clientId Client id to send message to - * @param i18nKey Message key - *

- * @throws NullPointerException If clientId or i18nKey is null - * @throws IllegalArgumentException If clientId or i18nKey is empty - */ - protected void showFacesMessage (final String clientId, final String i18nKey) throws NullPointerException, IllegalArgumentException { - // Both parameter must be valid - if (null == clientId) { - // Throw NPE - throw new NullPointerException("clientId is null"); //NOI18N - } else if (clientId.isEmpty()) { - // Is empty - throw new IllegalArgumentException("clientId is null"); //NOI18N - } else if (null == i18nKey) { - // Throw NPE - throw new NullPointerException("i18nKey is null"); //NOI18N - } else if (i18nKey.isEmpty()) { - // Is empty - throw new IllegalArgumentException("i18nKey is null"); //NOI18N - } - - // Get current locale - Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); - - // Get bundle bundle - ResourceBundle bundle = ResourceBundle.getBundle("org.mxchange.localization.bundle", locale); - - // Default is i18nKey - String message = i18nKey; - - // Try it - try { - // Get message - message = bundle.getString(i18nKey); - } catch (final MissingResourceException ex) { - // Did not find it, ignored - } - - // Get context and add message - FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(message)); - } - } -- 2.39.5