View Javadoc
1   /**
2    * Copyright 2005-2015 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.BeanTags;
21  import org.kuali.rice.krad.uif.UifConstants;
22  
23  /**
24   * Pattern for matching numeric characters, difference between NumericPatternConstraint and IntegerPatternConstraint
25   * is that a numeric pattern constraint is for matching numeric characters and can be mixed with other characters
26   * by setting allow flags on, while integer is for only positive/negative numbers
27   *
28   * @author Kuali Rice Team (rice.collab@kuali.org)
29   */
30  @BeanTags({@BeanTag(name = "numericPatternConstraint", parent = "NumericPatternConstraint"),
31          @BeanTag(name = "numericWithOperators", parent = "NumericWithOperators")})
32  public class NumericPatternConstraint extends AllowCharacterConstraint {
33  
34      /**
35       * {@inheritDoc}
36       */
37      @Override
38      protected String getRegexString() {
39          StringBuilder regexString = new StringBuilder("[0-9");
40          regexString.append(this.getAllowedCharacterRegex());
41          regexString.append("]");
42  
43          return regexString.toString();
44      }
45  
46      /**
47       * @see org.kuali.rice.krad.datadictionary.validation.constraint.BaseConstraint#getMessageKey()
48       */
49      @Override
50      public String getMessageKey() {
51          String messageKey = super.getMessageKey();
52          if (StringUtils.isNotEmpty(messageKey)) {
53              return messageKey;
54          }
55  
56          return UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "numericPattern";
57      }
58  
59  }