View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
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.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   * Validation pattern for matching floating point numbers, optionally matching negative numbers
23   * 
24   * @deprecated Use {@link org.kuali.rice.krad.datadictionary.validation.constraint.FloatingPointPatternConstraint}.
25   */
26  @Deprecated
27  public class FloatingPointValidationPattern extends FieldLevelValidationPattern {
28      protected 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.rice.krad.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.rice.krad.datadictionary.validation.FieldLevelValidationPattern#getPatternTypeName()
62       */
63      protected String getPatternTypeName() {
64          return "floatingPoint";
65      }
66  
67  
68      /**
69       * @see org.kuali.rice.krad.datadictionary.validation.ValidationPattern#buildExportMap(java.lang.String)
70       */
71      public ExportMap buildExportMap(String exportKey) {
72          ExportMap exportMap = super.buildExportMap(exportKey);
73  
74          if (allowNegative) {
75              exportMap.set("allowNegative", "true");
76          }
77  
78          return exportMap;
79      }
80      
81  	/**
82  	 * @see org.kuali.rice.krad.datadictionary.validation.FieldLevelValidationPattern#getValidationErrorMessageKey()
83  	 */
84  	@Override
85  	public String getValidationErrorMessageKey() {
86  		StringBuilder buf = new StringBuilder();
87  		buf.append("error.format.").append(getClass().getName());
88  		if (allowNegative) {
89  			buf.append(".allowNegative");
90  		}
91  		return buf.toString();
92  	}
93  }