001/**
002 * Copyright 2005-2015 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.apache.commons.lang.StringUtils;
019import org.kuali.rice.krad.datadictionary.parse.BeanTag;
020import org.kuali.rice.krad.datadictionary.parse.BeanTags;
021import org.kuali.rice.krad.uif.UifConstants;
022
023/**
024 * Pattern for matching numeric characters, difference between NumericPatternConstraint and IntegerPatternConstraint
025 * is that a numeric pattern constraint is for matching numeric characters and can be mixed with other characters
026 * by setting allow flags on, while integer is for only positive/negative numbers
027 *
028 * @author Kuali Rice Team (rice.collab@kuali.org)
029 */
030@BeanTags({@BeanTag(name = "numericPatternConstraint-bean", parent = "NumericPatternConstraint"),
031        @BeanTag(name = "numericWithOperators-bean", parent = "NumericWithOperators")})
032public class NumericPatternConstraint extends AllowCharacterConstraint {
033
034    /**
035     * @see org.kuali.rice.krad.datadictionary.validation.ValidationPattern#getRegexString()
036     */
037    protected String getRegexString() {
038        StringBuilder regexString = new StringBuilder("[0-9");
039        regexString.append(this.getAllowedCharacterRegex());
040        regexString.append("]");
041
042        return regexString.toString();
043    }
044
045    /**
046     * @see org.kuali.rice.krad.datadictionary.validation.constraint.BaseConstraint#getMessageKey()
047     */
048    @Override
049    public String getMessageKey() {
050        String messageKey = super.getMessageKey();
051        if (StringUtils.isNotEmpty(messageKey)) {
052            return messageKey;
053        }
054
055        return UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "numericPattern";
056    }
057
058}