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


Java Formatable类代码示例

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


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

示例1: processSingleValidCharacterConstraint

import org.kuali.rice.krad.datadictionary.validation.capability.Formatable; //导入依赖的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

示例2: doProcessFormattableValidCharConstraint

import org.kuali.rice.krad.datadictionary.validation.capability.Formatable; //导入依赖的package包/类
protected ConstraintValidationResult doProcessFormattableValidCharConstraint(DictionaryValidationResult result,
        ValidCharactersConstraint validCharsConstraint, Formatable definition, Object value,
        AttributeValueReader attributeValueReader) throws AttributeValidationException {
    String entryName = attributeValueReader.getEntryName();
    String attributeName = attributeValueReader.getAttributeName();

    // This is a strange KNS thing for validating searchable fields -- they sometimes come in a date range format, for example 2/12/2010..2/14/2010, and need to be split up
    List<String> parsedAttributeValues = attributeValueReader.getCleanSearchableValues(attributeName);

    if (parsedAttributeValues != null) {

        Class<?> formatterClass = null;
        Boolean doValidateDateRangeOrder = null;

        // It can't be a date range if it's more than two fields, for example "a .. b | c" is not a date range -- this saves us a tiny bit of processing later
        if (parsedAttributeValues.size() != 2) {
            doValidateDateRangeOrder = Boolean.FALSE;
        }

        // Use integer to iterate since we need to track which field we're looking at
        for (int i = 0; i < parsedAttributeValues.size(); i++) {
            String parsedAttributeValue = parsedAttributeValues.get(i);

            ConstraintValidationResult constraintValidationResult = doProcessValidCharConstraint(
                    validCharsConstraint, parsedAttributeValue);

            // If this is an error then some non-null validation result will be returned
            if (constraintValidationResult != null) {
                constraintValidationResult.setConstraintLabelKey(validCharsConstraint.getMessageKey());
                constraintValidationResult.setErrorParameters(
                        validCharsConstraint.getValidationMessageParamsArray());
                // Another strange KNS thing -- if the validation fails (not sure why only in that case) then some further error checking is done using the formatter, if one exists
                if (formatterClass == null) {
                    String formatterClassName = definition.getFormatterClass();
                    if (formatterClassName != null) {
                        formatterClass = ClassLoaderUtils.getClass(formatterClassName);
                    }
                }

                if (formatterClass != null) {
                    // Use the Boolean value being null to ensure we only do this once
                    if (doValidateDateRangeOrder == null) {
                        // We only want to validate a date range if we're dealing with something that has a date formatter on it and that looks like an actual range (is made up of 2 values with a between operator between them)
                        doValidateDateRangeOrder = Boolean.valueOf(DateFormatter.class.isAssignableFrom(
                                formatterClass) && StringUtils.contains(ValidationUtils.getString(value),
                                SearchOperator.BETWEEN.toString()));
                    }

                    constraintValidationResult = processFormatterValidation(result, formatterClass, entryName,
                            attributeName, parsedAttributeValue, DATE_RANGE_ERROR_PREFIXES[i]);

                    if (constraintValidationResult != null) {
                        result.addConstraintValidationResult(attributeValueReader, constraintValidationResult);
                        return constraintValidationResult;
                    }
                } else {
                    // Otherwise, just report the validation result (apparently the formatter can't provide any fall-through validation because it doesn't exist)
                    result.addConstraintValidationResult(attributeValueReader, constraintValidationResult);
                    return constraintValidationResult;
                }
            }
        }

        if (doValidateDateRangeOrder != null && doValidateDateRangeOrder.booleanValue()) {
            ConstraintValidationResult dateOrderValidationResult = validateDateOrder(parsedAttributeValues.get(0),
                    parsedAttributeValues.get(1), entryName, attributeName);

            if (dateOrderValidationResult != null) {
                result.addConstraintValidationResult(attributeValueReader, dateOrderValidationResult);
                return dateOrderValidationResult;
            }
        }

        return result.addSuccess(attributeValueReader, CONSTRAINT_NAME);
    }
    return result.addSkipped(attributeValueReader, CONSTRAINT_NAME);
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:78,代码来源:ValidCharactersConstraintProcessor.java


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