001/**
002 * Copyright 2005-2014 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", parent = "NumericPatternConstraint"),
031        @BeanTag(name = "numericWithOperators", parent = "NumericWithOperators")})
032public class NumericPatternConstraint extends AllowCharacterConstraint {
033
034    /**
035     * {@inheritDoc}
036     */
037    @Override
038    protected String getRegexString() {
039        StringBuilder regexString = new StringBuilder("[0-9");
040        regexString.append(this.getAllowedCharacterRegex());
041        regexString.append("]");
042
043        return regexString.toString();
044    }
045
046    /**
047     * @see org.kuali.rice.krad.datadictionary.validation.constraint.BaseConstraint#getMessageKey()
048     */
049    @Override
050    public String getMessageKey() {
051        String messageKey = super.getMessageKey();
052        if (StringUtils.isNotEmpty(messageKey)) {
053            return messageKey;
054        }
055
056        return UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "numericPattern";
057    }
058
059}