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().getPropertyString("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 | 0 | if ( regexPattern == null ) { |
55 | 0 | StringBuffer completeRegex = new StringBuffer("^"); |
56 | 0 | completeRegex.append(getRegexString()); |
57 | 0 | completeRegex.append("$"); |
58 | 0 | regexPattern = Pattern.compile(completeRegex.toString()); |
59 | } | |
60 | 0 | 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 | 0 | ExportMap exportMap = new ExportMap(exportKey); |
69 | ||
70 | 0 | exportMap.set("type", getPatternTypeName()); |
71 | ||
72 | 0 | 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 | 0 | StringBuilder buf = new StringBuilder(); |
83 | 0 | buf.append("error.format.").append(getClass().getName()); |
84 | 0 | return buf.toString(); |
85 | } | |
86 | } |