01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.core.datadictionary.validation.fieldlevel;
17:
18: import org.kuali.core.datadictionary.exporter.ExportMap;
19: import org.kuali.core.datadictionary.validation.FieldLevelValidationPattern;
20:
21: /**
22: * Validation pattern for matching floating point numbers, optionally matching negative numbers
23: *
24: *
25: */
26: public class FloatingPointValidationPattern extends
27: FieldLevelValidationPattern {
28: private boolean allowNegative;
29:
30: /**
31: * @return allowNegative
32: */
33: public boolean getAllowNegative() {
34: return allowNegative;
35: }
36:
37: /**
38: * @param allowNegative
39: */
40: public void setAllowNegative(boolean allowNegative) {
41: this .allowNegative = allowNegative;
42: }
43:
44: /**
45: * Adds special handling to account for optional allowNegative
46: *
47: * @see org.kuali.core.datadictionary.validation.ValidationPattern#getRegexString()
48: */
49: protected String getRegexString() {
50: StringBuffer regex = new StringBuffer();
51:
52: if (allowNegative) {
53: regex.append("-?");
54: }
55: regex.append(super .getRegexString());
56:
57: return regex.toString();
58: }
59:
60: /**
61: * @see org.kuali.core.datadictionary.validation.FieldLevelValidationPattern#getPatternTypeName()
62: */
63: protected String getPatternTypeName() {
64: return "floatingPoint";
65: }
66:
67: /**
68: * @see org.kuali.core.datadictionary.validation.ValidationPattern#buildExportMap(java.lang.String)
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: * @see org.kuali.core.datadictionary.validation.ValidationPattern#getPatternXml()
82: */
83: public String getPatternXml() {
84: StringBuffer xml = new StringBuffer("<floatingPoint ");
85: if (allowNegative) {
86: xml.append("allowNegative=\"true\" ");
87: }
88: xml.append("/>");
89:
90: return xml.toString();
91: }
92: }
|