001    /*
002     * Copyright 2005-2008 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.krad.datadictionary.validation.constraint;
017    
018    import java.util.ArrayList;
019    import java.util.List;
020    
021    import org.apache.commons.lang.StringUtils;
022    import org.kuali.rice.core.api.config.property.ConfigurationService;
023    import org.kuali.rice.krad.service.KRADServiceLocator;
024    import org.kuali.rice.krad.uif.UifConstants;
025    
026    
027    /**
028     * Pattern for matching alpha characters
029     * 
030     * @author Kuali Rice Team (rice.collab@kuali.org)
031     */
032    public class AlphaPatternConstraint extends AllowCharacterConstraint {
033        protected boolean lowerCase = false;
034        
035        /**
036         * @see org.kuali.rice.krad.datadictionary.validation.ValidationPattern#getRegexString()
037         */
038        protected String getRegexString() {
039            StringBuilder regexString = new StringBuilder("[A-Za-z");
040            /*
041             * This check must be first because we are removing the base 'A-Z' if lowerCase == true
042             */
043            if (lowerCase) {
044                regexString = new StringBuilder("[a-z");
045            }
046            regexString.append(this.getAllowedCharacterRegex());
047            regexString.append("]");
048    
049            return regexString.toString();
050        }
051    
052        /**
053         * A label key is auto generated for this bean if none is set. This generated message can be
054         * overridden through setLabelKey, but the generated message should cover most cases.
055         * 
056         * @see org.kuali.rice.krad.datadictionary.validation.constraint.BaseConstraint#getLabelKey()
057         */
058        @Override
059        public String getLabelKey() {
060            if (StringUtils.isEmpty(labelKey)) {
061                StringBuilder key = new StringBuilder("");
062                if (lowerCase) {
063                    return (UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "alphaPatternLowerCase");
064                } else {
065                    return (UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "alphaPattern");
066                }
067            }
068            return labelKey;
069        }
070            
071        /**
072         * @return the lowerCase
073         */
074        public boolean isLowerCase() {
075            return this.lowerCase;
076        }
077    
078        /**
079         * @param lowerCase the lowerCase to set
080         */
081        public void setLowerCase(boolean lowerCase) {
082            this.lowerCase = lowerCase;
083        }
084    
085    }