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