Package org.apache.cocoon.woody.util

Examples of org.apache.cocoon.woody.util.I18nMessage


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


    }

    public boolean validate(FormContext formContext) {
        if (this.part == null) {
            if (this.uploadDefinition.isRequired()) {
                this.validationError = new ValidationError(new I18nMessage("general.field-required", Constants.I18N_CATALOGUE));
            }
        } else {
            String mimeTypes = this.uploadDefinition.getMimeTypes();
            if (mimeTypes != null) {
                StringTokenizer tok = new StringTokenizer(this.uploadDefinition.getMimeTypes(), ", ");
                this.validationError = new ValidationError(new I18nMessage("upload.invalid-type", Constants.I18N_CATALOGUE));
                String contentType = this.part.getMimeType();
                while (tok.hasMoreTokens()) {
                    if (tok.nextToken().equals(contentType)) {
                        this.validationError = null;
                    }
View Full Code Here

            } else {
                sum += currentDigit;
            }
        }
        if(!((sum % 10) == 0))
            return hasFailMessage() ? getFailMessage() : new ValidationError(new I18nMessage("validation.mod10", Constants.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", Constants.I18N_CATALOGUE));
    }
View Full Code Here

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


        return validationError == null ? super.validate(formContext) : false;
    }
View Full Code Here

        // valid unless proven otherwise
        validationError = null;

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

    }

    public boolean validate(FormContext formContext) {
        if (this.part == null) {
            if (this.uploadDefinition.isRequired()) {
                this.validationError = new ValidationError(new I18nMessage("general.field-required", Constants.I18N_CATALOGUE));
            }
        } else {
            String mimeTypes = this.uploadDefinition.getMimeTypes();
            if (mimeTypes != null) {
                StringTokenizer tok = new StringTokenizer(this.uploadDefinition.getMimeTypes(), ", ");
                this.validationError = new ValidationError(new I18nMessage("upload.invalid-type", Constants.I18N_CATALOGUE));
                String contentType = this.part.getMimeType();
                while (tok.hasMoreTokens()) {
                    if (tok.nextToken().equals(contentType)) {
                        this.validationError = null;
                    }
View Full Code Here

                this.value = getDatatype().convertFromString(this.enteredValue, getForm().getLocale());
                if (this.value != null) {       // Conversion successfull
                    this.needsParse = false;
                    this.needsValidate = true;
                } else {        // Conversion failed
                    this.validationError = new ValidationError(new I18nMessage(
                        "datatype.conversion-failed",
                        new String[] {"datatype." + getDatatype().getDescriptiveName()},
                        new boolean[] { true },
                        Constants.I18N_CATALOGUE
                    ));
                    // No need for further validation (and need to keep the above error)
                    this.needsValidate = false;
                }
            } else {
                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 {
                if (super.validate(null)) {
                    // New-style validators were successful. Check the old-style ones.
                    if (this.value != null) {
                        this.validationError = getDatatype().validate(value, new ExpressionContextImpl(this));
                    } else {        // No value : is it required ?
                        if (this.fieldDefinition.isRequired()) {
                            this.validationError = new ValidationError(new I18nMessage("general.field-required", Constants.I18N_CATALOGUE));
                        }
                    }
                }
                this.needsValidate = false;
            } finally {
View Full Code Here

            max = (Comparable) result;
        }
       
        if (min != null && max != null) {
            if (decimal.compareTo(min) < 0 || decimal.compareTo(max) > 0) {
                return hasFailMessage() ? getFailMessage() : new ValidationError(new I18nMessage("validation.numeric.range",
                                                                                 new String[]{min.toString(), max.toString()},
                                                                                 Constants.I18N_CATALOGUE));
            }

            return null;
        } else if (min != null) {
            if (decimal.compareTo(min) < 0) {
                return hasFailMessage() ? getFailMessage() : new ValidationError(new I18nMessage("validation.numeric.min",
                                                                                 new String[]{min.toString()},
                                                                                 Constants.I18N_CATALOGUE));
            }

            return null;
        } else if (max != null) {
            if (decimal.compareTo(max) > 0) {
                return hasFailMessage() ? getFailMessage() : new ValidationError(new I18nMessage("validation.numeric.max",
                                                                                 new String[]{max.toString()},
                                                                                 Constants.I18N_CATALOGUE));
            }

            return null;
View Full Code Here

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

            result = evaluateNumeric(maxExpr, expressionContext, "max", "length");
            if (result instanceof ValidationError)
                return (ValidationError)result;
            else if (result instanceof CannotYetResolveWarning)
                return null;
            int maxLength = ((BigDecimal)result).intValue();

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

TOP

Related Classes of org.apache.cocoon.woody.util.I18nMessage

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.