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.krad.datadictionary.parse.BeanTag;
19 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
20 import org.kuali.rice.krad.messages.MessageService;
21 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
22 import org.kuali.rice.krad.uif.UifConstants;
23
24 import java.util.ArrayList;
25 import java.util.List;
26
27
28
29
30
31
32 @BeanTag(name = "floatingPointPatternConstraint", parent = "FloatingPointPatternConstraint")
33 public class FloatingPointPatternConstraint extends ConfigurationBasedRegexPatternConstraint {
34
35 protected boolean allowNegative;
36
37
38
39
40 @Override
41 protected String getRegexString() {
42 StringBuffer regex = new StringBuffer();
43
44 if (isAllowNegative()) {
45 regex.append("-?");
46 }
47 regex.append(super.getRegexString());
48
49 return regex.toString();
50 }
51
52
53
54
55 @BeanTagAttribute(name = "allowNegative")
56 public boolean isAllowNegative() {
57 return this.allowNegative;
58 }
59
60
61
62
63 public void setAllowNegative(boolean allowNegative) {
64 this.allowNegative = allowNegative;
65 }
66
67
68
69
70 @Override
71 public List<String> getValidationMessageParams() {
72 if (validationMessageParams == null) {
73 validationMessageParams = new ArrayList<String>();
74 MessageService messageService = KRADServiceLocatorWeb.getMessageService();
75 if (allowNegative) {
76 validationMessageParams.add(messageService.getMessageText(
77 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "positiveOrNegative"));
78 } else {
79 validationMessageParams.add(messageService.getMessageText(
80 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "positive"));
81 }
82 }
83 return validationMessageParams;
84 }
85 }