Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AnyCharacterPatternConstraint |
|
| 2.0;2 |
1 | /** | |
2 | * Copyright 2005-2011 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.constraint; | |
17 | ||
18 | import org.apache.commons.lang.StringUtils; | |
19 | import org.kuali.rice.krad.uif.UifConstants; | |
20 | ||
21 | /** | |
22 | * Pattern for matching any printable character | |
23 | */ | |
24 | 6 | public class AnyCharacterPatternConstraint extends ValidCharactersPatternConstraint { |
25 | 6 | protected boolean allowWhitespace = false; |
26 | 6 | protected boolean omitNewline = false; |
27 | ||
28 | /** | |
29 | * @return allowWhitespace | |
30 | */ | |
31 | public boolean getAllowWhitespace() { | |
32 | 0 | return allowWhitespace; |
33 | } | |
34 | ||
35 | /** | |
36 | * @param allowWhitespace | |
37 | */ | |
38 | public void setAllowWhitespace(boolean allowWhitespace) { | |
39 | 3 | this.allowWhitespace = allowWhitespace; |
40 | 3 | } |
41 | ||
42 | /** | |
43 | * @see org.kuali.rice.krad.datadictionary.validation.ValidationPattern#getRegexString() | |
44 | */ | |
45 | protected String getRegexString() { | |
46 | 3 | StringBuffer regexString = new StringBuffer("["); |
47 | ||
48 | 3 | regexString.append("\\x21-\\x7E"); |
49 | 3 | if (allowWhitespace) { |
50 | 1 | regexString.append("\\t\\v\\040"); |
51 | 1 | if (!omitNewline) { |
52 | 1 | regexString.append("\\f\\r\\n"); |
53 | } | |
54 | } | |
55 | ||
56 | 3 | regexString.append("]"); |
57 | ||
58 | 3 | return regexString.toString(); |
59 | } | |
60 | ||
61 | /** | |
62 | * @see org.kuali.rice.krad.datadictionary.validation.constraint.BaseConstraint#getLabelKey() | |
63 | */ | |
64 | @Override | |
65 | public String getLabelKey() { | |
66 | 2 | String labelKey = super.getLabelKey(); |
67 | 2 | if (StringUtils.isNotEmpty(labelKey)) { |
68 | 0 | return labelKey; |
69 | } | |
70 | 2 | if (!allowWhitespace) { |
71 | 2 | return UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "noWhitespace"; |
72 | } else { | |
73 | 0 | return UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "anyCharacterPattern"; |
74 | } | |
75 | } | |
76 | ||
77 | public boolean isOmitNewline() { | |
78 | 0 | return omitNewline; |
79 | } | |
80 | ||
81 | /** | |
82 | * When set to true, omit new line characters from the set of valid characters. This flag | |
83 | * will only have an effect if the allowWhitespace flag is true, otherwise all whitespace | |
84 | * including new lines characters are omitted. | |
85 | * @param omitNewline | |
86 | */ | |
87 | public void setOmitNewline(boolean omitNewline) { | |
88 | 0 | this.omitNewline = omitNewline; |
89 | 0 | } |
90 | } |