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