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 = "utf8AnyCharacterPatternConstraint", parent = "UTF8AnyCharacterPatternConstraint")
29 public class UTF8AnyCharacterPatternConstraint 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("\\u0000-\\uFFFF");
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 messageKey = super.getMessageKey();
74 if (StringUtils.isNotEmpty(messageKey)) {
75 return messageKey;
76 }
77
78 if (!allowWhitespace) {
79 return UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "noWhitespace";
80 } else {
81 return UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "utf8AnyCharacterPattern";
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 }