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.kuali.rice.core.api.config.property.ConfigurationService;
19 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21 import org.kuali.rice.krad.messages.MessageService;
22 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
23 import org.kuali.rice.krad.uif.UifConstants;
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28
29
30
31
32
33 @BeanTag(name = "integerPatternConstraint-bean", parent = "IntegerPatternConstraint")
34 public class IntegerPatternConstraint extends ValidDataPatternConstraint {
35 protected boolean allowNegative;
36 protected boolean onlyNegative;
37 protected boolean omitZero;
38
39
40
41
42 @Override
43 protected String getRegexString() {
44 StringBuffer regex = new StringBuffer();
45
46 if (isAllowNegative() && !onlyNegative) {
47 regex.append("((-?");
48 } else if (onlyNegative) {
49 regex.append("((-");
50 } else {
51 regex.append("((");
52 }
53 if (omitZero) {
54 regex.append("[1-9][0-9]*))");
55 } else {
56 regex.append("[1-9][0-9]*)|[0]*)");
57 }
58
59 return regex.toString();
60 }
61
62
63
64
65 @BeanTagAttribute(name = "allowNegative")
66 public boolean isAllowNegative() {
67 return this.allowNegative;
68 }
69
70
71
72
73 public void setAllowNegative(boolean allowNegative) {
74 this.allowNegative = allowNegative;
75 }
76
77 @BeanTagAttribute(name = "onlyNegative")
78 public boolean isOnlyNegative() {
79 return onlyNegative;
80 }
81
82
83
84
85
86
87 public void setOnlyNegative(boolean onlyNegative) {
88 this.onlyNegative = onlyNegative;
89 }
90
91 @BeanTagAttribute(name = "omitZero")
92 public boolean isOmitZero() {
93 return omitZero;
94 }
95
96
97
98
99
100
101 public void setOmitZero(boolean omitZero) {
102 this.omitZero = omitZero;
103 }
104
105
106
107
108
109
110 @Override
111 public List<String> getValidationMessageParams() {
112 if (validationMessageParams == null) {
113 validationMessageParams = new ArrayList<String>();
114
115 MessageService messageService = KRADServiceLocatorWeb.getMessageService();
116 if (allowNegative && !onlyNegative) {
117 if (omitZero) {
118 validationMessageParams.add(messageService.getMessageText(
119 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "positiveOrNegative"));
120 } else {
121 validationMessageParams.add(messageService.getMessageText(
122 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "positiveOrNegativeOrZero"));
123 }
124 } else if (onlyNegative) {
125 if (omitZero) {
126 validationMessageParams.add(messageService.getMessageText(
127 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "negative"));
128 } else {
129 validationMessageParams.add(messageService.getMessageText(
130 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "negativeOrZero"));
131 }
132 } else {
133 if (omitZero) {
134 validationMessageParams.add(messageService.getMessageText(
135 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "positive"));
136 } else {
137 validationMessageParams.add(messageService.getMessageText(
138 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "positiveOrZero"));
139 }
140 }
141 }
142 return validationMessageParams;
143 }
144 }