From ac1a55001415a650cef270e375f3c119f47c6b4e Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 11 Sep 2015 15:36:56 +0200 Subject: [PATCH] =?utf8?q?Continued=20with=20refacturing:=20-=20added=20ne?= =?utf8?q?w=20validator=20for=20longs=20and=20amounts=20-=20updated=20jars?= =?utf8?q?=20Signed-off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- lib/jcore-ee-logger.jar | Bin 8006 -> 8032 bytes lib/jcore.jar | Bin 27933 -> 28035 bytes src/org/mxchange/jcoreee/BaseEeSystem.java | 16 +++- .../jcoreee/beans/BaseFrameworkBean.java | 4 +- .../validator/BaseObjectValidator.java | 3 +- .../validator/bool/BaseBooleanValidator.java | 8 +- .../validator/number/BaseLongValidator.java | 84 ++++++++++++++++++ .../item_amount/ItemAmountValidator.java | 46 ++++++++++ .../validator/string/BaseStringValidator.java | 4 +- 9 files changed, 157 insertions(+), 8 deletions(-) create mode 100644 src/org/mxchange/jcoreee/validator/number/BaseLongValidator.java create mode 100644 src/org/mxchange/jcoreee/validator/number/item_amount/ItemAmountValidator.java diff --git a/lib/jcore-ee-logger.jar b/lib/jcore-ee-logger.jar index 6160458d2a2ce3da276e245a39698c4b05cd18cb..3c1fb7f8b083e1a84be405024abc1be40c559475 100644 GIT binary patch delta 968 zcmaJ=K}-`t6rJ5|x3p#yYQdyiN=ryeXtr%YS|w$rCA2{l8sfndZKdm`X4@qN378nu zc=AR&Hxo2bZbqW%N#us%qy(=Vh(__IAu;i!(Ld8rEir5|^XLEn-rv7}-fk-&6r7q6 zOg4mC5L%z{S8y+WKI2brIkZ&`A*5B}X)zKArNfcR3!gv{dtJ=@?4^eIxG=LBF3Rj< zF3#*{ZX82CdAA^)3UCMo$Pj;t!(^H7hy58p1p5JBNMW1RN(JX?7k?O`Rt9A61|J5)h&b`bWBt$&TO^unm(# zVGLe3XrlWaQylh9QxD60G>w4gHPhBIW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h**2 zm8hc6n~p}iZL0O6lTkabrb=$yJlJu90Vn9}nzD84R9?ra3~4G~IaLhl3NlQ{#5WkS zR9^HPkdi;S5z8KP5F17WTAnZBN>=xw|i^yt}`*!&%<_ z@MeZu4RxrOpmufiJ39uK?MQy~NPXavhcq;xQRB5XhXY%X!4T-Xr?uqUaU^1zb7`+3Lmqpr)^4-(#g8+Pa`6GEeJ;h zLihy~k6M1yNAU^|!2y0**?3Ouyo;mmMq>C(WH%Uw|MEj*WQb#kmw3&6h30>87YSS_ z^P*Fb1PeE_^7*~{Kt7M4=fI4oVKlhlH$^Y3_lpqzJRpl}LPD}`pHk(J!B@G_ropbH`>jTu7U^#^?zD>cfG#>Ma;QYfA%S$;sp-%i4mkuA zP8&Pj(8>;rykDZWaBKX1?n?M7b8XQaw*a5zPtUrIG|{yVx1Zl~KmV5KM`CO)%zF1n_rRj>|pTQCUh%WAdyKQnb)1XIerZs@hcKPed6Pa6!vSt3B@*a0r zlheu3V?ny|u-TtHH~8xzwrsG-4}@?ym9A`Xhh~UFQ=xj)hb+Eyc~~j@VH42Va=^N}@;4TWu9pc4z22+Nu1daSty-(TnEkoQcqPbUQMRoU`kE(QT0r zMa{w{%IrzheQddv=rh9YMV}vn3ENy6+Y(LmQjhz~F7;UCo|svYA9?h;;m}@-{BG== zg-B*wZ=}9N)DJw4eZsdVdcnMHPNaOzAY6n*H<4fl(MnhbM1No F{tvN3i`@VK diff --git a/src/org/mxchange/jcoreee/BaseEeSystem.java b/src/org/mxchange/jcoreee/BaseEeSystem.java index 6f655a4..56ddbdb 100644 --- a/src/org/mxchange/jcoreee/BaseEeSystem.java +++ b/src/org/mxchange/jcoreee/BaseEeSystem.java @@ -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); } diff --git a/src/org/mxchange/jcoreee/beans/BaseFrameworkBean.java b/src/org/mxchange/jcoreee/beans/BaseFrameworkBean.java index 0a62f6e..f801bb9 100644 --- a/src/org/mxchange/jcoreee/beans/BaseFrameworkBean.java +++ b/src/org/mxchange/jcoreee/beans/BaseFrameworkBean.java @@ -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 */ diff --git a/src/org/mxchange/jcoreee/validator/BaseObjectValidator.java b/src/org/mxchange/jcoreee/validator/BaseObjectValidator.java index 5e9d14a..90a98df 100644 --- a/src/org/mxchange/jcoreee/validator/BaseObjectValidator.java +++ b/src/org/mxchange/jcoreee/validator/BaseObjectValidator.java @@ -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)); diff --git a/src/org/mxchange/jcoreee/validator/bool/BaseBooleanValidator.java b/src/org/mxchange/jcoreee/validator/bool/BaseBooleanValidator.java index e0b3317..38fa468 100644 --- a/src/org/mxchange/jcoreee/validator/bool/BaseBooleanValidator.java +++ b/src/org/mxchange/jcoreee/validator/bool/BaseBooleanValidator.java @@ -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 index 0000000..d69333a --- /dev/null +++ b/src/org/mxchange/jcoreee/validator/number/BaseLongValidator.java @@ -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 . + */ +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 + */ +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 index 0000000..43e53b1 --- /dev/null +++ b/src/org/mxchange/jcoreee/validator/number/item_amount/ItemAmountValidator.java @@ -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 . + */ +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 + */ +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 + } +} diff --git a/src/org/mxchange/jcoreee/validator/string/BaseStringValidator.java b/src/org/mxchange/jcoreee/validator/string/BaseStringValidator.java index 34203b5..b245656 100644 --- a/src/org/mxchange/jcoreee/validator/string/BaseStringValidator.java +++ b/src/org/mxchange/jcoreee/validator/string/BaseStringValidator.java @@ -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)); } -- 2.39.5