Coverage Report - org.kuali.rice.kns.datadictionary.validation.ValidationPattern
 
Classes in this File Line Coverage Branch Coverage Complexity
ValidationPattern
0%
0/7
N/A
1
ValidationPattern$ValidationPatternException
0%
0/8
N/A
1
 
 1  
 /*
 2  
  * Copyright 2005-2008 The Kuali Foundation
 3  
  * 
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kns.datadictionary.validation;
 17  
 
 18  
 import java.io.Serializable;
 19  
 import java.util.regex.Matcher;
 20  
 import java.util.regex.Pattern;
 21  
 
 22  
 import org.kuali.rice.core.exception.RiceRuntimeException;
 23  
 import org.kuali.rice.kns.datadictionary.exporter.ExportMap;
 24  
 
 25  
 /**
 26  
  * Abstraction of the regular expressions used to validate attribute values.
 27  
  * 
 28  
                     The validationPattern element defines the allowable character-level
 29  
                     or field-level values for an attribute.
 30  
 
 31  
                     JSTL: validationPattern is a Map which is accessed using a key
 32  
                     of "validationPattern". Each entry may contain some of the keys
 33  
                     listed below.  The keys that may be present for a given attribute
 34  
                     are dependent upon the type of validationPattern.
 35  
 
 36  
                         * maxLength (String)
 37  
                         * exactLength
 38  
                         * type
 39  
                         * allowWhitespace
 40  
                         * allowUnderscore
 41  
                         * allowPeriod
 42  
                         * validChars
 43  
                         * precision
 44  
                         * scale
 45  
                         * allowNegative
 46  
 
 47  
                     The allowable keys (in addition to type) for each type are:
 48  
                         ****Type****    ***Keys***
 49  
                         alphanumeric    exactLength
 50  
                                         maxLength
 51  
                                         allowWhitespace
 52  
                                         allowUnderscore
 53  
                                         allowPeriod
 54  
 
 55  
                         alpha           exactLength
 56  
                                         maxLength
 57  
                                         allowWhitespace
 58  
 
 59  
                         anyCharacter    exactLength
 60  
                                         maxLength
 61  
                                         allowWhitespace
 62  
 
 63  
                         charset         validChars
 64  
 
 65  
                         numeric         exactLength
 66  
                                         maxLength
 67  
 
 68  
                         fixedPoint      allowNegative
 69  
                                         precision
 70  
                                         scale
 71  
 
 72  
                         floatingPoint   allowNegative
 73  
 
 74  
                         date            n/a
 75  
                         emailAddress    n/a
 76  
                         javaClass       n/a
 77  
                         month           n/a
 78  
                         phoneNumber     n/a
 79  
                         timestamp       n/a
 80  
                         year            n/a
 81  
                         zipcode         n/a
 82  
 
 83  
                     Note: maxLength and exactLength are mutually exclusive.
 84  
                     If one is entered, the other may not be entered.
 85  
 
 86  
                     Note:  See ApplicationResources.properties for
 87  
                     exact regex patterns.
 88  
                     e.g. validationPatternRegex.date for regex used in date validation.
 89  
  */
 90  0
 abstract public class ValidationPattern implements Serializable {
 91  
 // TODO: UNIT TEST: compile all patterns to test
 92  
 
 93  
     /**
 94  
      * @return regular expression Pattern generated by the individual ValidationPattern subclass
 95  
      */
 96  
     abstract public Pattern getRegexPattern();
 97  
 
 98  
     /**
 99  
      * @return String version of regular expression base, suitable for modification with length-specifiers and used internally by
 100  
      *         getRegexPattern
 101  
      */
 102  
     abstract protected String getRegexString();
 103  
 
 104  
 
 105  
     /**
 106  
      * @return true if the given String matches this pattern
 107  
      */
 108  
     public boolean matches(String input) {
 109  0
         Pattern p = getRegexPattern();
 110  
 
 111  0
         Matcher m = p.matcher(input);
 112  
 
 113  0
         return m.matches();
 114  
     }
 115  
 
 116  
     /**
 117  
      * @return ExportMap describing the subclass instance
 118  
      */
 119  
     abstract public ExportMap buildExportMap(String exportKey);
 120  
     
 121  
     abstract public String getValidationErrorMessageKey();
 122  
     
 123  
     public String[] getValidationErrorMessageParameters(String attributeLabel) {
 124  0
         return new String[] {attributeLabel};
 125  
     }
 126  
     
 127  
     /**
 128  
      * This method throws an exception if it is not configured properly
 129  
      * 
 130  
      */
 131  
     public void completeValidation() throws ValidationPatternException {
 132  0
     }
 133  
     
 134  
     /** exception thrown when a ValidationPattern is in an incorrect state. */
 135  0
     public static class ValidationPatternException extends RiceRuntimeException {
 136  
 
 137  
             private static final long serialVersionUID = 2012770642382150523L;
 138  
         
 139  
         public ValidationPatternException(String message) {
 140  0
             super(message);
 141  0
         }
 142  
 
 143  
         public ValidationPatternException() {
 144  0
             super();
 145  0
         }
 146  
 
 147  
         public ValidationPatternException(String message, Throwable cause) {
 148  0
             super(message, cause);
 149  0
         }
 150  
 
 151  
         public ValidationPatternException(Throwable cause) {
 152  0
             super(cause);
 153  0
         }
 154  
     }
 155  
 }