01: /*
02: * Copyright 2005-2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.core.datadictionary.validation;
17:
18: import java.util.regex.Pattern;
19:
20: import org.kuali.core.datadictionary.exporter.ExportMap;
21: import org.kuali.rice.KNSServiceLocator;
22:
23: /**
24: * Abstraction of the regular expressions used to validate attribute values.
25: *
26: *
27: */
28: abstract public class FieldLevelValidationPattern extends
29: ValidationPattern {
30: /**
31: * Uses the key returned by getConfigurationRegexKey to fetch the validationPattern's regex string from the
32: * KualiConfigurationService
33: *
34: * @see org.kuali.core.datadictionary.validation.ValidationPattern#getRegexString()
35: */
36: protected String getRegexString() {
37: return (String) KNSServiceLocator
38: .getKualiConfigurationService().getPropertyString(
39: "validationPatternRegex."
40: + 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: * @return regular expression Pattern generated using the individual ValidationPattern subclass
51: */
52: public final Pattern getRegexPattern() {
53: StringBuffer completeRegex = new StringBuffer("^");
54: completeRegex.append(getRegexString());
55: completeRegex.append("$");
56:
57: return Pattern.compile(completeRegex.toString());
58: }
59:
60: /**
61: * @see org.kuali.core.datadictionary.validation.ValidationPattern#buildExportMap(java.lang.String)
62: */
63: public ExportMap buildExportMap(String exportKey) {
64: ExportMap exportMap = new ExportMap(exportKey);
65:
66: exportMap.set("type", getPatternTypeName());
67:
68: return exportMap;
69: }
70: }
|