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