001    /**
002     * Copyright 2005-2011 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 org.apache.commons.lang.StringUtils;
019    import org.kuali.rice.krad.service.KRADServiceLocator;
020    import org.kuali.rice.krad.uif.UifConstants;
021    
022    /**
023     * 
024     * @author Kuali Rice Team (rice.collab@kuali.org)
025     */
026    public class ConfigurationBasedRegexPatternConstraint extends ValidDataPatternConstraint {
027        /**
028         * the key used to identify the validation pattern
029         */
030        protected String patternTypeKey;
031        
032        /**
033         * the key used to identify the validation pattern
034         * 
035         * @return the patternTypeKey
036         */
037        public String getPatternTypeKey() {
038            return this.patternTypeKey;
039        }
040    
041        /**
042         * the key used to identify the validation pattern
043         * 
044         * @param patternTypeKey the patternTypeKey to set
045         */
046        public void setPatternTypeKey(String patternTypeKey) {
047            this.patternTypeKey = patternTypeKey;
048        }
049        
050        /**
051         * This overridden method ...
052         * 
053         * @see org.kuali.rice.krad.datadictionary.validation.constraint.BaseConstraint#getLabelKey()
054         */
055        @Override
056        public String getLabelKey() {
057            if(StringUtils.isNotEmpty(labelKey)){
058                return labelKey;
059            }
060            else{
061                StringBuilder buf = new StringBuilder();
062                buf.append(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX).append(getPatternTypeKey());
063                return buf.toString();
064            }
065        }
066        
067            /**
068             * This method implementation uses the key returned by {@link #getPatternTypePropertyString()} to fetch the 
069             * validationPattern's regex string from the ConfigurationService which should not include the start(^) and end($) symbols
070             */
071        protected String getRegexString() {
072    //        return (String) KRADServiceLocator.getKualiConfigurationService().getPropertyValueAsString("validationPatternRegex." + getPatternTypeName());
073            return (String) KRADServiceLocator.getKualiConfigurationService().getPropertyValueAsString(getPatternTypeKey());
074        }
075    
076    }