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