001    package org.apache.fulcrum.intake.validator;
002    
003    import org.apache.fulcrum.intake.model.Field;
004    
005    /*
006     * Licensed to the Apache Software Foundation (ASF) under one
007     * or more contributor license agreements.  See the NOTICE file
008     * distributed with this work for additional information
009     * regarding copyright ownership.  The ASF licenses this file
010     * to you under the Apache License, Version 2.0 (the
011     * "License"); you may not use this file except in compliance
012     * with the License.  You may obtain a copy of the License at
013     *
014     *   http://www.apache.org/licenses/LICENSE-2.0
015     *
016     * Unless required by applicable law or agreed to in writing,
017     * software distributed under the License is distributed on an
018     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
019     * KIND, either express or implied.  See the License for the
020     * specific language governing permissions and limitations
021     * under the License.
022     */
023    
024    /**
025     * Validator api.
026     *
027     * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
028     * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
029     * @version $Id: Validator.java 535465 2007-05-05 06:58:06Z tv $
030     */
031    public interface Validator
032    {
033        /** "flexible" Rule, used in DateFormat Validator */
034        String FLEXIBLE_RULE_NAME = "flexible";
035    
036        /** "format" Rule, used in DateFormat Validator */
037        String FORMAT_RULE_NAME = "format";
038    
039        /** "invalidNumber" Rule, used in the various Number Validators */
040        String INVALID_NUMBER_RULE_NAME = "invalidNumber";
041    
042        /** "mask" Rule, used in StringValidator */
043        String MASK_RULE_NAME = "mask";
044    
045        /** "maxLength" Rule, used in all validators */
046        String MAX_LENGTH_RULE_NAME = "maxLength";
047    
048        /** "maxValue" Rule, used in the various Number Validators */
049        String MAX_VALUE_RULE_NAME = "maxValue";
050    
051        /** "minLength" Rule, used in all validators */
052        String MIN_LENGTH_RULE_NAME = "minLength";
053    
054        /** "minValue" Rule, used in the various Number Validators */
055        String MIN_VALUE_RULE_NAME = "minValue";
056    
057        /** "required" Rule, used in all validators */
058        String REQUIRED_RULE_NAME = "required";
059    
060        /**
061         * Determine whether a field meets the criteria specified
062         * in the constraints defined for this validator
063         *
064         * @param field a <code>Field</code> to be tested
065         * @return true if valid, false otherwise
066         */
067        boolean isValid(Field field);
068    
069        /**
070         * Determine whether a field meets the criteria specified
071         * in the constraints defined for this validator
072         *
073         * @param field a <code>Field</code> to be tested
074         * @exception ValidationException containing an error message if the
075         * testValue did not pass the validation tests.
076         */
077        void assertValidity(Field field)
078                throws ValidationException;
079    
080        /**
081         * Determine whether a testValue meets the criteria specified
082         * in the constraints defined for this validator
083         *
084         * @param testValue a <code>String</code> to be tested
085         * @return true if valid, false otherwise
086         *
087         * @deprecated use isValid(Field) instead
088         */
089        boolean isValid(String testValue);
090    
091        /**
092         * Determine whether a testValue meets the criteria specified
093         * in the constraints defined for this validator
094         *
095         * @param testValue a <code>String</code> to be tested
096         * @exception ValidationException containing an error message if the
097         * testValue did not pass the validation tests.
098         */
099        void assertValidity(String testValue)
100                throws ValidationException;
101    
102        /**
103         * Get the last error message resulting from invalid input.
104         *
105         * @return a <code>String</code> message, or the empty String "".
106         */
107        String getMessage();
108    }