Package org.apache.cocoon.forms.validation

Examples of org.apache.cocoon.forms.validation.ValidationError


            } else if (result instanceof CannotYetResolveWarning) {
                return null;
            }
            int length = ((BigDecimal)result).intValue();
            if (array.length != length) {
                return hasFailMessage() ? getFailMessage() : new ValidationError(new I18nMessage("validation.array.exact-valuecount", new String[] {String.valueOf(length)}, FormsConstants.I18N_CATALOGUE));
            }
            return null;
        } else if (minExpr != null && maxExpr != null) {
            Object result = evaluateNumeric(minExpr, expressionContext, "min", "value-count");
            if (result instanceof ValidationError) {
                return (ValidationError)result;
            } else if (result instanceof CannotYetResolveWarning) {
                return null;
            }
            int minLength = ((BigDecimal)result).intValue();

            result = evaluateNumeric(maxExpr, expressionContext, "max", "value-count");
            if (result instanceof ValidationError) {
                return (ValidationError)result;
            } else if (result instanceof CannotYetResolveWarning) {
                return null;
            }
            int maxLength = ((BigDecimal)result).intValue();

            if (array.length < minLength || array.length > maxLength) {
                return hasFailMessage() ? getFailMessage() : new ValidationError(new I18nMessage("validation.array.range-valuecount", new String[] {String.valueOf(minLength), String.valueOf(maxLength)}, FormsConstants.I18N_CATALOGUE));
            }
            return null;
        } else if (minExpr != null) {
            Object result = evaluateNumeric(minExpr, expressionContext, "min", "value-count");
            if (result instanceof ValidationError) {
                return (ValidationError)result;
            } else if (result instanceof CannotYetResolveWarning) {
                return null;
            }
            int length = ((BigDecimal)result).intValue();
            if (array.length < length) {
                return hasFailMessage() ? getFailMessage() : new ValidationError(new I18nMessage("validation.array.min-valuecount", new String[] {String.valueOf(length)}, FormsConstants.I18N_CATALOGUE));
            }
            return null;
        } else if (maxExpr != null) {
            Object result = evaluateNumeric(maxExpr, expressionContext, "max", "value-count");
            if (result instanceof ValidationError) {
                return (ValidationError)result;
            } else if (result instanceof CannotYetResolveWarning) {
                return null;
            }
            int length = ((BigDecimal)result).intValue();
            if (array.length > length) {
                return hasFailMessage() ? getFailMessage() : new ValidationError(new I18nMessage("validation.array.max-valuecount", new String[] {String.valueOf(length)}, FormsConstants.I18N_CATALOGUE));
            }
            return null;
        }
        return null;
    }
View Full Code Here


            // No value. Consider it as correct (required="true" will set an error if present)
            return true;
           
        } else {
            // Non-null value: perform validation
            ValidationError error = this.rule.validate(value, new ExpressionContextImpl(widget));
            if (error != null) {
                // Validation failed
                ((ValidationErrorAware)widget).setValidationError(error);
                return false;
            } else {
View Full Code Here

    protected ValidationError buildFailMessage(Element validationRuleElement) {
        Element failMessageElement = DomHelper.getChildElement(validationRuleElement,
                                                               FormsConstants.DEFINITION_NS, "failmessage");
        if (failMessageElement != null) {
            XMLizable failMessage = DomHelper.compileElementContent(failMessageElement);
            return new ValidationError(failMessage);
        }
        return this.getDefaultFailMessage();
    }
View Full Code Here

            return false;
        }

        if (result instanceof String) {
            // Set a non-i18n error on the current widget
            ((ValidationErrorAware)widget).setValidationError(new ValidationError((String)result, false));
            return false;
        }

        if (result instanceof XMLizable) {
            // Set a xmlizable error (e.g. I18nMessage) on the current widget
            ((ValidationErrorAware)widget).setValidationError(new ValidationError((XMLizable)result));
            return false;
        }

        throw new RuntimeException("Validation script returned an unexpected value of type " + result.getClass());
    }
View Full Code Here

        try {
            expressionResult = testExpression.evaluate(expressionContext);
        } catch (CannotYetResolveWarning w) {
            return null;
        } catch (ExpressionException e) {
            return new ValidationError("Error evaluating expression on assert validation rule.", false);
        }

        if (!(expressionResult instanceof Boolean))
            return new ValidationError("Got non-boolean result from expression on assert validation rule.", false);

        if (((Boolean)expressionResult).booleanValue())
            return null;
        else
            return hasFailMessage() ? getFailMessage() : new ValidationError("Assertion validation rule failed.", false);
    }
View Full Code Here

      String string = (String)value;
     
      if(matchesRegExp(string))
         return null;  
      else
        return hasFailMessage() ? getFailMessage() : new ValidationError(new I18nMessage("validation.string.regexp", new String[] {regexp}, FormsConstants.I18N_CATALOGUE));
    }
View Full Code Here

            } else {
                sum += currentDigit;
            }
        }
        if(!((sum % 10) == 0))
            return hasFailMessage() ? getFailMessage() : new ValidationError(new I18nMessage("validation.mod10", FormsConstants.I18N_CATALOGUE));
        else
            return null;
    }
View Full Code Here

        String email = (String)value;

        if (isEmail(email))
            return null;
        else
            return hasFailMessage() ? getFailMessage() : new ValidationError(new I18nMessage("validation.string.invalidemail", FormsConstants.I18N_CATALOGUE));
    }
View Full Code Here

    /**
     * Returns the failMessage wrapped in a ValidationError object.
     */
    public ValidationError getFailMessage() {
        return new ValidationError(failMessage);
    }
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 BigDecimal)) {
            return new ValidationError("Got non-numeric result from \"" + exprName + "\" expression on \"" +
                                       ruleName + "\" validation rule", false);
        }

        return expressionResult;
    }
View Full Code Here

TOP

Related Classes of org.apache.cocoon.forms.validation.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.