⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 validationutilities.java

📁 A Java web application, based on Struts and Hibernate, that serves as an online running log. Users m
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        if (LOG.isDebugEnabled()) {            LOG.debug("executeMinValueValidation: Forwarding validation of"                      + " field '" + fieldName + "' to Validations");        }        boolean success = Validations.validateMinValue(bean, action,                                                       field, errors);        if (LOG.isDebugEnabled()) {            LOG.debug("executeMinValueValidation: Result of the validation"                      + " is '" + success + "'");        }        return success;    }    /**     * Perform a date validation.  This method will use the supplied     * parameters to contruct the appropriate commons-validator objects and     * then use the <code>Validations.validateDate</code> method to     * perform the actual validation.     *     * @param bean The bean containing the property to be validated     * @param fieldName The name of the property to be evaluated     * @param errors List to which any errors should be added     * @return True if the validation succeeded, false otherwise     * @see Validations#validateDate(DTO, ValidatorAction, Field, List)     */    public static boolean executeDateValidation(DTO bean,                                                String fieldName,                                                List errors) {        Field field = getNewValidationField(fieldName);        ValidatorAction action = getNewValidatorAction(ERROR_INVALID_DATE);        if (LOG.isDebugEnabled()) {            LOG.debug("executeDateValidation: Forwarding validation of field"                      + " '" + fieldName + "' to Validations");        }        boolean success = Validations.validateDate(bean, action, field, errors);        if (LOG.isDebugEnabled()) {            LOG.debug("executeDateValidation: Result of the validation is '"                      + success + "'");        }        return success;    }    /**     * Perform a time validation.  This method will use the supplied     * parameters to contruct the appropriate commons-validator objects and     * then use the <code>Validations.validateTime</code> method to     * perform the actual validation.     *     * @param bean The bean containing the property to be validated     * @param fieldName The name of the property to be evaluated     * @param errors List to which any errors should be added     * @return True if the validation succeeded, false otherwise     * @see Validations#validateTime(DTO, ValidatorAction, Field, List)     */    public static boolean executeTimeValidation(DTO bean,                                                String fieldName,                                                List errors) {        Field field = getNewValidationField(fieldName);        ValidatorAction action = getNewValidatorAction(ERROR_INVALID_TIME);        if (LOG.isDebugEnabled()) {            LOG.debug("executeTimeValidation: Forwarding validation of field"                      + " '" + fieldName + "' to Validations");        }        boolean success = Validations.validateTime(bean, action, field, errors);        if (LOG.isDebugEnabled()) {            LOG.debug("executeTimeValidation: Result of the validation is '"                      + success + "'");        }        return success;    }    /**     * Perform a boolean validation.  This method will use the supplied     * parameters to contruct the appropriate commons-validator objects and     * then use the <code>Validations.validateBoolean</code> method to     * perform the actual validation.     *     * @param bean The bean containing the property to be validated     * @param fieldName The name of the property to be evaluated     * @param errors List to which any errors should be added     * @return True if the validation succeeded, false otherwise     * @see Validations#validateBoolean(DTO, ValidatorAction, Field, List)     */    public static boolean executeBooleanValidation(DTO bean,                                                   String fieldName,                                                   List errors) {        Field field = getNewValidationField(fieldName);        ValidatorAction action = getNewValidatorAction(ERROR_INVALID_BOOLEAN);        if (LOG.isDebugEnabled()) {            LOG.debug("executeBooleanValidation: Forwarding validation of field"                      + " '" + fieldName + "' to Validations");        }        boolean success = Validations.validateBoolean(bean,                                                      action,                                                      field,                                                      errors);        if (LOG.isDebugEnabled()) {            LOG.debug("executeBooleanValidation: Result of the validation is '"                      + success + "'");        }        return success;    }    /**     * Perform a decimal validation.  This method will use the supplied     * parameters to contruct the appropriate commons-validator objects and     * then use the <code>Validations.validateDecimal</code> method to     * perform the actual validation.     *     * @param bean The bean containing the property to be validated     * @param fieldName The name of the property to be evaluated     * @param errors List to which any errors should be added     * @return True if the validation succeeded, false otherwise     * @see Validations#validateDecimal(DTO, ValidatorAction, Field, List)     */    public static boolean executeDecimalValidation(DTO bean,                                                   String fieldName,                                                   List errors) {        Field field = getNewValidationField(fieldName);        ValidatorAction action = getNewValidatorAction(ERROR_INVALID_NUMBER);        if (LOG.isDebugEnabled()) {            LOG.debug("executeDecimalValidation: Forwarding validation of field"                      + " '" + fieldName + "' to Validations");        }        boolean success = Validations.validateDecimal(bean,                                                      action,                                                      field,                                                      errors);        if (LOG.isDebugEnabled()) {            LOG.debug("executeDecimalValidation: Result of the validation is '"                      + success + "'");        }        return success;    }    /**     * Perform an email validation.  This method will use the supplied     * parameters to contruct the appropriate commons-validator objects and     * then use the <code>Validations.validateEmail</code> method to     * perform the actual validation.     *     * @param bean The bean containing the property to be validated     * @param fieldName The name of the property to be evaluated     * @param errors List to which any errors should be added     * @return True if the validation succeeded, false otherwise     * @see Validations#validateEmail(DTO, ValidatorAction, Field, List)     */    public static boolean executeEmailValidation(DTO bean,                                                 String fieldName,                                                 List errors) {        Field field = getNewValidationField(fieldName);        ValidatorAction action = getNewValidatorAction(ERROR_INVALID_EMAIL);        if (LOG.isDebugEnabled()) {            LOG.debug("executeEmailValidation: Forwarding validation of "                      + "field '" + fieldName + "' to Validations");        }        boolean success = Validations.validateEmail(bean, action,                                                    field, errors);        if (LOG.isDebugEnabled()) {            LOG.debug("executeEmailValidation: Result of the validation is '"                      + success + "'");        }        return success;    }    /**     * Perform a valid values validation.  This method will use the supplied     * parameters to contruct the appropriate commons-validator objects and     * then use the <code>Validations.validateValidValues</code> method to     * perform the actual validation.     *     * @param bean The bean containing the property to be validated     * @param fieldName The name of the property to be evaluated     * @param errors List to which any errors should be added     * @return True if the validation succeeded, false otherwise     * @see Validations#validateValidValues(DTO, ValidatorAction, Field, List)     */    public static boolean executeValidValuesValidation(DTO bean,                                                       String fieldName,                                                       List errors) {        Field field = getNewValidationField(fieldName);        ValidatorAction action = getNewValidatorAction(ERROR_INVALID_VALUE);        if (LOG.isDebugEnabled()) {            LOG.debug("executeValidValuesValidation: Forwarding validation of"                      + " field '" + fieldName + "' to Validations");        }        boolean success = Validations.validateValidValues(bean, action,                                                          field, errors);        if (LOG.isDebugEnabled()) {            LOG.debug("executeValidValuesValidation: Result of the validation"                      + " is '" + success + "'");        }        return success;    }    /**     * Create a new <code>Field</code> instance.  This method will create a new     * instance and populate its property field with the parameter string.     *     * @param fieldName The value to be set as the field's property     * @return The new field instance     */    protected static Field getNewValidationField(String fieldName) {        if (Utilities.isBlank(fieldName)) {            LOG.error("Cannot invoke execute a validation with a blank field"                      + " name");            throw new IllegalArgumentException("Cannot invoke execute a "                                               + "validation with a blank"                                               + " field name");        }        Field field = new Field();        field.setProperty(fieldName);        return field;    }    /**     * Create a new <code>ValidatorAction</code> instance.  This method will     * create a new instance and populate its message field with the parameter     * string.     *     * @param errorNumber The value to be set as the action's message     * @return The new instance     */    protected static ValidatorAction getNewValidatorAction(String errorNumber) {        ValidatorAction action = new ValidatorAction();        action.setMsg(errorNumber);        return action;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -