1 /**
2 * Copyright 2005-2013 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-bean", parent = "NumericPatternConstraint"),
31 @BeanTag(name = "numericWithOperators-bean", parent = "NumericWithOperators")})
32 public class NumericPatternConstraint extends AllowCharacterConstraint {
33
34 /**
35 * @see org.kuali.rice.krad.datadictionary.validation.ValidationPattern#getRegexString()
36 */
37 protected String getRegexString() {
38 StringBuilder regexString = new StringBuilder("[0-9");
39 regexString.append(this.getAllowedCharacterRegex());
40 regexString.append("]");
41
42 return regexString.toString();
43 }
44
45 /**
46 * @see org.kuali.rice.krad.datadictionary.validation.constraint.BaseConstraint#getMessageKey()
47 */
48 @Override
49 public String getMessageKey() {
50 String messageKey = super.getMessageKey();
51 if (StringUtils.isNotEmpty(messageKey)) {
52 return messageKey;
53 }
54
55 return UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "numericPattern";
56 }
57
58 }