View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.datadictionary.validation.constraint;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21  
22  /**
23   * @author Kuali Rice Team (rice.collab@kuali.org)
24   */
25  @BeanTag(name = "validDataPatternConstraint-bean")
26  public abstract class ValidDataPatternConstraint extends ValidCharactersConstraint {
27  
28      /**
29       * Warning: This value should NOT be set on this class as the value is built dynamically from the
30       * flags set on the constraint - if this value IS set it will override any automatic generation and only
31       * use that which was set through this method for server side validation
32       *
33       * @see org.kuali.rice.krad.datadictionary.validation.constraint.ValidCharactersConstraint#setValue(java.lang.String)
34       */
35      @Override
36      public void setValue(String value) {
37          super.setValue(value);
38      }
39  
40      /**
41       * @see org.kuali.rice.krad.datadictionary.validation.constraint.ValidCharactersConstraint#getValue()
42       */
43      @Override
44      @BeanTagAttribute(name = "value")
45      public String getValue() {
46          if (StringUtils.isEmpty(value)) {
47              return "^" + getRegexString() + "$";
48          }
49          return value;
50  
51      }
52  
53      /**
54       * This method returns a string representing a regex with characters to match, this string should not
55       * include the start(^) and end($) symbols
56       */
57      abstract protected String getRegexString();
58  
59  }