001/** 002 * Copyright 2005-2018 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.constraint; 017 018import org.apache.commons.lang.StringUtils; 019import org.kuali.rice.krad.datadictionary.parse.BeanTag; 020import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute; 021 022/** 023 * This abstract class extends from ValidCharactersConstraint. Its subclasses contain a regex that 024 * is built out with flags that can be turned off and on. All ValidCharactersPatternConstraints 025 * allow a certain set of characters to be repeated multiple times 026 * 027 * @author Kuali Rice Team (rice.collab@kuali.org) 028 */ 029@BeanTag(name = "validCharactersPatternContraint") 030public abstract class ValidCharactersPatternConstraint extends ValidCharactersConstraint { 031 /** 032 * Warning: This value should NOT be set on ValidCharactersPatternConstraints as the value is 033 * built dynamically from the flags set on the constraint - if this value IS set it will 034 * override any automatic generation and only use that which was set through this method for 035 * server side validation 036 * 037 * @see org.kuali.rice.krad.datadictionary.validation.constraint.ValidCharactersConstraint#setValue(java.lang.String) 038 */ 039 @Override 040 public void setValue(String value) { 041 super.setValue(value); 042 } 043 044 /** 045 * @see org.kuali.rice.krad.datadictionary.validation.constraint.ValidCharactersConstraint#getValue() 046 */ 047 @Override 048 @BeanTagAttribute(name = "value") 049 public String getValue() { 050 if (StringUtils.isEmpty(value)) { 051 return "^" + getRegexString() + "*$"; 052 } 053 return value; 054 055 } 056 057 /** 058 * This method returns a string representing a regex with characters to match, this string 059 * should not include the start(^) and end($) symbols or any length related symbols (*, {0,}, 060 * etc) 061 * 062 * @return regular expression 063 */ 064 abstract protected String getRegexString(); 065 066}