]> git.mxchange.org Git - jcoreee.git/commitdiff
updated jar(s)
authorRoland Häder <roland@mxchange.org>
Mon, 31 Jul 2017 20:29:03 +0000 (22:29 +0200)
committerRoland Häder <roland@mxchange.org>
Sat, 5 Aug 2017 14:55:56 +0000 (16:55 +0200)
Signed-off-by: Roland Häder <roland@mxchange.org>
src/org/mxchange/jcoreee/validator/BaseObjectValidator.java
src/org/mxchange/jcoreee/validator/bool/BaseBooleanValidator.java
src/org/mxchange/jcoreee/validator/date/BaseDateValidator.java
src/org/mxchange/jcoreee/validator/number/BaseLongValidator.java [deleted file]
src/org/mxchange/jcoreee/validator/number/BaseNumberValidator.java [new file with mode: 0644]
src/org/mxchange/jcoreee/validator/string/BaseStringValidator.java

index 6fc1583f6f4d3e578652a0e4e3ea703184f99574..4f19b933f9a4babdda85a0ce0098d1ae1386234c 100644 (file)
@@ -45,11 +45,11 @@ public abstract class BaseObjectValidator implements Validator, Serializable {
         * component's id has been found, it stops iteration on requiredFields
         * (which saves execution time).
         * <p>
-        * @param context FacesContext instance
-        * @param component UIComponent instance
-        * @param value Value to check
+        * @param context        FacesContext instance
+        * @param component      UIComponent instance
+        * @param value          Value to check
         * @param requiredFields Array of required field names (ending with)
-        * @param allowNull Wether null or empty values are allowed
+        * @param allowNull      Wether null or empty values are allowed
         * <p>
         * @throws ValidatorException If something more horrible went wrong
         */
@@ -58,14 +58,11 @@ public abstract class BaseObjectValidator implements Validator, Serializable {
                //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("preValidate: context={0},component={1},value={2},requiredFields={3} - CALLED!", context, component, value, Arrays.toString(requiredFields))); //NOI18N
 
                // Init message and key
-               FacesMessage facesMessage = null;
+               String requiredMessage = null;
 
                // Get client id
                final String clientId = component.getClientId();
 
-               // Default is no field is valid
-               boolean isValidField = false;
-
                // Check component's id against required fields and find a match
                for (final String field : requiredFields) {
                        // Get logger
@@ -73,13 +70,10 @@ public abstract class BaseObjectValidator implements Validator, Serializable {
 
                        // Is it the same?
                        if (clientId.endsWith(field)) {
-                               // Is valid field
-                               isValidField = true;
-
                                // Is it null?
                                if ((!allowNull) && (null == value)) {
                                        // Value it null
-                                       facesMessage = new FacesMessage(MessageFormat.format("Field {0} is null.", field)); //NOI18N
+                                       requiredMessage = MessageFormat.format("Field {0} is null.", field); //NOI18N
                                }
 
                                // Abort here
@@ -88,20 +82,10 @@ public abstract class BaseObjectValidator implements Validator, Serializable {
                }
 
                // Debug message
-               //this.getLogger().logDebug(MessageFormat.format("preValidate: isValidField={0}", isValidField)); //NOI18N
-
-               // Valid field?
-               if (!isValidField) {
-                       // Invalid field
-                       facesMessage = new FacesMessage(MessageFormat.format("Value {0} for clientId={1} is not valid/unexpected.", value, clientId)); //NOI18N
-               }
-
-               // Debug message
-               //this.getLogger().logDebug(MessageFormat.format("preValidate: facesMessage={0}", facesMessage)); //NOI18N
-
+               //* NOISY-DEBUG: */ this.getLogger().logDebug(MessageFormat.format("preValidate: requiredMessage={0}", requiredMessage)); //NOI18N
                // Is it not null?
-               if (null != facesMessage) {
-                       throw new ValidatorException(facesMessage);
+               if (null != requiredMessage) {
+                       throw new ValidatorException(new FacesMessage(MessageFormat.format("Value {0} for clientId={1} is not valid/unexpected.", value, clientId)));
                }
 
                // Trace message
index 0194bdb2c999a6f09a32b92adb255398e384f1fa..7cbad80942bae6cf74643a9cbda25f280b946643 100644 (file)
@@ -49,8 +49,7 @@ public abstract class BaseBooleanValidator extends BaseObjectValidator implement
 
                // Get client id and init message + key
                String clientId = component.getClientId();
-               FacesMessage facesMessage = null;
-               String requiredMessage;
+               String requiredMessage = null;
 
                // So far all fine, no check if the field is fine
                for (final String field : requiredFields) {
@@ -65,7 +64,6 @@ public abstract class BaseBooleanValidator extends BaseObjectValidator implement
                                        requiredMessage = MessageFormat.format("Field {0} is not Boolean: {1}", field, value); //NOI18N
 
                                        // Value is not right type
-                                       facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage); //NOI18N
                                        break;
                                }
 
@@ -98,16 +96,15 @@ public abstract class BaseBooleanValidator extends BaseObjectValidator implement
                                        }
 
                                        // Abort processing here
-                                       facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage);
                                        break;
                                }
                        }
                }
 
                // Is facesMessage set?
-               if (null != facesMessage) {
+               if (null != requiredMessage) {
                        // Abort here
-                       throw new ValidatorException(facesMessage);
+                       throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage));
                }
        }
 
index 726ba1fed9563710aa1582f4b7a44ae8d471bb7b..37be7f2a8376e9e941936f06690beddc302c8a14 100644 (file)
@@ -46,8 +46,7 @@ public abstract class BaseDateValidator extends BaseObjectValidator {
 
                // Get client id and init message + key
                String clientId = component.getClientId();
-               FacesMessage facesMessage = null;
-               String requiredMessage;
+               String requiredMessage = null;
 
                // So far all fine, no check if the field is fine
                for (final String field : requiredFields) {
@@ -62,7 +61,6 @@ public abstract class BaseDateValidator extends BaseObjectValidator {
                                        requiredMessage = MessageFormat.format("Field {0} is not Date: {1}", field, value); //NOI18N
 
                                        // Value is not right type
-                                       facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage); //NOI18N
                                        break;
                                }
 
@@ -74,9 +72,9 @@ public abstract class BaseDateValidator extends BaseObjectValidator {
                }
 
                // Is facesMessage set?
-               if (null != facesMessage) {
+               if (null != requiredMessage) {
                        // Abort here
-                       throw new ValidatorException(facesMessage);
+                       throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage));
                }
        }
 
diff --git a/src/org/mxchange/jcoreee/validator/number/BaseLongValidator.java b/src/org/mxchange/jcoreee/validator/number/BaseLongValidator.java
deleted file mode 100644 (file)
index d44ce31..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * 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 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 java.text.MessageFormat;
-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.
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public abstract class BaseLongValidator extends BaseObjectValidator implements Validator {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 25_481_878_590_589_321L;
-
-       @Override
-       public void preValidate (final FacesContext context, final UIComponent component, final Object value, final String[] requiredFields, Boolean allowNull) throws ValidatorException {
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("preValidate: context={0},component={1},value={2},requiredFields={3},allowNull={4} - CALLED!", context, component, value, Arrays.toString(requiredFields, allowNull))); //NOI18N
-
-               // Pre-validate
-               super.preValidate(context, component, value, requiredFields, allowNull);
-
-               // 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)) {
-                               // Init variables
-                               Integer i = null;
-                               Long l = null;
-
-                               // Compare value's type
-                               if (value instanceof String) {
-                                       // Is a string, try long
-                                       try {
-                                               l = Long.valueOf((String) value);
-                                       } catch (final NumberFormatException ex) {
-                                               // Cannot parse string to long
-                                               requiredMessage = MessageFormat.format("Field {0} cannot be parsed to long: {1}, exception:{2}", field, value, ex);
-
-                                               // Abort processing here
-                                               break;
-                                       }
-                               } else if (value instanceof Integer) {
-                                       // Is integer
-                                       i = (Integer) value;
-                               } else if (value instanceof Long) {
-                                       // Is long
-                                       l = (Long) value;
-                               }
-
-                               // Is the number below zero?
-                               if ((!allowNull) && ((i instanceof Integer) && (i < 0))) {
-                                       // Generate message
-                                       requiredMessage = MessageFormat.format("Value {0} for field {1} is below zero.", i, field); //NOI18N
-
-                                       // Abort processing here
-                                       break;
-                               } else if ((!allowNull) && ((l instanceof Long) && (l < 0))) {
-                                       // Generate message
-                                       requiredMessage = MessageFormat.format("Value {0} for field {1} is below zero.", l, field); //NOI18N
-
-                                       // Abort processing here
-                                       break;
-                               }
-                       }
-               }
-
-               // Is requiredMessage set?
-               if (null != requiredMessage) {
-                       // Embed into FacesMessage
-                       facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage);
-               }
-
-               // Is facesMessage set?
-               if (null != facesMessage) {
-                       // Abort here
-                       throw new ValidatorException(facesMessage);
-               }
-       }
-
-}
diff --git a/src/org/mxchange/jcoreee/validator/number/BaseNumberValidator.java b/src/org/mxchange/jcoreee/validator/number/BaseNumberValidator.java
new file mode 100644 (file)
index 0000000..f5ddf22
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * 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 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 java.text.MessageFormat;
+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.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public abstract class BaseNumberValidator extends BaseObjectValidator implements Validator {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 25_481_878_590_589_321L;
+
+       @Override
+       public void preValidate (final FacesContext context, final UIComponent component, final Object value, final String[] requiredFields, Boolean allowNull) throws ValidatorException {
+               // Trace message
+               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("preValidate: context={0},component={1},value={2},requiredFields={3},allowNull={4} - CALLED!", context, component, value, Arrays.toString(requiredFields, allowNull))); //NOI18N
+
+               // Pre-validate
+               super.preValidate(context, component, value, requiredFields, allowNull);
+
+               // Get client id and init message + key
+               String clientId = component.getClientId();
+               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)) {
+                               // Init variables
+                               Number number = null;
+
+                               // Compare value's type, supported: String, Long, Integer
+                               if (value instanceof String) {
+                                       // Is a string, then try to parse it as Long, largest range
+                                       try {
+                                               number = Long.valueOf((String) value);
+                                       } catch (final NumberFormatException ex) {
+                                               // Cannot parse string to long
+                                               requiredMessage = MessageFormat.format("Field {0} cannot be parsed to long: {1}, exception:{2}", field, value, ex);
+
+                                               // Abort processing here
+                                               break;
+                                       }
+                               } else if ((value instanceof Integer) || (value instanceof Long) || (value instanceof Short)) {
+                                       // Is any used number
+                                       number = (Number) value;
+                               }
+
+                               // Is the number below zero? Casting again largest range will not result in unexpected comparison
+                               if ((!allowNull) && ((number instanceof Number) && ((Long) number < 0))) {
+                                       // Generate message
+                                       requiredMessage = MessageFormat.format("Value {0} for field {1} is below zero.", number, field); //NOI18N
+
+                                       // Abort processing here
+                                       break;
+                               }
+                       }
+               }
+
+               // Is facesMessage set?
+               if (null != requiredMessage) {
+                       // Abort here
+                       throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage));
+               }
+       }
+
+}
index c13116b24090218bd031722a4dc9bf5b3847bcab..84fc78131e4fb5a675b73c743335f8c0f54d448a 100644 (file)
@@ -46,7 +46,7 @@ public abstract class BaseStringValidator extends BaseObjectValidator {
 
                // 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) {
@@ -58,7 +58,7 @@ public abstract class BaseStringValidator extends BaseObjectValidator {
                                // Compare value's type
                                if ((!allowNull) && (!(value instanceof String))) {
                                        // Value is empty
-                                       facesMessage = new FacesMessage(MessageFormat.format("Field {0} is not String: {1}", field, value)); //NOI18N
+                                       requiredMessage = MessageFormat.format("Field {0} is not String: {1}", field, value); //NOI18N
                                }
 
                                // Cast to string
@@ -66,18 +66,19 @@ public abstract class BaseStringValidator extends BaseObjectValidator {
 
                                // Is it empty?
                                if (str.isEmpty()) {
-                                       // Generate message
-                                       facesMessage = new FacesMessage(MessageFormat.format("Field {0} is empty.", field)); //NOI18N
+                                       // Empty strings are currently not accepted, may indicate flaw in invoker
+                                       requiredMessage = MessageFormat.format("Field {0} is empty.", field); //NOI18N
                                }
                        }
                }
 
                // Debug message
-               //this.getLogger().logDebug(MessageFormat.format("preValidate: facesMessage={0}", facesMessage)); //NOI18N
+               //this.getLogger().logDebug(MessageFormat.format("preValidate: requiredMessage={0}", requiredMessage)); //NOI18N
 
                // Is it not null?
-               if (null != facesMessage) {
-                       throw new ValidatorException(facesMessage);
+               if (null != requiredMessage) {
+                       // Then there was something wrong with it
+                       throw new ValidatorException(new FacesMessage(requiredMessage));
                }
 
                // Trace message