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