当前位置: 首页>>代码示例>>Java>>正文


Java GenericValidator类代码示例

本文整理汇总了Java中org.apache.commons.validator.GenericValidator的典型用法代码示例。如果您正苦于以下问题:Java GenericValidator类的具体用法?Java GenericValidator怎么用?Java GenericValidator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GenericValidator类属于org.apache.commons.validator包,在下文中一共展示了GenericValidator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isValidAuthority

import org.apache.commons.validator.GenericValidator; //导入依赖的package包/类
@Override
protected boolean isValidAuthority(String authority) {
    if (relative && authority == null) {
        return true;
    }

    boolean isValid = super.isValidAuthority(authority);

    if (!isValid && !GenericValidator.isBlankOrNull(authority)) {
        if (isValidAuthorityHostNoDot(authority)) {
            return true;
        } else if (isValidAuthorityHostNoTld(authority)) {
            return true;
        } else {
            return isValidAuthorityIPV6Host(authority);
        }
    } else {
        return isValid;
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:21,代码来源:ADMValidator.java

示例2: isValidAuthorityHostNoDot

import org.apache.commons.validator.GenericValidator; //导入依赖的package包/类
/**
 * Check if the authority contains a valid hostname without "."
 * characters and an optional port number
 * 
 * @param authority
 * @return <code>true</code> if the authority is valid
 */
private boolean isValidAuthorityHostNoDot(String authority) {
    Perl5Util authorityMatcher = new Perl5Util();
    if (authority != null
            && authorityMatcher.match(
                    "/^([a-zA-Z\\d\\-\\.]*)(:\\d*)?(.*)?/", authority)) {
        String hostIP = authorityMatcher.group(1);
        if (hostIP.indexOf('.') < 0) {
            // the hostname contains no dot, add domain validation to check invalid hostname like "g08fnstd110825-"
            DomainValidator domainValidator = DomainValidator.getInstance(true);
            if(!domainValidator.isValid(hostIP)) {
                return false;
            }
            String port = authorityMatcher.group(2);
            if (!isValidPort(port)) {
                return false;
            }
            String extra = authorityMatcher.group(3);
            return GenericValidator.isBlankOrNull(extra);
        } else {
            return false;
        }
    } else {
        return false;
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:33,代码来源:ADMValidator.java

示例3: isSecurityInfo

import org.apache.commons.validator.GenericValidator; //导入依赖的package包/类
/**
 * Either question and answer are not set or both must be set.
 * 
 * @param question
 *            the security question.
 * @param answer
 *            the security answer.
 */
public static void isSecurityInfo(String question, String answer)
        throws ValidationException {
    BLValidator.isDescription("securityQuestion", question, false);
    BLValidator.isDescription("securityAnswer", answer, false);

    if (!GenericValidator.isBlankOrNull(question)
            || !GenericValidator.isBlankOrNull(answer)) {
        if (GenericValidator.isBlankOrNull(question)
                || GenericValidator.isBlankOrNull(answer)) {
            ValidationException vf = new ValidationException(
                    ReasonEnum.SECURITY_INFO, null, null);
            logValidationFailure(vf);
            throw vf;
        }
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:25,代码来源:BLValidator.java

示例4: updatePlatformUser

import org.apache.commons.validator.GenericValidator; //导入依赖的package包/类
/**
 * Updates all fields in the platform user object for which a LDAP attribute
 * is configured. <br>
 * The filed "userid", will not be updated since it's possible that the new
 * LDAP user id is not unique in BES. For this reason the field
 * "realmuserid" will be updated to be in sync with LDAP.
 * 
 * @param userDetails
 *            The value object containing the values to be set.
 * @param settingList
 *            The list with the configured LDAP attributes.
 * @param userToBeUpdated
 *            The platform user object to be updated.
 * @return The updated platform user object.
 * @throws ValidationException
 *             Thrown if the validation of the value objects failed.
 */
public static PlatformUser updatePlatformUser(VOUserDetails userDetails,
        List<SettingType> settingList, PlatformUser userToBeUpdated) {
    for (int i = 0; i < settingList.size(); i++) {
        if (settingList.get(i) == SettingType.LDAP_ATTR_ADDITIONAL_NAME) {
            userToBeUpdated.setAdditionalName(userDetails
                    .getAdditionalName());
        } else if (settingList.get(i) == SettingType.LDAP_ATTR_EMAIL) {
            if (!GenericValidator.isBlankOrNull(userDetails.getEMail())) {
                userToBeUpdated.setEmail(userDetails.getEMail());
            }
        } else if (settingList.get(i) == SettingType.LDAP_ATTR_FIRST_NAME) {
            userToBeUpdated.setFirstName(userDetails.getFirstName());
        } else if (settingList.get(i) == SettingType.LDAP_ATTR_LAST_NAME) {
            userToBeUpdated.setLastName(userDetails.getLastName());
        } else if (settingList.get(i) == SettingType.LDAP_ATTR_UID) {
            // Do not update the userid here because a update can violate
            // the unique constraint in BES.
            userToBeUpdated.setRealmUserId((userDetails.getRealmUserId()));
        }
    }
    return userToBeUpdated;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:40,代码来源:UserDataAssembler.java

示例5: parse

import org.apache.commons.validator.GenericValidator; //导入依赖的package包/类
/**
 * Parses the specified string into a long integer.
 * 
 * @param context
 *            FacesContext for the request we are processing
 * @param component
 *            UIComponent we are checking for correctness
 * @param value
 *            the value to parse
 * @throws ValidatorException
 *             if the specified string could not be parsed into a valid long
 *             integer.
 */
public static long parse(FacesContext context, UIComponent uiComponent,
        String value) throws ValidatorException {
    if (!GenericValidator.isLong(value)) {
        Object[] args = null;
        String label = JSFUtils.getLabel(uiComponent);
        if (label != null) {
            args = new Object[] { label };
        }
        ValidationException e = new ValidationException(
                ValidationException.ReasonEnum.LONG, label, null);
        String message = JSFUtils.getText(e.getMessageKey(), args, context);
        throw getException(message);
    }
    return Long.parseLong(value);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:29,代码来源:LongValidator.java

示例6: validateInteger

import org.apache.commons.validator.GenericValidator; //导入依赖的package包/类
/**
 * Validate integer value.
 * 
 * @param context
 *            JSF context.
 * @param uiComponent
 *            UI component.
 * @param value
 *            Value for validation.
 */
private void validateInteger(FacesContext context, UIComponent uiComponent,
        String value) {
    if (!GenericValidator.isInt(value.toString())) {
        Object[] args = null;
        String label = JSFUtils.getLabel(uiComponent);
        if (label != null) {
            args = new Object[] { label };
        }
        ValidationException e = new ValidationException(
                ValidationException.ReasonEnum.INTEGER, label, null);
        String text = JSFUtils.getText(e.getMessageKey(), args, context);
        throw new ValidatorException(new FacesMessage(
                FacesMessage.SEVERITY_ERROR, text, null));
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:26,代码来源:ParameterValueValidator.java

示例7: validate

import org.apache.commons.validator.GenericValidator; //导入依赖的package包/类
@Override
public void validate(Object obj) throws ValidationException {
    super.validate(obj);
    VOParameter parameter = (VOParameter) obj;
    VOParameterDefinition parameterDefinition = parameter
            .getParameterDefinition();

    if (isOptionalAndNullOrEmpty(parameter)) {
        return;
    }

    if (!GenericValidator.isLong(parameter.getValue())) {
        throw new ValidationException(ValidationException.ReasonEnum.LONG,
                null, new Object[] { parameter.getParameterDefinition()
                        .getParameterId() });
    }

    if (!isValid(parameter, parameterDefinition)) {
        throw new ValidationException(
                ValidationException.ReasonEnum.VALUE_NOT_IN_RANGE, null,
                new Object[] { parameter.getParameterDefinition()
                        .getParameterId() });
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:25,代码来源:LongParameterValidator.java

示例8: validate

import org.apache.commons.validator.GenericValidator; //导入依赖的package包/类
@Override
public void validate(Object obj) throws ValidationException {
    super.validate(obj);
    VOParameter parameter = (VOParameter) obj;
    VOParameterDefinition parameterDefinition = parameter
            .getParameterDefinition();

    if(isOptionalAndNullOrEmpty(parameter)) {
        return;
    }
    
    if (!GenericValidator.isInt(parameter.getValue())) {
        throw new ValidationException(
                ValidationException.ReasonEnum.INTEGER, null,
                new Object[] { parameter.getParameterDefinition()
                        .getParameterId() });
    }

    if (!isValid(parameter, parameterDefinition)) {
        throw new ValidationException(
                ValidationException.ReasonEnum.VALUE_NOT_IN_RANGE, null,
                new Object[] { parameter.getParameterDefinition()
                        .getParameterId() });
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:26,代码来源:IntegerParameterValidator.java

示例9: validateRequired

import org.apache.commons.validator.GenericValidator; //导入依赖的package包/类
/**
 * Checks if the field isn't null and length of the field is greater than zero not
 * including whitespace.
 *
 * @param bean The bean validation is being performed on.
 * @param va The <code>ValidatorAction</code> that is currently being performed.
 * @param field The <code>Field</code> object associated with the current
 * field being validated.
 * @param errors The <code>ActionMessages</code> object to add errors to if
 * any validation errors occur.
 * @param validator The <code>Validator</code> instance, used to access
 *                  other field values.
 * @param request Current request object.
 * @return true if meets stated requirements, false otherwise.
 */
public static boolean validateRequired(Object bean,
                                       ValidatorAction va, Field field,
                                       ActionMessages errors,
                                       Validator validator,
                                       HttpServletRequest request) {

    String value = null;
    if (isString(bean)) {
        value = (String) bean;
    } else {
        value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    }

    if (GenericValidator.isBlankOrNull(value)) {
        errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
        return false;
    } else {
        return true;
    }

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:37,代码来源:FieldChecks.java

示例10: validateShort

import org.apache.commons.validator.GenericValidator; //导入依赖的package包/类
/**
 * Checks if the field can safely be converted to a short primitive.
 *
 * @param bean The bean validation is being performed on.
 * @param va The <code>ValidatorAction</code> that is currently being performed.
 * @param field The <code>Field</code> object associated with the current
 * field being validated.
 * @param errors The <code>ActionMessages</code> object to add errors to if
 * any validation errors occur.
 * @param validator The <code>Validator</code> instance, used to access
 * other field values.
 * @param request Current request object.
 * @return true if valid, false otherwise.
 */
public static Object validateShort(Object bean,
                                  ValidatorAction va, Field field,
                                  ActionMessages errors,
                                  Validator validator,
                                  HttpServletRequest request) {
    Object result = null;
    String value = null;
    if (isString(bean)) {
        value = (String) bean;
    } else {
        value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    }

    if (GenericValidator.isBlankOrNull(value)) {
        return Boolean.TRUE;
    }

    result = GenericTypeValidator.formatShort(value);

    if (result == null) {
        errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
    }

    return result == null ? Boolean.FALSE : result;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:40,代码来源:FieldChecks.java

示例11: validateInteger

import org.apache.commons.validator.GenericValidator; //导入依赖的package包/类
/**
 * Checks if the field can safely be converted to an int primitive.
 *
 * @param  bean     The bean validation is being performed on.
 * @param  va       The <code>ValidatorAction</code> that is currently being performed.
 * @param  field    The <code>Field</code> object associated with the current
 *      field being validated.
 * @param  errors   The <code>ActionMessages</code> object to add errors to if any
 *      validation errors occur.
 * @param validator The <code>Validator</code> instance, used to access
 * other field values.
 * @param  request  Current request object.
 * @return true if valid, false otherwise.
 */
public static Object validateInteger(Object bean,
                                      ValidatorAction va, Field field,
                                      ActionMessages errors,
                                      Validator validator,
                                      HttpServletRequest request) {
    Object result = null;
    String value = null;
    if (isString(bean)) {
        value = (String) bean;
    } else {
        value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    }

    if (GenericValidator.isBlankOrNull(value)) {
        return Boolean.TRUE;
    }

    result = GenericTypeValidator.formatInt(value);

    if (result == null) {
        errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
    }

    return result == null ? Boolean.FALSE : result;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:40,代码来源:FieldChecks.java

示例12: validateLong

import org.apache.commons.validator.GenericValidator; //导入依赖的package包/类
/**
 * Checks if the field can safely be converted to a long primitive.
 *
 * @param  bean     The bean validation is being performed on.
 * @param  va       The <code>ValidatorAction</code> that is currently being performed.
 * @param  field    The <code>Field</code> object associated with the current
 *      field being validated.
 * @param  errors   The <code>ActionMessages</code> object to add errors to if any
 *      validation errors occur.
 * @param validator The <code>Validator</code> instance, used to access
 * other field values.
 * @param  request  Current request object.
 * @return true if valid, false otherwise.
 */
public static Object validateLong(Object bean,
                                ValidatorAction va, Field field,
                                ActionMessages errors,
                                Validator validator,
                                HttpServletRequest request) {
    Object result = null;
    String value = null;
    if (isString(bean)) {
        value = (String) bean;
    } else {
        value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    }

    if (GenericValidator.isBlankOrNull(value)) {
        return Boolean.TRUE;
    }

    result = GenericTypeValidator.formatLong(value);

    if (result == null) {
        errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
    }

    return result == null ? Boolean.FALSE : result;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:40,代码来源:FieldChecks.java

示例13: validateFloat

import org.apache.commons.validator.GenericValidator; //导入依赖的package包/类
/**
 * Checks if the field can safely be converted to a float primitive.
 *
 * @param  bean     The bean validation is being performed on.
 * @param  va       The <code>ValidatorAction</code> that is currently being performed.
 * @param  field    The <code>Field</code> object associated with the current
 *      field being validated.
 * @param  errors   The <code>ActionMessages</code> object to add errors to if any
 *      validation errors occur.
 * @param validator The <code>Validator</code> instance, used to access
 * other field values.
 * @param  request  Current request object.
 * @return true if valid, false otherwise.
 */
public static Object validateFloat(Object bean,
                                  ValidatorAction va, Field field,
                                  ActionMessages errors,
                                  Validator validator,
                                  HttpServletRequest request) {
    Object result = null;
    String value = null;
    if (isString(bean)) {
        value = (String) bean;
    } else {
        value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    }

    if (GenericValidator.isBlankOrNull(value)) {
        return Boolean.TRUE;
    }

    result = GenericTypeValidator.formatFloat(value);

    if (result == null) {
        errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
    }

    return result == null ? Boolean.FALSE : result;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:40,代码来源:FieldChecks.java

示例14: validateDouble

import org.apache.commons.validator.GenericValidator; //导入依赖的package包/类
/**
 *  Checks if the field can safely be converted to a double primitive.
 *
 * @param  bean     The bean validation is being performed on.
 * @param  va       The <code>ValidatorAction</code> that is currently being performed.
 * @param  field    The <code>Field</code> object associated with the current
 *      field being validated.
 * @param  errors   The <code>ActionMessages</code> object to add errors to if any
 *      validation errors occur.
 * @param validator The <code>Validator</code> instance, used to access
 * other field values.
 * @param  request  Current request object.
 * @return true if valid, false otherwise.
 */
public static Object validateDouble(Object bean,
                                    ValidatorAction va, Field field,
                                    ActionMessages errors,
                                    Validator validator,
                                    HttpServletRequest request) {
    Object result = null;
    String value = null;
    if (isString(bean)) {
        value = (String) bean;
    } else {
        value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    }

    if (GenericValidator.isBlankOrNull(value)) {
        return Boolean.TRUE;
    }

    result = GenericTypeValidator.formatDouble(value);

    if (result == null) {
        errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
    }

    return result == null ? Boolean.FALSE : result;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:40,代码来源:FieldChecks.java

示例15: validateEmail

import org.apache.commons.validator.GenericValidator; //导入依赖的package包/类
/**
 *  Checks if a field has a valid e-mail address.
 *
 * @param  bean     The bean validation is being performed on.
 * @param  va       The <code>ValidatorAction</code> that is currently being performed.
 * @param  field    The <code>Field</code> object associated with the current
 *      field being validated.
 * @param  errors   The <code>ActionMessages</code> object to add errors to if any
 *      validation errors occur.
 * @param validator The <code>Validator</code> instance, used to access
 *      other field values.
 * @param  request  Current request object.
 * @return True if valid, false otherwise.
 */
public static boolean validateEmail(Object bean,
                                    ValidatorAction va, Field field,
                                    ActionMessages errors,
                                    Validator validator,
                                    HttpServletRequest request) {

    String value = null;
    if (isString(bean)) {
        value = (String) bean;
    } else {
        value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    }

    if (!GenericValidator.isBlankOrNull(value) && !GenericValidator.isEmail(value)) {
        errors.add(field.getKey(), Resources.getActionMessage(validator, request, va, field));
        return false;
    } else {
        return true;
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:35,代码来源:FieldChecks.java


注:本文中的org.apache.commons.validator.GenericValidator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。