1 /** 2 * Copyright 2005-2011 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.krad.datadictionary.validation; 17 18 import org.kuali.rice.krad.datadictionary.exporter.ExportMap; 19 import org.kuali.rice.krad.service.KRADServiceLocator; 20 21 import java.util.regex.Pattern; 22 23 /** 24 * Abstraction of the regular expressions used to validate attribute values. 25 * 26 * 27 */ 28 @Deprecated 29 abstract public class FieldLevelValidationPattern extends ValidationPattern { 30 protected Pattern regexPattern; 31 32 /** 33 * Uses the key returned by getConfigurationRegexKey to fetch the validationPattern's regex string from the 34 * ConfigurationService 35 * 36 * @see org.kuali.rice.krad.datadictionary.validation.ValidationPattern#getRegexString() 37 */ 38 protected String getRegexString() { 39 return (String) KRADServiceLocator.getKualiConfigurationService().getPropertyValueAsString( 40 "validationPatternRegex." + getPatternTypeName()); 41 } 42 43 /** 44 * @return the key used to retrieve the validationPattern's type name, which is used as the suffix of the regex property key, as 45 * the type entry in the exportMap, etc. 46 */ 47 abstract protected String getPatternTypeName(); 48 49 50 /** 51 * @return regular expression Pattern generated using the individual ValidationPattern subclass 52 */ 53 public final Pattern getRegexPattern() { 54 if ( regexPattern == null ) { 55 StringBuffer completeRegex = new StringBuffer("^"); 56 completeRegex.append(getRegexString()); 57 completeRegex.append("$"); 58 regexPattern = Pattern.compile(completeRegex.toString()); 59 } 60 return regexPattern; 61 } 62 63 64 /** 65 * @see org.kuali.rice.krad.datadictionary.validation.ValidationPattern#buildExportMap(java.lang.String) 66 */ 67 public ExportMap buildExportMap(String exportKey) { 68 ExportMap exportMap = new ExportMap(exportKey); 69 70 exportMap.set("type", getPatternTypeName()); 71 72 return exportMap; 73 } 74 75 /** 76 * This overridden method ... 77 * 78 * @see org.kuali.rice.krad.datadictionary.validation.ValidationPattern#getValidationErrorMessageKey() 79 */ 80 @Override 81 public String getValidationErrorMessageKey() { 82 StringBuilder buf = new StringBuilder(); 83 buf.append("error.format.").append(getClass().getName()); 84 return buf.toString(); 85 } 86 }