/*
- * Copyright (C) 2016 Roland Haeder
+ * Copyright (C) 2016, 2017 Roland Häder
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
*/
package org.mxchange.pizzaapplication.beans;
-import java.io.Serializable;
-import java.text.MessageFormat;
-import javax.faces.application.FacesMessage;
-import javax.faces.context.FacesContext;
+import java.util.Locale;
+import java.util.ResourceBundle;
+import org.mxchange.jcoreee.bean.faces.BaseFacesBean;
/**
* A general controller
* <p>
- * @author Roland Haeder<roland@mxchange.org>
+ * @author Roland Häder<roland@mxchange.org>
*/
-public abstract class BasePizzaController implements Serializable {
+public abstract class BasePizzaController extends BaseFacesBean {
/**
* Serial number
private static final long serialVersionUID = 50_837_597_127_567_140L;
/**
- * Checks whether debug mode is enabled for given controller
- * <p>
- * @param controllerName Name of controller
- * <p>
- * @return Whether debug mode is enabled
+ * Protected constructor
*/
- 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 = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(String.format("is_debug_%s_enabled", controllerName)); //NOI18N
-
- // Is it set and true?
- boolean isEnabled = ((contextParameter instanceof String) && (contextParameter.equals("true"))); //NOI18N
-
- // Return it
- return isEnabled;
- }
-
- /**
- * Shows a faces message for given causing exception. The message from the
- * exception is being inserted into the message.
- * <p>
- * @param clientId Client id to send message to
- * @param cause Causing exception
- */
- protected void showFacesMessage (final String clientId, final Throwable cause) {
- // Trace message
- System.out.println(MessageFormat.format("showFacesMessage: clientId={0},cause={1} - CALLED!", clientId, cause));
-
- // Get context and add message
- FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(cause.getMessage()));
+ protected BasePizzaController () {
+ // Call super constructor
+ super();
}
- /**
- * Returns given property key or throws an exception if not found.
- * <p>
- * @param parameterKey Property key
- * <p>
- * @return Property value
- * <p>
- * @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.
- * <p>
- * @param parameterKey Property key
- * <p>
- * @return Property value
- * <p>
- * @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("parameterKey=" + parameterKey + " is not set.");
- }
+ @Override
+ protected ResourceBundle loadResourceBundle (final Locale locale) {
+ // Load resource bundle
+ ResourceBundle bundle = ResourceBundle.getBundle("org.mxchange.localization.bundle", locale);
// Return it
- return contextValue;
+ return bundle;
}
}