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", parent="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 @Override
52 protected String getRegexString() {
53 StringBuffer regexString = new StringBuffer("[");
54
55 regexString.append("\\x21-\\x7E");
56 if (allowWhitespace) {
57 regexString.append("\\t\\v\\040");
58 if (!omitNewline) {
59 regexString.append("\\f\\r\\n");
60 }
61 }
62
63 regexString.append("]");
64
65 return regexString.toString();
66 }
67
68
69
70
71 @Override
72 public String getMessageKey() {
73 String labelKey = super.getMessageKey();
74 if (StringUtils.isNotEmpty(labelKey)) {
75 return labelKey;
76 }
77
78 if (!allowWhitespace) {
79 return UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "anyCharacterPatternNoWhitespace";
80 } else {
81 return UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "anyCharacterPattern";
82 }
83 }
84
85 @BeanTagAttribute(name = "omitNewline")
86 public boolean isOmitNewline() {
87 return omitNewline;
88 }
89
90
91
92
93
94
95
96
97 public void setOmitNewline(boolean omitNewline) {
98 this.omitNewline = omitNewline;
99 }
100 }