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.charlevel;
017
018import org.kuali.rice.krad.datadictionary.exporter.ExportMap;
019import org.kuali.rice.krad.datadictionary.validation.CharacterLevelValidationPattern;
020import org.kuali.rice.krad.util.KRADConstants;
021
022/**
023 * Pattern for matching alpha characters
024 * 
025 * @deprecated Use {@link org.kuali.rice.krad.datadictionary.validation.constraint.AlphaPatternConstraint}.
026 */
027@Deprecated
028public class AlphaValidationPattern extends CharacterLevelValidationPattern {
029    protected boolean allowWhitespace = false;
030
031
032    /**
033     * @return allowWhitespace
034     */
035    public boolean getAllowWhitespace() {
036        return allowWhitespace;
037    }
038
039    /**
040     * @param allowWhitespace
041     */
042    public void setAllowWhitespace(boolean allowWhitespace) {
043        this.allowWhitespace = allowWhitespace;
044    }
045
046
047    /**
048     * @see org.kuali.rice.krad.datadictionary.validation.ValidationPattern#getRegexString()
049     */
050    protected String getRegexString() {
051        StringBuffer regexString = new StringBuffer("[A-Za-z");
052
053        if (allowWhitespace) {
054            regexString.append("\\s");
055        }
056        regexString.append("]");
057
058        return regexString.toString();
059    }
060
061
062    /**
063     * @see org.kuali.rice.krad.datadictionary.validation.CharacterLevelValidationPattern#extendExportMap(org.kuali.bo.datadictionary.exporter.ExportMap)
064     */
065    public void extendExportMap(ExportMap exportMap) {
066        exportMap.set("type", "alpha");
067
068        if (allowWhitespace) {
069            exportMap.set("allowWhitespace", "true");
070        }
071    }
072
073        @Override
074        protected String getValidationErrorMessageKeyOptions() {
075                if (getAllowWhitespace()) {
076                        return ".allowWhitespace";
077                }
078                return KRADConstants.EMPTY_STRING;
079        }
080}