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