001/**
002 * Copyright 2005-2016 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.uif.UifConstants;
020
021import javax.xml.bind.annotation.XmlAccessType;
022import javax.xml.bind.annotation.XmlAccessorType;
023
024/**
025 * Pattern for matching numeric characters, difference between NumericPatternConstraint and IntegerPatternConstraint
026 * is that a numeric pattern constraint is for matching numeric characters and can be mixed with other characters
027 * by setting allow flags on, while integer is for only positive/negative numbers
028 * 
029 * 
030 */
031@XmlAccessorType(XmlAccessType.FIELD)
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     * This overridden method ...
047     * 
048     * @see org.kuali.rice.krad.datadictionary.validation.constraint.BaseConstraint#getLabelKey()
049     */
050    @Override
051    public String getLabelKey() {
052        String labelKey = super.getLabelKey();
053        if (StringUtils.isNotEmpty(labelKey)) {
054            return labelKey;
055        }
056        return UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "numericPattern";
057    }
058
059}