]> git.mxchange.org Git - jcore-utils.git/blobdiff - src/org/mxchange/jcoreee/validator/number/BaseNumberValidator.java
Continued:
[jcore-utils.git] / src / org / mxchange / jcoreee / validator / number / BaseNumberValidator.java
diff --git a/src/org/mxchange/jcoreee/validator/number/BaseNumberValidator.java b/src/org/mxchange/jcoreee/validator/number/BaseNumberValidator.java
deleted file mode 100644 (file)
index 23664ed..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (C) 2016 - 2018 Free Software Foundation
- *
- * 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.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<Object> {
-
-       /**
-        * 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));
-               }
-       }
-
-}