1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.datadictionary.validation.charlevel;
17
18 import org.kuali.rice.krad.datadictionary.exporter.ExportMap;
19 import org.kuali.rice.krad.datadictionary.validation.CharacterLevelValidationPattern;
20 import org.kuali.rice.krad.util.KRADConstants;
21
22
23
24
25
26
27 public class AlphaValidationPattern extends CharacterLevelValidationPattern {
28 protected boolean allowWhitespace = false;
29
30
31
32
33
34 public boolean getAllowWhitespace() {
35 return allowWhitespace;
36 }
37
38
39
40
41 public void setAllowWhitespace(boolean allowWhitespace) {
42 this.allowWhitespace = allowWhitespace;
43 }
44
45
46
47
48
49 protected String getRegexString() {
50 StringBuffer regexString = new StringBuffer("[A-Za-z");
51
52 if (allowWhitespace) {
53 regexString.append("\\s");
54 }
55 regexString.append("]");
56
57 return regexString.toString();
58 }
59
60
61
62
63
64 public void extendExportMap(ExportMap exportMap) {
65 exportMap.set("type", "alpha");
66
67 if (allowWhitespace) {
68 exportMap.set("allowWhitespace", "true");
69 }
70 }
71
72 @Override
73 protected String getValidationErrorMessageKeyOptions() {
74 if (getAllowWhitespace()) {
75 return ".allowWhitespace";
76 }
77 return KRADConstants.EMPTY_STRING;
78 }
79 }