View Javadoc

1   /**
2    * Copyright 2005-2011 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  
20  /**
21   * This abstract class extends from ValidCharactersConstraint. Its subclasses contain a regex that
22   * is built out with flags that can be turned off and on. All ValidCharactersPatternConstraints
23   * allow a certain set of characters to be repeated multiple times
24   * @author Kuali Rice Team (rice.collab@kuali.org)
25   */
26  public abstract class ValidCharactersPatternConstraint extends ValidCharactersConstraint {
27      /**
28       * Warning: This value should NOT be set on ValidCharactersPatternConstraints as the value is
29       * built dynamically from the flags set on the constraint - if this value IS set it will
30       * override any automatic generation and only use that which was set through this method for
31       * 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      public String getValue() {
45          if (StringUtils.isEmpty(value)) {
46              return "^" + getRegexString() + "*$";
47          }
48          return value;
49  
50      }
51  
52      /**
53       * This method returns a string representing a regex with characters to match, this string
54       * should not include the start(^) and end($) symbols or any length related symbols (*, {0,},
55       * etc)
56       * 
57       * @return
58       */
59      abstract protected String getRegexString();
60  
61  }