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 org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21 import org.kuali.rice.krad.uif.UifConstants;
22
23
24
25
26
27
28 @BeanTag(name = "anyCharacterPatternConstraint")
29 public class AnyCharacterPatternConstraint extends ValidCharactersPatternConstraint {
30 protected boolean allowWhitespace = false;
31 protected boolean omitNewline = false;
32
33
34
35
36 @BeanTagAttribute(name = "allowWhitespace")
37 public boolean getAllowWhitespace() {
38 return allowWhitespace;
39 }
40
41
42
43
44 public void setAllowWhitespace(boolean allowWhitespace) {
45 this.allowWhitespace = allowWhitespace;
46 }
47
48
49
50
51 protected String getRegexString() {
52 StringBuffer regexString = new StringBuffer("[");
53
54 regexString.append("\\x21-\\x7E");
55 if (allowWhitespace) {
56 regexString.append("\\t\\v\\040");
57 if (!omitNewline) {
58 regexString.append("\\f\\r\\n");
59 }
60 }
61
62 regexString.append("]");
63
64 return regexString.toString();
65 }
66
67
68
69
70 @Override
71 public String getMessageKey() {
72 String labelKey = super.getMessageKey();
73 if (StringUtils.isNotEmpty(labelKey)) {
74 return labelKey;
75 }
76
77 if (!allowWhitespace) {
78 return UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "noWhitespace";
79 } else {
80 return UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "anyCharacterPattern";
81 }
82 }
83
84 @BeanTagAttribute(name = "omitNewline")
85 public boolean isOmitNewline() {
86 return omitNewline;
87 }
88
89
90
91
92
93
94
95
96 public void setOmitNewline(boolean omitNewline) {
97 this.omitNewline = omitNewline;
98 }
99 }