View Javadoc

1   package org.apache.turbine.services.intake.validator;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.turbine.services.intake.model.Field;
23  
24  
25  /***
26   * Validator api.
27   *
28   * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
29   * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
30   * @version $Id: Validator.java 534527 2007-05-02 16:10:59Z tv $
31   */
32  public interface Validator
33  {
34      /*** "flexible" Rule, used in DateFormat Validator */
35      String FLEXIBLE_RULE_NAME = "flexible";
36  
37      /*** "format" Rule, used in DateFormat Validator */
38      String FORMAT_RULE_NAME = "format";
39  
40      /*** "invalidNumber" Rule, used in the various Number Validators */
41      String INVALID_NUMBER_RULE_NAME = "invalidNumber";
42  
43      /*** "mask" Rule, used in StringValidator */
44      String MASK_RULE_NAME = "mask";
45  
46      /*** "maxLength" Rule, used in all validators */
47      String MAX_LENGTH_RULE_NAME = "maxLength";
48  
49      /*** "maxValue" Rule, used in the various Number Validators */
50      String MAX_VALUE_RULE_NAME = "maxValue";
51  
52      /*** "minLength" Rule, used in all validators */
53      String MIN_LENGTH_RULE_NAME = "minLength";
54  
55      /*** "minValue" Rule, used in the various Number Validators */
56      String MIN_VALUE_RULE_NAME = "minValue";
57  
58      /*** "required" Rule, used in all validators */
59      String REQUIRED_RULE_NAME = "required";
60  
61      /***
62       * Determine whether a field meets the criteria specified
63       * in the constraints defined for this validator
64       *
65       * @param field a <code>Field</code> to be tested
66       * @return true if valid, false otherwise
67       */
68      boolean isValid(Field field);
69  
70      /***
71       * Determine whether a field meets the criteria specified
72       * in the constraints defined for this validator
73       *
74       * @param field a <code>Field</code> to be tested
75       * @exception ValidationException containing an error message if the
76       * testValue did not pass the validation tests.
77       */
78      void assertValidity(Field field)
79              throws ValidationException;
80  
81      /***
82       * Determine whether a testValue meets the criteria specified
83       * in the constraints defined for this validator
84       *
85       * @param testValue a <code>String</code> to be tested
86       * @return true if valid, false otherwise
87       *
88       * @deprecated use isValid(Field) instead
89       */
90      boolean isValid(String testValue);
91  
92      /***
93       * Determine whether a testValue meets the criteria specified
94       * in the constraints defined for this validator
95       *
96       * @param testValue a <code>String</code> to be tested
97       * @exception ValidationException containing an error message if the
98       * testValue did not pass the validation tests.
99       */
100     void assertValidity(String testValue)
101             throws ValidationException;
102 
103     /***
104      * Get the last error message resulting from invalid input.
105      *
106      * @return a <code>String</code> message, or the empty String "".
107      */
108     String getMessage();
109 }