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