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