Package org.apache.cocoon.woody.datatype

Examples of org.apache.cocoon.woody.datatype.ValidationError


        try {
            expressionResult = expression.evaluate(expressionContext);
        } catch (CannotYetResolveWarning w) {
            return w;
        } catch (ExpressionException e) {
            return new ValidationError("Error evaluating \"" + exprName + "\" expression on \"" +
                                       ruleName + "\" validation rule", false);
        }
       
        if (!(expressionResult instanceof BigDecimal)) {
            return new ValidationError("Got non-numeric result from \"" + exprName + "\" expression on \"" +
                                       ruleName + "\" validation rule", false);
        }

        return expressionResult;
    }
View Full Code Here


        try {
            expressionResult = expression.evaluate(expressionContext);
        } catch (CannotYetResolveWarning w) {
            return w;
        } catch (ExpressionException e) {
            return new ValidationError("Error evaluating \"" + exprName + "\" expression on \"" +
                                       ruleName + "\" validation rule", false);
        }
       
        if (!(expressionResult instanceof Comparable)) {
            return new ValidationError("Got non-comparable result from \"" + exprName + "\" expression on \"" +
                                       ruleName + "\" validation rule", false);
        }

        return expressionResult;
    }
View Full Code Here

            else if (result instanceof CannotYetResolveWarning)
                return null;
            BigDecimal max = (BigDecimal) result;

            if (decimal.compareTo(min) < 0 || decimal.compareTo(max) > 0)
                return hasFailMessage() ? getFailMessage() : new ValidationError("validation.numeric.range", new String[]{min.toString(), max.toString()});
            return null;
        } else if (minExpr != null) {
            Object result = evaluateNumeric(minExpr, expressionContext, MIN_ATTR, RANGE_ELEM);
            if (result instanceof ValidationError)
                return (ValidationError) result;
            else if (result instanceof CannotYetResolveWarning)
                return null;
            BigDecimal min = (BigDecimal) result;
            if (decimal.compareTo(min) < 0)
                return hasFailMessage() ? getFailMessage() : new ValidationError("validation.numeric.min", new String[]{min.toString()});
            return null;
        } else if (maxExpr != null) {
            Object result = evaluateNumeric(maxExpr, expressionContext, MAX_ATTR, RANGE_ELEM);
            if (result instanceof ValidationError)
                return (ValidationError) result;
            else if (result instanceof CannotYetResolveWarning)
                return null;
            BigDecimal max = (BigDecimal) result;
            if (decimal.compareTo(max) > 0)
                return hasFailMessage() ? getFailMessage() : new ValidationError("validation.numeric.max", new String[]{max.toString()});
            return null;
        }
        return null;
    }
View Full Code Here

    public boolean validate(FormContext formContext) {
        if (values != null)
            validationError = definition.getDatatype().validate(values, new ExpressionContextImpl(this));
        else
            validationError = new ValidationError("multivaluefield.conversionfailed");

        return validationError == null;
    }
View Full Code Here

    public boolean validate(FormContext formContext) {
        // valid unless proven otherwise
        validationError = null;

        if (enteredValue == null && isRequired()) {
            validationError = new ValidationError("general.field-required");
            return false;
        } else if (enteredValue == null)
            return true;
        else if (!fieldsHaveValues()) {
            Object splitFailMessage = definition.getSplitFailMessage();
            if (splitFailMessage != null)
                validationError = new ValidationError(splitFailMessage);
            else
                validationError = new ValidationError("aggregatedfield.split-failed", new String[] { definition.getSplitRegexp()});
            return false;
        } else {
            // validate my child fields
            Iterator fieldsIt = fields.iterator();
            while (fieldsIt.hasNext()) {
View Full Code Here

                // Parse the value
                this.value = definition.getDatatype().convertFromString(this.enteredValue, getForm().getLocale());

                if (this.value == null) {
                    // Conversion failed
                    this.validationError = new ValidationError(
                        "datatype.conversion-failed",
                        new String[] {"datatype." + definition.getDatatype().getDescriptiveName()},
                        new boolean[] { true }
                    );

                    // No need for further validation (and need to keep the above error)
                    this.needsValidate = false;
                } else {
                    // Conversion successfull
                    this.needsParse = false;
                    this.needsValidate = true;
                }
            }
        }

        // if getValue() is called on this field while we're validating, then it's because a validation
        // rule called getValue(), so then we just return the parsed (but not validated) value to avoid an endless loop
        if (isValidating) {
            return value;
        }

        // Validate the value
        if (this.needsValidate) {
            isValidating = true;
            try {
                // Clear error, it will be recomputed
                this.validationError = null;

                if (this.value == null) {
                    // No value : is it required ?
                    if (this.definition.isRequired()) {
                        this.validationError = new ValidationError("general.field-required");
                    }

                } else {
                    this.validationError = definition.getDatatype().validate(value, new ExpressionContextImpl(this));
                }
View Full Code Here

    public boolean validate(FormContext formContext) {
        if (value != null)
            validationError = definition.getDatatype().validate(value, new ExpressionContextImpl(this));
        else if (conversionFailed)
            validationError = new ValidationError("datatype.conversion-failed", new String[] {"datatype." + definition.getDatatype().getDescriptiveName()}, new boolean[] { true });
        else if (definition.isRequired())
            validationError = new ValidationError("general.field-required");

        return validationError == null;
    }
View Full Code Here

    public ValidationError validate(Object value, ExpressionContext expressionContext) {
        Iterator validationRulesIt = validationRules.iterator();
        while (validationRulesIt.hasNext()) {
            ValidationRule validationRule = (ValidationRule)validationRulesIt.next();
            ValidationError result = validationRule.validate(value, expressionContext);
            if (result != null)
                return result;
        }
        return null;
    }
View Full Code Here

    public boolean validate(FormContext formContext) {
        if (value != null)
            validationError = definition.getDatatype().validate(value, new ExpressionContextImpl(this));
        else if (conversionFailed)
            validationError = new ValidationError("datatype.conversion-failed", new String[] {"datatype." + definition.getDatatype().getDescriptiveName()}, new boolean[] { true });
        else if (definition.isRequired())
            validationError = new ValidationError("general.field-required");

        return validationError == null;
    }
View Full Code Here

    public boolean validate(FormContext formContext) {
        // valid unless proven otherwise
        validationError = null;

        if (enteredValue == null && isRequired()) {
            validationError = new ValidationError("general.field-required");
            return false;
        } else if (enteredValue == null)
            return true;
        else if (!fieldsHaveValues()) {
            Object splitFailMessage = definition.getSplitFailMessage();
            if (splitFailMessage != null)
                validationError = new ValidationError(splitFailMessage);
            else
                validationError = new ValidationError("aggregatedfield.split-failed", new String[] { definition.getSplitRegexp()});
            return false;
        } else {
            // validate my child fields
            Iterator fieldsIt = fields.iterator();
            while (fieldsIt.hasNext()) {
View Full Code Here

TOP

Related Classes of org.apache.cocoon.woody.datatype.ValidationError

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.