1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.datadictionary.validation.fieldlevel;
17
18 import org.kuali.rice.krad.datadictionary.exporter.ExportMap;
19 import org.kuali.rice.krad.datadictionary.validation.FieldLevelValidationPattern;
20
21
22
23
24
25
26 public class FloatingPointValidationPattern extends FieldLevelValidationPattern {
27 protected boolean allowNegative;
28
29
30
31
32 public boolean getAllowNegative() {
33 return allowNegative;
34 }
35
36
37
38
39 public void setAllowNegative(boolean allowNegative) {
40 this.allowNegative = allowNegative;
41 }
42
43
44
45
46
47
48 protected String getRegexString() {
49 StringBuffer regex = new StringBuffer();
50
51 if (allowNegative) {
52 regex.append("-?");
53 }
54 regex.append(super.getRegexString());
55
56 return regex.toString();
57 }
58
59
60
61
62 protected String getPatternTypeName() {
63 return "floatingPoint";
64 }
65
66
67
68
69
70 public ExportMap buildExportMap(String exportKey) {
71 ExportMap exportMap = super.buildExportMap(exportKey);
72
73 if (allowNegative) {
74 exportMap.set("allowNegative", "true");
75 }
76
77 return exportMap;
78 }
79
80
81
82
83 @Override
84 public String getValidationErrorMessageKey() {
85 StringBuilder buf = new StringBuilder();
86 buf.append("error.format.").append(getClass().getName());
87 if (allowNegative) {
88 buf.append(".allowNegative");
89 }
90 return buf.toString();
91 }
92 }