]> git.mxchange.org Git - jcoreee.git/commitdiff
Continued with refacturing:
authorRoland Haeder <roland@mxchange.org>
Fri, 11 Sep 2015 13:36:56 +0000 (15:36 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 11 Sep 2015 13:36:56 +0000 (15:36 +0200)
- added new validator for longs and amounts
- updated jars
Signed-off-by:Roland Häder <roland@mxchange.org>

lib/jcore-ee-logger.jar
lib/jcore.jar
src/org/mxchange/jcoreee/BaseEeSystem.java
src/org/mxchange/jcoreee/beans/BaseFrameworkBean.java
src/org/mxchange/jcoreee/validator/BaseObjectValidator.java
src/org/mxchange/jcoreee/validator/bool/BaseBooleanValidator.java
src/org/mxchange/jcoreee/validator/number/BaseLongValidator.java [new file with mode: 0644]
src/org/mxchange/jcoreee/validator/number/item_amount/ItemAmountValidator.java [new file with mode: 0644]
src/org/mxchange/jcoreee/validator/string/BaseStringValidator.java

index 6160458d2a2ce3da276e245a39698c4b05cd18cb..3c1fb7f8b083e1a84be405024abc1be40c559475 100644 (file)
Binary files a/lib/jcore-ee-logger.jar and b/lib/jcore-ee-logger.jar differ
index 00e90e137a26c3f568dd22c4d0d25b25b2c1c88a..6ee220159c66619b257eec183504a58dbf8e24ce 100644 (file)
Binary files a/lib/jcore.jar and b/lib/jcore.jar differ
index 6f655a4420e86f6b5cf81ec335284d40ffa1189b..56ddbdb77819e4aeae69a6c91c982d98c5056478 100644 (file)
@@ -26,7 +26,15 @@ public class BaseEeSystem {
        /**
         * Bundle instance
         */
-       private ResourceBundle bundle;
+       private volatile ResourceBundle bundle;
+
+       /**
+        * Protectd constructor
+        */
+       protected BaseEeSystem () {
+               // Load resource bundle
+               this.bundle = ResourceBundle.getBundle("org/mxchange/localization/bundle");
+       }
 
        /**
         * Getter for message from given key
@@ -35,6 +43,12 @@ public class BaseEeSystem {
         * @return Message
         */
        protected String getMessageStringFromKey (final String key) {
+               // Is the bundle loaded?
+               if (this.getBundle() == null) {
+                       // Abort here
+                       throw new NullPointerException("bundle is null"); //NOI18N
+               }
+
                // Return message
                return this.getBundle().getString(key);
        }
index 0a62f6e3a356d5c61b7cfff419a6462418dbb0ff..f801bb9d141539649340cb101b4b81cbf333d482 100644 (file)
@@ -44,8 +44,8 @@ public abstract class BaseFrameworkBean implements Serializable {
        }
 
        /**
-        * Super initialization method. If you overwrite this method, please call it
-        * before (!) your own initialization.
+        * Super initialization method. If you wrie your initialization method,
+        * please call this method before (!) your own initialization.
         *
         * @throws RuntimeException If something unexpected happens
         */
index 5e9d14aee5bbe56a829c68790fa53f91f4986a30..90a98df1186eba2aa36187f2033415da343d1067 100644 (file)
@@ -84,7 +84,8 @@ public abstract class BaseObjectValidator extends BaseEeSystem implements Valida
 
                                // Is it null?
                                if (null == value) {
-                                       errKey = String.format("error.%s.is_null", field); //NOI18N
+                                       // Generate message
+                                       errKey = String.format("ERROR_%s_IS_NULL", field.toUpperCase()); //NOI18N
 
                                        // Value it null
                                        facesMessage = new FacesMessage(getMessageStringFromKey(errKey));
index e0b3317d84c5a8a340db24bb9504aa0f1cbd7ba4..38fa468dcc3de2cc5143f43be9bf7ceefe0abc96 100644 (file)
@@ -45,6 +45,7 @@ public abstract class BaseBooleanValidator extends BaseObjectValidator implement
                // Get client id and init message + key
                String clientId = component.getClientId();
                FacesMessage facesMessage = null;
+               String requiredMessage = null;
 
                // So far all fine, no check if the field is fine
                for (final String field : requiredFields) {
@@ -55,8 +56,11 @@ public abstract class BaseBooleanValidator extends BaseObjectValidator implement
                        if (clientId.endsWith(field)) {
                                // Compare value's type
                                if (!(value instanceof Boolean)) {
+                                       // Generate message
+                                       requiredMessage = this.getMessageStringFromKey(String.format("ERROR_%s_IS_NOT_BOOLEAN", field.toUpperCase()));
+
                                        // Value is not right type
-                                       facesMessage = new FacesMessage(getMessageStringFromKey(String.format("error.%s.is_not_boolean", field))); //NOI18N
+                                       facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage); //NOI18N
                                        break;
                                }
 
@@ -66,7 +70,7 @@ public abstract class BaseBooleanValidator extends BaseObjectValidator implement
                                // Is it false?
                                if (bool.equals(Boolean.FALSE)) {
                                        // Default message
-                                       String requiredMessage = ((UIInput) component).getRequiredMessage();
+                                       requiredMessage = ((UIInput) component).getRequiredMessage();
 
                                        if (null == requiredMessage) {
                                                Object label = component.getAttributes().get("label"); //NOI18N
diff --git a/src/org/mxchange/jcoreee/validator/number/BaseLongValidator.java b/src/org/mxchange/jcoreee/validator/number/BaseLongValidator.java
new file mode 100644 (file)
index 0000000..d69333a
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2015 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.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcoreee.validator.number;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+import org.mxchange.jcoreee.validator.BaseObjectValidator;
+
+/**
+ * A general number value validator.
+ *
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+public abstract class BaseLongValidator extends BaseObjectValidator implements Validator {
+
+       @Override
+       public void preValidate (final FacesContext context, final UIComponent component, final Object value, final String[] requiredFields) throws ValidatorException {
+               // Trace message
+               //this.getLogger().logTrace(MessageFormat.format("preValidate: context={0},component={1},value={2},requiredFields={3} - CALLED!", context, component, value, Arrays.toString(requiredFields))); //NOI18N
+
+               // Pre-validate
+               super.preValidate(context, component, value, requiredFields);
+
+               // Get client id and init message + key
+               String clientId = component.getClientId();
+               FacesMessage facesMessage = null;
+               String requiredMessage = null;
+
+               // So far all fine, no check if the field is fine
+               for (final String field : requiredFields) {
+                       // Debug message
+                       //this.getLogger().logDebug(MessageFormat.format("preValidate: field={0},clientId={1}", field, clientId)); //NOI18N
+
+                       // Is it the same?
+                       if (clientId.endsWith(field)) {
+                               // Compare value's type
+                               if (!(value instanceof Long)) {
+                                       // Generate message
+                                       requiredMessage = this.getMessageStringFromKey(String.format("ERROR_%s_IS_NOT_LONG", field.toUpperCase()));
+
+                                       // Value is not right type
+                                       facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage); //NOI18N
+                                       break;
+                               }
+
+                               // Cast to string
+                               Long num = (Long) value;
+
+                               // Is the number below zero?
+                               if (num < 0) {
+                                       // Generate message
+                                       requiredMessage = this.getMessageStringFromKey(String.format("ERROR_%s_IS_BELOW_ZERO", field.toUpperCase()));
+
+                                       // Abort processing here
+                                       facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage);
+                                       break;
+                               }
+                       }
+               }
+
+               // Is facesMessage set?
+               if (facesMessage != null) {
+                       // Abort here
+                       throw new ValidatorException(facesMessage);
+               }
+       }
+}
diff --git a/src/org/mxchange/jcoreee/validator/number/item_amount/ItemAmountValidator.java b/src/org/mxchange/jcoreee/validator/number/item_amount/ItemAmountValidator.java
new file mode 100644 (file)
index 0000000..43e53b1
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2015 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.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcoreee.validator.number.item_amount;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+import org.mxchange.jcoreee.validator.string.BaseStringValidator;
+
+/**
+ * A validator for item amount
+ *
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+public class ItemAmountValidator extends BaseStringValidator implements Validator {
+
+       @Override
+       public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
+               // Trace message
+               //this.getLogger().logTrace(MessageFormat.format("validate: context={0},component={1},value={2} - CALLED!", context, component, value)); //NOI18N
+
+               // The required field
+               String[] requiredFileds = {"amount"}; //NOI18N
+
+               // Pre-validation (e.g. not null, not a string, empty string ...)
+               super.preValidate(context, component, value, requiredFileds);
+
+               // Trace message
+               //this.getLogger().logTrace("validate: EXIT!"); //NOI18N
+       }
+}
index 34203b56758fdf460382bb265858f6feea9013e8..b24565631f8c654917569c9e8b2ef2348936683b 100644 (file)
@@ -53,7 +53,7 @@ public abstract class BaseStringValidator extends BaseObjectValidator {
                                // Compare value's type
                                if (!(value instanceof String)) {
                                        // Value is empty
-                                       errKey = String.format("error.%s.is_not_string", field); //NOI18N
+                                       errKey = String.format("error_%s_is_not_string", field); //NOI18N
 
                                        facesMessage = new FacesMessage(getMessageStringFromKey(errKey));
                                }
@@ -64,7 +64,7 @@ public abstract class BaseStringValidator extends BaseObjectValidator {
                                // Is it empty?
                                if (str.isEmpty()) {
                                        // Value is empty
-                                       errKey = String.format("error.%s.is_empty", field); //NOI18N
+                                       errKey = String.format("error_%s_is_empty", field); //NOI18N
 
                                        facesMessage = new FacesMessage(getMessageStringFromKey(errKey));
                                }