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.krad.datadictionary.validation;
017
018import org.kuali.rice.krad.datadictionary.exporter.ExportMap;
019import org.kuali.rice.krad.service.KRADServiceLocator;
020
021import java.util.regex.Pattern;
022
023/**
024 * Abstraction of the regular expressions used to validate attribute values.
025 * 
026 * 
027 */
028@Deprecated
029abstract public class FieldLevelValidationPattern extends ValidationPattern {
030    protected Pattern regexPattern;
031    
032    /**
033     * Uses the key returned by getConfigurationRegexKey to fetch the validationPattern's regex string from the
034     * ConfigurationService
035     * 
036     * @see org.kuali.rice.krad.datadictionary.validation.ValidationPattern#getRegexString()
037     */
038    protected String getRegexString() {
039        return (String) KRADServiceLocator.getKualiConfigurationService().getPropertyValueAsString(
040                "validationPatternRegex." + getPatternTypeName());
041    }
042
043    /**
044     * @return the key used to retrieve the validationPattern's type name, which is used as the suffix of the regex property key, as
045     *         the type entry in the exportMap, etc.
046     */
047    abstract protected String getPatternTypeName();
048
049
050    /**
051     * @return regular expression Pattern generated using the individual ValidationPattern subclass
052     */
053    public final Pattern getRegexPattern() {
054        if ( regexPattern == null ) {
055            StringBuffer completeRegex = new StringBuffer("^");
056            completeRegex.append(getRegexString());
057            completeRegex.append("$");
058            regexPattern = Pattern.compile(completeRegex.toString()); 
059        }
060        return regexPattern; 
061    }
062
063
064    /**
065     * @see org.kuali.rice.krad.datadictionary.validation.ValidationPattern#buildExportMap(java.lang.String)
066     */
067    public ExportMap buildExportMap(String exportKey) {
068        ExportMap exportMap = new ExportMap(exportKey);
069
070        exportMap.set("type", getPatternTypeName());
071
072        return exportMap;
073    }
074    
075        /**
076         * This overridden method ...
077         * 
078         * @see org.kuali.rice.krad.datadictionary.validation.ValidationPattern#getValidationErrorMessageKey()
079         */
080        @Override
081        public String getValidationErrorMessageKey() {
082                StringBuilder buf = new StringBuilder();
083                buf.append("error.format.").append(getClass().getName());
084                return buf.toString();
085        }
086}