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.service.KRADServiceLocator;
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-bean", 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
71
72 @Override
73 public List<String> getValidationMessageParams() {
74 if (validationMessageParams == null) {
75 validationMessageParams = new ArrayList<String>();
76 ConfigurationService configService = KRADServiceLocator.getKualiConfigurationService();
77 if (allowNegative) {
78 validationMessageParams.add(configService.getPropertyValueAsString(
79 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "positiveOrNegative"));
80 } else {
81 validationMessageParams.add(configService.getPropertyValueAsString(
82 UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "positive"));
83 }
84 }
85 return validationMessageParams;
86 }
87 }