From 4b7c1b03e7ca11a41f21420a6dd2dd19fc761a8f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 31 Jul 2017 22:29:03 +0200 Subject: [PATCH] updated jar(s) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../validator/BaseObjectValidator.java | 34 ++++----------- .../validator/bool/BaseBooleanValidator.java | 9 ++-- .../validator/date/BaseDateValidator.java | 8 ++-- ...alidator.java => BaseNumberValidator.java} | 43 ++++++------------- .../validator/string/BaseStringValidator.java | 15 ++++--- 5 files changed, 36 insertions(+), 73 deletions(-) rename src/org/mxchange/jcoreee/validator/number/{BaseLongValidator.java => BaseNumberValidator.java} (72%) diff --git a/src/org/mxchange/jcoreee/validator/BaseObjectValidator.java b/src/org/mxchange/jcoreee/validator/BaseObjectValidator.java index 6fc1583..4f19b93 100644 --- a/src/org/mxchange/jcoreee/validator/BaseObjectValidator.java +++ b/src/org/mxchange/jcoreee/validator/BaseObjectValidator.java @@ -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). *

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

* @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 diff --git a/src/org/mxchange/jcoreee/validator/bool/BaseBooleanValidator.java b/src/org/mxchange/jcoreee/validator/bool/BaseBooleanValidator.java index 0194bdb..7cbad80 100644 --- a/src/org/mxchange/jcoreee/validator/bool/BaseBooleanValidator.java +++ b/src/org/mxchange/jcoreee/validator/bool/BaseBooleanValidator.java @@ -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)); } } diff --git a/src/org/mxchange/jcoreee/validator/date/BaseDateValidator.java b/src/org/mxchange/jcoreee/validator/date/BaseDateValidator.java index 726ba1f..37be7f2 100644 --- a/src/org/mxchange/jcoreee/validator/date/BaseDateValidator.java +++ b/src/org/mxchange/jcoreee/validator/date/BaseDateValidator.java @@ -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/BaseNumberValidator.java similarity index 72% rename from src/org/mxchange/jcoreee/validator/number/BaseLongValidator.java rename to src/org/mxchange/jcoreee/validator/number/BaseNumberValidator.java index d44ce31..f5ddf22 100644 --- a/src/org/mxchange/jcoreee/validator/number/BaseLongValidator.java +++ b/src/org/mxchange/jcoreee/validator/number/BaseNumberValidator.java @@ -29,7 +29,7 @@ import org.mxchange.jcoreee.validator.BaseObjectValidator; *

* @author Roland Häder */ -public abstract class BaseLongValidator extends BaseObjectValidator implements Validator { +public abstract class BaseNumberValidator extends BaseObjectValidator implements Validator { /** * Serial number @@ -46,7 +46,6 @@ public abstract class BaseLongValidator extends BaseObjectValidator implements V // 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 @@ -57,14 +56,13 @@ public abstract class BaseLongValidator extends BaseObjectValidator implements V // Is it the same? if (clientId.endsWith(field)) { // Init variables - Integer i = null; - Long l = null; + Number number = null; - // Compare value's type + // Compare value's type, supported: String, Long, Integer if (value instanceof String) { - // Is a string, try long + // Is a string, then try to parse it as Long, largest range try { - l = Long.valueOf((String) value); + 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); @@ -72,24 +70,15 @@ public abstract class BaseLongValidator extends BaseObjectValidator implements V // Abort processing here break; } - } else if (value instanceof Integer) { - // Is integer - i = (Integer) value; - } else if (value instanceof Long) { - // Is long - l = (Long) value; + } else if ((value instanceof Integer) || (value instanceof Long) || (value instanceof Short)) { + // Is any used number + number = (Number) value; } - // Is the number below zero? - if ((!allowNull) && ((i instanceof Integer) && (i < 0))) { + // 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.", 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 + requiredMessage = MessageFormat.format("Value {0} for field {1} is below zero.", number, field); //NOI18N // Abort processing here break; @@ -97,16 +86,10 @@ public abstract class BaseLongValidator extends BaseObjectValidator implements V } } - // Is requiredMessage set? - if (null != requiredMessage) { - // Embed into FacesMessage - facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage); - } - // 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/string/BaseStringValidator.java b/src/org/mxchange/jcoreee/validator/string/BaseStringValidator.java index c13116b..84fc781 100644 --- a/src/org/mxchange/jcoreee/validator/string/BaseStringValidator.java +++ b/src/org/mxchange/jcoreee/validator/string/BaseStringValidator.java @@ -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 -- 2.39.5