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