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.kuali.rice.krad.datadictionary.parse.BeanTag;
019import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
020import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
021
022/**
023 * This is a constraint that limits attribute values to some subset of valid characters or to match a particular
024 * regular
025 * expression.
026 *
027 * For example:
028 * - To limit to both upper and lower-case letters, value can be set to "[A-Za-z]*"
029 * - To limit to any character except carriage returns and line feeds, value can be set to "[^\n\r]*"
030 *
031 * @author Kuali Rice Team (rice.collab@kuali.org)
032 */
033@BeanTag(name = "validCharactersConstraint", parent="ValidCharactersConstraint")
034public class ValidCharactersConstraint extends BaseConstraint {
035
036    protected String value;
037
038    /**
039     * The Java based regex for valid characters
040     * This value should include the ^ and $ symbols if needed
041     *
042     * @return the value
043     */
044    @BeanTagAttribute(name = "value")
045    public String getValue() {
046        return value;
047    }
048
049    /**
050     * @param value the value to set
051     */
052    public void setValue(String value) {
053        this.value = value;
054    }
055
056    /**
057     * Validates different requirements of component compiling a series of reports detailing information on errors
058     * found in the component.  Used by the RiceDictionaryValidator.
059     *
060     * @param tracer Record of component's location
061     */
062    @Override
063    public void completeValidation(ValidationTrace tracer) {
064        tracer.addBean("ValidCharacterConstraint", getMessageKey());
065
066        if (getValue() == null) {
067            String currentValues[] = {"getValue =" + getValue()};
068            tracer.createWarning("GetValue should return something", currentValues);
069        }
070
071        super.completeValidation(tracer.getCopy());
072    }
073}