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 java.util.ArrayList;
19 import java.util.List;
20
21 import org.kuali.rice.core.api.config.property.ConfigurationService;
22 import org.kuali.rice.krad.service.KRADServiceLocator;
23 import org.kuali.rice.krad.uif.UifConstants;
24
25
26
27
28
29
30 public class FixedPointPatternConstraint extends ValidDataPatternConstraint {
31
32 protected boolean allowNegative;
33 protected int precision;
34 protected int scale;
35
36
37
38
39
40
41 @Override
42 protected String getRegexString() {
43 StringBuilder regex = new StringBuilder();
44
45 if (isAllowNegative()) {
46 regex.append("-?");
47 }
48
49 regex.append("(");
50 regex.append("[0-9]{0," + (getPrecision() - getScale()) + "}");
51 regex.append("\\.");
52 regex.append("[0-9]{1," + getScale() + "}");
53 regex.append("|[0-9]{1," + (getPrecision() - getScale()) + "}");
54 regex.append(")");
55 return regex.toString();
56 }
57
58
59
60
61 public boolean isAllowNegative() {
62 return this.allowNegative;
63 }
64
65
66
67
68 public void setAllowNegative(boolean allowNegative) {
69 this.allowNegative = allowNegative;
70 }
71
72
73
74
75 public int getPrecision() {
76 return this.precision;
77 }
78
79
80
81
82 public void setPrecision(int precision) {
83 this.precision = precision;
84 }
85
86
87
88
89 public int getScale() {
90 return this.scale;
91 }
92
93
94
95
96 public void setScale(int scale) {
97 this.scale = scale;
98 }
99
100
101
102
103
104
105 @Override
106 public List<String> getValidationMessageParams() {
107 if(validationMessageParams == null){
108 validationMessageParams = new ArrayList<String>();
109 ConfigurationService configService = KRADServiceLocator.getKualiConfigurationService();
110 if (allowNegative) {
111 validationMessageParams.add(configService.getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX
112 + "positiveOrNegative"));
113 } else {
114 validationMessageParams.add(configService.getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX
115 + "positive"));
116 }
117
118 validationMessageParams.add(Integer.toString(precision));
119 validationMessageParams.add(Integer.toString(scale));
120 }
121 return validationMessageParams;
122 }
123
124 }