1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krad.datadictionary.validation.constraint; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.List; |
20 | |
|
21 | |
import org.apache.commons.lang.StringUtils; |
22 | |
import org.kuali.rice.core.api.config.property.ConfigurationService; |
23 | |
import org.kuali.rice.krad.service.KRADServiceLocator; |
24 | |
import org.kuali.rice.krad.uif.UifConstants; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | 18 | public class AlphaNumericPatternConstraint extends ValidCharactersPatternConstraint { |
32 | 18 | protected boolean allowWhitespace = false; |
33 | 18 | protected boolean allowUnderscore = false; |
34 | 18 | protected boolean allowPeriod = false; |
35 | 18 | protected boolean allowParenthesis = false; |
36 | 18 | protected boolean allowDollar = false; |
37 | 18 | protected boolean allowForwardSlash = false; |
38 | 18 | protected boolean lowerCase = false; |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
@Override |
47 | |
public String getLabelKey() { |
48 | 6 | if (StringUtils.isEmpty(labelKey)) { |
49 | 6 | StringBuilder key = new StringBuilder(""); |
50 | 6 | if (lowerCase) { |
51 | 0 | return (UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "alphanumericPatternLowerCase"); |
52 | |
} else { |
53 | 6 | return (UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "alphanumericPattern"); |
54 | |
} |
55 | |
} |
56 | 0 | return labelKey; |
57 | |
} |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
@Override |
65 | |
public void setLabelKey(String labelKey) { |
66 | 0 | super.setLabelKey(labelKey); |
67 | 0 | } |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
@Override |
73 | |
protected String getRegexString() { |
74 | |
|
75 | 6 | StringBuilder regexString = new StringBuilder("[A-Za-z0-9"); |
76 | |
|
77 | |
|
78 | |
|
79 | 6 | if (lowerCase) { |
80 | 0 | regexString = new StringBuilder("[a-z0-9"); |
81 | |
} |
82 | |
|
83 | 6 | if (allowWhitespace) { |
84 | 4 | regexString.append("\\s"); |
85 | |
} |
86 | 6 | if (allowUnderscore) { |
87 | 2 | regexString.append("_"); |
88 | |
} |
89 | 6 | if (allowPeriod) { |
90 | 2 | regexString.append("."); |
91 | |
} |
92 | 6 | if (allowParenthesis) { |
93 | 2 | regexString.append("("); |
94 | 2 | regexString.append(")"); |
95 | |
} |
96 | 6 | if (allowDollar) { |
97 | 0 | regexString.append("$"); |
98 | |
} |
99 | 6 | if (allowForwardSlash) { |
100 | 0 | regexString.append("/"); |
101 | |
} |
102 | 6 | regexString.append("]"); |
103 | |
|
104 | 6 | return regexString.toString(); |
105 | |
} |
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
public boolean isAllowWhitespace() { |
111 | 0 | return this.allowWhitespace; |
112 | |
} |
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
public void setAllowWhitespace(boolean allowWhitespace) { |
118 | 12 | this.allowWhitespace = allowWhitespace; |
119 | 12 | } |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
public boolean isAllowUnderscore() { |
125 | 0 | return this.allowUnderscore; |
126 | |
} |
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
public void setAllowUnderscore(boolean allowUnderscore) { |
132 | 6 | this.allowUnderscore = allowUnderscore; |
133 | 6 | } |
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
public boolean isAllowPeriod() { |
139 | 0 | return this.allowPeriod; |
140 | |
} |
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
public void setAllowPeriod(boolean allowPeriod) { |
146 | 6 | this.allowPeriod = allowPeriod; |
147 | 6 | } |
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
public boolean isAllowParenthesis() { |
153 | 0 | return this.allowParenthesis; |
154 | |
} |
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
public void setAllowParenthesis(boolean allowParenthesis) { |
160 | 6 | this.allowParenthesis = allowParenthesis; |
161 | 6 | } |
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
public boolean isAllowDollar() { |
167 | 0 | return this.allowDollar; |
168 | |
} |
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
public void setAllowDollar(boolean allowDollar) { |
174 | 0 | this.allowDollar = allowDollar; |
175 | 0 | } |
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
public boolean isAllowForwardSlash() { |
181 | 0 | return this.allowForwardSlash; |
182 | |
} |
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
public void setAllowForwardSlash(boolean allowForwardSlash) { |
188 | 0 | this.allowForwardSlash = allowForwardSlash; |
189 | 0 | } |
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
public boolean isLowerCase() { |
195 | 0 | return this.lowerCase; |
196 | |
} |
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
public void setLowerCase(boolean lowerCase) { |
202 | 0 | this.lowerCase = lowerCase; |
203 | 0 | } |
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
public List<String> getValidationMessageParams() { |
210 | 0 | if (validationMessageParams == null) { |
211 | 0 | validationMessageParams = new ArrayList<String>(); |
212 | 0 | ConfigurationService configService = KRADServiceLocator.getKualiConfigurationService(); |
213 | 0 | StringBuilder paramString = new StringBuilder(""); |
214 | |
|
215 | 0 | if (allowWhitespace) { |
216 | 0 | paramString.append(", " + configService |
217 | |
.getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "whitespace")); |
218 | |
} |
219 | 0 | if (allowUnderscore) { |
220 | 0 | paramString.append(", " + configService |
221 | |
.getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "underscore")); |
222 | |
} |
223 | 0 | if (allowPeriod) { |
224 | 0 | paramString.append(", " + configService |
225 | |
.getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "period")); |
226 | |
} |
227 | 0 | if (allowParenthesis) { |
228 | 0 | paramString.append(", " + configService |
229 | |
.getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "parenthesis")); |
230 | |
} |
231 | 0 | if (allowDollar) { |
232 | 0 | paramString.append(", " + configService |
233 | |
.getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "dollar")); |
234 | |
} |
235 | 0 | if (allowForwardSlash) { |
236 | 0 | paramString.append(", " + configService |
237 | |
.getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "forwardSlash")); |
238 | |
} |
239 | |
|
240 | 0 | validationMessageParams.add(paramString.toString()); |
241 | |
} |
242 | 0 | return this.validationMessageParams; |
243 | |
} |
244 | |
|
245 | |
} |