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
21
22
23
24
25
26 public class AlphaNumericValidationPattern extends CharacterLevelValidationPattern {
27 protected boolean allowWhitespace = false;
28 protected boolean allowUnderscore = false;
29 protected boolean allowPeriod = false;
30
31 protected boolean allowParenthesis = false;
32 protected boolean allowDollar = false;
33 protected boolean allowForwardSlash = false;
34 protected boolean lowerCase = false;
35
36
37
38
39 public boolean getAllowPeriod() {
40 return allowPeriod;
41 }
42
43
44
45
46 public void setAllowPeriod(boolean allowPeriod) {
47 this.allowPeriod = allowPeriod;
48 }
49
50
51
52
53 public boolean isAllowPeriod() {
54 return allowPeriod;
55 }
56
57
58
59
60 public boolean isAllowParenthesis() {
61 return allowParenthesis;
62 }
63
64
65
66
67 public void setAllowParenthesis(boolean allowParenthesis) {
68 this.allowParenthesis = allowParenthesis;
69 }
70
71
72
73
74 public boolean isAllowDollar() {
75 return allowDollar;
76 }
77
78
79
80
81 public void setAllowDollar(boolean allowDollar) {
82 this.allowDollar = allowDollar;
83 }
84
85
86
87
88 public boolean isAllowForwardSlash() {
89 return allowForwardSlash;
90 }
91
92
93
94
95 public void setAllowForwardSlash(boolean allowForwardSlash) {
96 this.allowForwardSlash = allowForwardSlash;
97 }
98
99
100
101
102 public boolean getAllowWhitespace() {
103 return allowWhitespace;
104 }
105
106
107
108
109 public void setAllowWhitespace(boolean allowWhitespace) {
110 this.allowWhitespace = allowWhitespace;
111 }
112
113
114
115
116
117 public boolean getAllowUnderscore() {
118 return allowUnderscore;
119 }
120
121
122
123
124 public void setAllowUnderscore(boolean allowUnderscore) {
125 this.allowUnderscore = allowUnderscore;
126 }
127
128
129
130
131 public boolean isLowerCase() {
132 return this.lowerCase;
133 }
134
135
136
137
138 public void setLowerCase(boolean lowerCase) {
139 this.lowerCase = lowerCase;
140 }
141
142
143
144
145 protected String getRegexString() {
146 StringBuilder regexString = new StringBuilder("[A-Za-z0-9");
147
148
149
150
151 if(lowerCase){
152 regexString = new StringBuilder("[a-z0-9");
153 }
154
155 if (allowWhitespace) {
156 regexString.append("\\s");
157 }
158 if (allowUnderscore) {
159 regexString.append("_");
160 }
161 if (allowPeriod) {
162 regexString.append(".");
163 }
164 if(allowParenthesis) {
165 regexString.append("(");
166 regexString.append(")");
167 }
168 if(allowDollar) {
169 regexString.append("$");
170 }
171 if(allowForwardSlash) {
172 regexString.append("/");
173 }
174 regexString.append("]");
175
176 return regexString.toString();
177 }
178
179
180
181
182
183 public void extendExportMap(ExportMap exportMap) {
184 exportMap.set("type", "alphaNumeric");
185
186 if (lowerCase) {
187 exportMap.set("allowUpperCase", "true");
188 }
189 if (allowWhitespace) {
190 exportMap.set("allowWhitespace", "true");
191 }
192 if (allowUnderscore) {
193 exportMap.set("allowUnderscore", "true");
194 }
195 if (allowPeriod) {
196 exportMap.set("allowPeriod", "true");
197 }
198 if(allowParenthesis) {
199 exportMap.set("allowParenthesis", "true");
200
201 }
202 if(allowDollar) {
203 exportMap.set("allowDollar", "true");
204
205 }
206 if(allowForwardSlash) {
207 exportMap.set("allowForwardSlash", "true");
208
209 }
210 }
211
212 @Override
213 protected String getValidationErrorMessageKeyOptions() {
214 final StringBuilder opts = new StringBuilder();
215
216 if (lowerCase) {
217 opts.append(".lowerCase");
218 }
219 if (allowWhitespace) {
220 opts.append(".allowWhitespace");
221 }
222 if (allowUnderscore) {
223 opts.append(".allowUnderscore");
224 }
225 if (allowPeriod) {
226 opts.append(".allowPeriod");
227 }
228 if(allowParenthesis) {
229 opts.append(".allowParenthesis");
230 }
231 if(allowDollar) {
232 opts.append(".allowDollar");
233 }
234 if(allowForwardSlash) {
235 opts.append(".allowForwardSlash");
236 }
237
238 return opts.toString();
239 }
240 }