當前位置: 首頁>>代碼示例>>Java>>正文


Java ValidationUtils.isNullOrEmpty方法代碼示例

本文整理匯總了Java中org.kuali.rice.krad.datadictionary.validation.ValidationUtils.isNullOrEmpty方法的典型用法代碼示例。如果您正苦於以下問題:Java ValidationUtils.isNullOrEmpty方法的具體用法?Java ValidationUtils.isNullOrEmpty怎麽用?Java ValidationUtils.isNullOrEmpty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.kuali.rice.krad.datadictionary.validation.ValidationUtils的用法示例。


在下文中一共展示了ValidationUtils.isNullOrEmpty方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: processSingleExistenceConstraint

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入方法依賴的package包/類
protected ConstraintValidationResult processSingleExistenceConstraint(DictionaryValidationResult result,
        Object value, ExistenceConstraint constraint,
        AttributeValueReader attributeValueReader) throws AttributeValidationException {
    // If it's not set, then there's no constraint
    if (constraint.isRequired() == null) {
        return result.addNoConstraint(attributeValueReader, CONSTRAINT_NAME);
    }

    if (constraint.isRequired().booleanValue() && !skipConstraint(attributeValueReader)) {
        // If this attribute is required and the value is null then
        if (ValidationUtils.isNullOrEmpty(value)) {
            String errorParameter = attributeValueReader.getLabel(attributeValueReader.getAttributeName());
            if (ValidationUtils.isNullOrEmpty(errorParameter)) {
                errorParameter = attributeValueReader.getAttributeName();
            }
            return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_REQUIRED,
                    errorParameter);
        }
        return result.addSuccess(attributeValueReader, CONSTRAINT_NAME);
    }

    return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:24,代碼來源:ExistenceConstraintProcessor.java

示例2: processSingleLengthConstraint

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入方法依賴的package包/類
protected ConstraintValidationResult processSingleLengthConstraint(DictionaryValidationResult result, Object value,
        LengthConstraint constraint,
        AttributeValueReader attributeValueReader) throws AttributeValidationException {
    // Can't process any range constraints on null values
    if (ValidationUtils.isNullOrEmpty(value)) {
        return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
    }

    DataType dataType = constraint.getDataType();
    Object typedValue = value;

    if (dataType != null) {
        typedValue = ValidationUtils.convertToDataType(value, dataType, dateTimeService);
    }

    // The only thing that can have a length constraint currently is a string.
    if (typedValue instanceof String) {
        return validateLength(result, (String) typedValue, constraint, attributeValueReader);
    }

    return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:23,代碼來源:LengthConstraintProcessor.java

示例3: process

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public ProcessorResult process(DictionaryValidationResult result, Object value, PrerequisiteConstraint constraint,
        AttributeValueReader attributeValueReader) throws AttributeValidationException {

    if (ValidationUtils.isNullOrEmpty(value)) {
        return new ProcessorResult(result.addSkipped(attributeValueReader, CONSTRAINT_NAME));
    }

    ConstraintValidationResult constraintValidationResult = processPrerequisiteConstraint(constraint,
            attributeValueReader);

    if (constraint != null) {
        if (StringUtils.isNotBlank(constraint.getMessageKey())) {
            constraintValidationResult.setConstraintLabelKey(constraint.getMessageKey());
        } else {
            constraintValidationResult.setConstraintLabelKey(
                    UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + FALLBACK_KEY);
        }
        constraintValidationResult.setErrorParameters(constraint.getValidationMessageParamsArray());
    }

    result.addConstraintValidationResult(attributeValueReader, constraintValidationResult);

    return new ProcessorResult(constraintValidationResult);
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:29,代碼來源:PrerequisiteConstraintProcessor.java

示例4: processSingleExistenceConstraint

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入方法依賴的package包/類
protected ConstraintValidationResult processSingleExistenceConstraint(DictionaryValidationResult result,
        Object value, ExistenceConstraint constraint,
        AttributeValueReader attributeValueReader) throws AttributeValidationException {
    // If it's not set, then there's no constraint
    if (constraint.isRequired() == null) {
        return result.addNoConstraint(attributeValueReader, CONSTRAINT_NAME);
    }

    if (constraint.isRequired().booleanValue() && !skipConstraint(attributeValueReader)) {
        // If this attribute is required and the value is null then
        if (ValidationUtils.isNullOrEmpty(value)) {
            return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_REQUIRED,
                    attributeValueReader.getLabel(attributeValueReader.getAttributeName()));
        }
        return result.addSuccess(attributeValueReader, CONSTRAINT_NAME);
    }

    return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
}
 
開發者ID:aapotts,項目名稱:kuali_rice,代碼行數:20,代碼來源:ExistenceConstraintProcessor.java

示例5: process

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入方法依賴的package包/類
/**
 * @see org.kuali.rice.krad.datadictionary.validation.processor.ConstraintProcessor#process(DictionaryValidationResult,
 *      Object, org.kuali.rice.krad.datadictionary.validation.capability.Validatable,
 *      org.kuali.rice.krad.datadictionary.validation.AttributeValueReader)
 */
@Override
public ProcessorResult process(DictionaryValidationResult result, Object value, PrerequisiteConstraint constraint,
        AttributeValueReader attributeValueReader) throws AttributeValidationException {

    if (ValidationUtils.isNullOrEmpty(value)) {
        return new ProcessorResult(result.addSkipped(attributeValueReader, CONSTRAINT_NAME));
    }

    ConstraintValidationResult constraintValidationResult = processPrerequisiteConstraint(constraint,
            attributeValueReader);

    if (constraint != null) {
        if (StringUtils.isNotBlank(constraint.getMessageKey())) {
            constraintValidationResult.setConstraintLabelKey(constraint.getMessageKey());
        } else {
            constraintValidationResult.setConstraintLabelKey(
                    UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + FALLBACK_KEY);
        }
        constraintValidationResult.setErrorParameters(constraint.getValidationMessageParamsArray());
    }

    result.addConstraintValidationResult(attributeValueReader, constraintValidationResult);

    return new ProcessorResult(constraintValidationResult);
}
 
開發者ID:aapotts,項目名稱:kuali_rice,代碼行數:31,代碼來源:PrerequisiteConstraintProcessor.java

示例6: processDataTypeConstraint

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入方法依賴的package包/類
/**
 * validates the value provided using {@code DataTypeConstraint}
 *
 * @param result - a holder for any already run validation results
 * @param dataType - the expected data type
 * @param value - the value to validate
 * @param attributeValueReader - provides access to the attribute being validated
 * @return the passed in result, updated with the results of the processing
 */
protected ConstraintValidationResult processDataTypeConstraint(DictionaryValidationResult result, DataType dataType,
        Object value, AttributeValueReader attributeValueReader) {
    if (dataType == null) {
        return result.addNoConstraint(attributeValueReader, CONSTRAINT_NAME);
    }

    if (ValidationUtils.isNullOrEmpty(value)) {
        return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
    }

    try {
        ValidationUtils.convertToDataType(value, dataType, dateTimeService);
    } catch (Exception e) {
        switch (dataType) {
            case BOOLEAN:
                return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_BOOLEAN);
            case INTEGER:
                return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_INTEGER);
            case LONG:
                return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_LONG);
            case DOUBLE:
                return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_BIG_DECIMAL);
            case FLOAT:
                return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_BIG_DECIMAL);
            case TRUNCATED_DATE:
            case DATE:
                return result.addError(attributeValueReader, CONSTRAINT_NAME, RiceKeyConstants.ERROR_BIG_DECIMAL);
            case STRING:
        }
    }

    // If we get here then it was a success!
    return result.addSuccess(attributeValueReader, CONSTRAINT_NAME);
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:44,代碼來源:DataTypeConstraintProcessor.java

示例7: processSingleRangeConstraint

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入方法依賴的package包/類
/**
 * validates the value provided using {@code RangeConstraint}
 *
 * @param result - a holder for any already run validation results
 * @param value - the value to validate
 * @param constraint - the range constraint to use
 * @param attributeValueReader - provides access to the attribute being validated
 * @return the passed in result, updated with the results of the processing
 * @throws AttributeValidationException if validation fails
 */
protected ConstraintValidationResult processSingleRangeConstraint(DictionaryValidationResult result, Object value,
        RangeConstraint constraint, AttributeValueReader attributeValueReader) throws AttributeValidationException {
    // Can't process any range constraints on null values
    if (ValidationUtils.isNullOrEmpty(value) || (constraint.getExclusiveMin() == null
            && constraint.getInclusiveMax() == null)) {
        return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
    }

    // This is necessary because sometimes we'll be getting a string, for example, that represents a date.
    DataType dataType = constraint.getDataType();
    Object typedValue = value;

    if (dataType != null) {
        typedValue = ValidationUtils.convertToDataType(value, dataType, dateTimeService);
    } else if (value instanceof String) {
        //assume string is a number of type double
        try {
            Double d = Double.parseDouble((String) value);
            typedValue = d;
        } catch (NumberFormatException n) {
            //do nothing, typedValue is never reset
        }
    }

    // TODO: decide if there is any reason why the following would be insufficient - i.e. if something numeric could still be cast to String at this point
    if (typedValue instanceof Date) {
        return validateRange(result, (Date) typedValue, constraint, attributeValueReader);
    } else if (typedValue instanceof Number) {
        return validateRange(result, (Number) typedValue, constraint, attributeValueReader);
    }

    return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:44,代碼來源:RangeConstraintProcessor.java

示例8: process

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入方法依賴的package包/類
/**
 * @see org.kuali.rice.krad.datadictionary.validation.processor.ConstraintProcessor#process(org.kuali.rice.krad.datadictionary.validation.result.DictionaryValidationResult,
 *      Object, org.kuali.rice.krad.datadictionary.validation.constraint.Constraint,
 *      org.kuali.rice.krad.datadictionary.validation.AttributeValueReader)
 */
@Override
public ProcessorResult process(DictionaryValidationResult result, Object value, MustOccurConstraint constraint,
        AttributeValueReader attributeValueReader) throws AttributeValidationException {

    if (ValidationUtils.isNullOrEmpty(value)) {
        return new ProcessorResult(result.addSkipped(attributeValueReader, CONSTRAINT_NAME));
    }

    ConstraintValidationResult constraintValidationResult = new ConstraintValidationResult(CONSTRAINT_NAME);
    if (StringUtils.isNotBlank(constraint.getMessageKey())) {
        constraintValidationResult.setConstraintLabelKey(constraint.getMessageKey());
    } else {
        constraintValidationResult.setConstraintLabelKey(
                UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + FALLBACK_KEY);
    }

    constraintValidationResult.setErrorParameters(constraint.getValidationMessageParamsArray());

    // If the processing of this constraint is not successful then it's an error
    if (!processMustOccurConstraint(constraintValidationResult, constraint, attributeValueReader)) {
        // if attributeName is null, use the entry name since we are processing a must occur constraint that may be referencing multiple attributes
        if (attributeValueReader.getAttributeName() == null) {
            constraintValidationResult.setAttributeName(attributeValueReader.getEntryName());
        } else {
            constraintValidationResult.setAttributeName(attributeValueReader.getAttributeName());
            constraintValidationResult.setAttributePath(attributeValueReader.getPath());
        }
        constraintValidationResult.setError(RiceKeyConstants.ERROR_OCCURS);
    }

    // Store the label key (if one exists) for this constraint on the constraint validation result so it can be shown later

    // Add it to the DictionaryValidationResult object
    result.addConstraintValidationResult(attributeValueReader, constraintValidationResult);

    return new ProcessorResult(constraintValidationResult);

}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:44,代碼來源:MustOccurConstraintProcessor.java

示例9: processSingleValidCharacterConstraint

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入方法依賴的package包/類
protected ConstraintValidationResult processSingleValidCharacterConstraint(DictionaryValidationResult result,
        Object value, ValidCharactersConstraint constraint,
        AttributeValueReader attributeValueReader) throws AttributeValidationException {

    if (constraint == null) {
        return result.addNoConstraint(attributeValueReader, CONSTRAINT_NAME);
    }

    if (ValidationUtils.isNullOrEmpty(value)) {
        return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
    }

    // This mix-in interface is here to allow some definitions to avoid the extra processing that goes on in KNS
    // to decipher and validate things like date range strings -- something that looks like "02/02/2002..03/03/2003"
    Constrainable definition = attributeValueReader.getDefinition(attributeValueReader.getAttributeName());
    if (definition instanceof Formatable) {
        return doProcessFormattableValidCharConstraint(result, constraint, (Formatable) definition, value,
                attributeValueReader);
    }

    ConstraintValidationResult constraintValidationResult = doProcessValidCharConstraint(constraint, value);
    if (constraintValidationResult == null) {
        return result.addSuccess(attributeValueReader, CONSTRAINT_NAME);
    }

    result.addConstraintValidationResult(attributeValueReader, constraintValidationResult);
    constraintValidationResult.setConstraintLabelKey(constraint.getMessageKey());
    constraintValidationResult.setErrorParameters(constraint.getValidationMessageParamsArray());
    return constraintValidationResult;
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:31,代碼來源:ValidCharactersConstraintProcessor.java

示例10: processSingleRangeConstraint

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入方法依賴的package包/類
/**
 * validates the value provided using {@code RangeConstraint}
 *
 * @param result - a holder for any already run validation results
 * @param value - the value to validate
 * @param constraint - the range constraint to use
 * @param attributeValueReader - provides access to the attribute being validated
 * @return the passed in result, updated with the results of the processing
 */
protected ConstraintValidationResult processSingleRangeConstraint(DictionaryValidationResult result, Object value,
        RangeConstraint constraint, AttributeValueReader attributeValueReader) throws AttributeValidationException {
    // Can't process any range constraints on null values
    if (ValidationUtils.isNullOrEmpty(value) || (constraint.getExclusiveMin() == null
            && constraint.getInclusiveMax() == null)) {
        return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
    }

    // This is necessary because sometimes we'll be getting a string, for example, that represents a date.
    DataType dataType = constraint.getDataType();
    Object typedValue = value;

    if (dataType != null) {
        typedValue = ValidationUtils.convertToDataType(value, dataType, dateTimeService);
    } else if (value instanceof String) {
        //assume string is a number of type double
        try {
            Double d = Double.parseDouble((String) value);
            typedValue = d;
        } catch (NumberFormatException n) {
            //do nothing, typedValue is never reset
        }
    }

    // TODO: decide if there is any reason why the following would be insufficient - i.e. if something numeric could still be cast to String at this point
    if (typedValue instanceof Date) {
        return validateRange(result, (Date) typedValue, constraint, attributeValueReader);
    } else if (typedValue instanceof Number) {
        return validateRange(result, (Number) typedValue, constraint, attributeValueReader);
    }

    return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
}
 
開發者ID:aapotts,項目名稱:kuali_rice,代碼行數:43,代碼來源:RangeConstraintProcessor.java

示例11: processPrerequisiteConstraint

import org.kuali.rice.krad.datadictionary.validation.ValidationUtils; //導入方法依賴的package包/類
protected ConstraintValidationResult processPrerequisiteConstraint(PrerequisiteConstraint constraint,
        AttributeValueReader attributeValueReader) throws AttributeValidationException {
    ConstraintValidationResult constraintValidationResult = new ConstraintValidationResult(getName());

    if (constraint == null) {
        constraintValidationResult.setStatus(ErrorLevel.NOCONSTRAINT);
        return constraintValidationResult;
    }

    // TODO: Does this code need to be able to look at more than just the other immediate members of the object?
    String attributeName = constraint.getPropertyName();

    if (ValidationUtils.isNullOrEmpty(attributeName)) {
        throw new AttributeValidationException(
                "Prerequisite constraints must include the name of the attribute that is required");
    }

    Object value = attributeValueReader.getValue(attributeName);

    boolean isSuccessful = true;

    if (value instanceof java.lang.String) {
        isSuccessful = ValidationUtils.hasText((String) value);
    } else if (value instanceof Collection) {
        isSuccessful = (((Collection<?>) value).size() > 0);
    } else {
        isSuccessful = (null != value) ? true : false;
    }

    if (!isSuccessful) {
        String label = attributeValueReader.getLabel(attributeName);
        if (label != null) {
            attributeName = label;
        }

        constraintValidationResult.setError(RiceKeyConstants.ERROR_REQUIRES_FIELD, attributeName);
        constraintValidationResult.setConstraintLabelKey(constraint.getMessageKey());
        constraintValidationResult.setErrorParameters(constraint.getValidationMessageParamsArray());
    }

    return constraintValidationResult;
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:43,代碼來源:BasePrerequisiteConstraintProcessor.java


注:本文中的org.kuali.rice.krad.datadictionary.validation.ValidationUtils.isNullOrEmpty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。