001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.kns.datadictionary.validation.fieldlevel;
017
018import org.kuali.rice.krad.datadictionary.exporter.ExportMap;
019import org.kuali.rice.krad.datadictionary.validation.FieldLevelValidationPattern;
020
021/**
022 * Validation pattern for matching floating point numbers, optionally matching negative numbers
023 * 
024 * @deprecated Use {@link org.kuali.rice.krad.datadictionary.validation.constraint.FloatingPointPatternConstraint}.
025 */
026@Deprecated
027public class FloatingPointValidationPattern extends FieldLevelValidationPattern {
028    protected boolean allowNegative;
029
030    /**
031     * @return allowNegative
032     */
033    public boolean getAllowNegative() {
034        return allowNegative;
035    }
036
037    /**
038     * @param allowNegative
039     */
040    public void setAllowNegative(boolean allowNegative) {
041        this.allowNegative = allowNegative;
042    }
043
044    /**
045     * Adds special handling to account for optional allowNegative
046     * 
047     * @see org.kuali.rice.krad.datadictionary.validation.ValidationPattern#getRegexString()
048     */
049    protected String getRegexString() {
050        StringBuffer regex = new StringBuffer();
051
052        if (allowNegative) {
053            regex.append("-?");
054        }
055        regex.append(super.getRegexString());
056
057        return regex.toString();
058    }
059
060    /**
061     * @see org.kuali.rice.krad.datadictionary.validation.FieldLevelValidationPattern#getPatternTypeName()
062     */
063    protected String getPatternTypeName() {
064        return "floatingPoint";
065    }
066
067
068    /**
069     * @see org.kuali.rice.krad.datadictionary.validation.ValidationPattern#buildExportMap(java.lang.String)
070     */
071    public ExportMap buildExportMap(String exportKey) {
072        ExportMap exportMap = super.buildExportMap(exportKey);
073
074        if (allowNegative) {
075            exportMap.set("allowNegative", "true");
076        }
077
078        return exportMap;
079    }
080    
081        /**
082         * @see org.kuali.rice.krad.datadictionary.validation.FieldLevelValidationPattern#getValidationErrorMessageKey()
083         */
084        @Override
085        public String getValidationErrorMessageKey() {
086                StringBuilder buf = new StringBuilder();
087                buf.append("error.format.").append(getClass().getName());
088                if (allowNegative) {
089                        buf.append(".allowNegative");
090                }
091                return buf.toString();
092        }
093}