Coverage Report - org.kuali.rice.krad.datadictionary.validation.constraint.AlphaPatternConstraint
 
Classes in this File Line Coverage Branch Coverage Complexity
AlphaPatternConstraint
54%
12/22
37%
3/8
2
 
 1  
 /*
 2  
  * Copyright 2005-2008 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 java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import org.apache.commons.lang.StringUtils;
 22  
 import org.kuali.rice.core.api.config.property.ConfigurationService;
 23  
 import org.kuali.rice.krad.service.KRADServiceLocator;
 24  
 import org.kuali.rice.krad.uif.UifConstants;
 25  
 
 26  
 
 27  
 /**
 28  
  * Pattern for matching alpha characters
 29  
  * 
 30  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 31  
  */
 32  10
 public class AlphaPatternConstraint extends ValidCharactersPatternConstraint {
 33  10
     protected boolean allowWhitespace = false;
 34  
 
 35  
 
 36  
     /**
 37  
      * @return allowWhitespace
 38  
      */
 39  
     public boolean getAllowWhitespace() {
 40  0
         return allowWhitespace;
 41  
     }
 42  
 
 43  
     /**
 44  
      * @param allowWhitespace
 45  
      */
 46  
     public void setAllowWhitespace(boolean allowWhitespace) {
 47  5
         this.allowWhitespace = allowWhitespace;
 48  5
     }
 49  
 
 50  
 
 51  
     /**
 52  
      * @see org.kuali.rice.krad.datadictionary.validation.ValidationPattern#getRegexString()
 53  
      */
 54  
     protected String getRegexString() {
 55  5
         StringBuffer regexString = new StringBuffer("[A-Za-z");
 56  
 
 57  5
         if (allowWhitespace) {
 58  3
             regexString.append("\\s");
 59  
         }
 60  5
         regexString.append("]");
 61  
 
 62  5
         return regexString.toString();
 63  
     }
 64  
 
 65  
         /**
 66  
          * 
 67  
          * @see org.kuali.rice.krad.datadictionary.validation.constraint.BaseConstraint#getLabelKey()
 68  
          */
 69  
         @Override
 70  
         public String getLabelKey() {
 71  6
                 String labelKey = super.getLabelKey();
 72  6
                 if (StringUtils.isNotEmpty(labelKey)) {
 73  0
                         return labelKey;
 74  
                 }
 75  
                 
 76  6
                 return UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "alphaPattern";
 77  
         }
 78  
 
 79  
     /**
 80  
      * Parameters to be used in the string retrieved by this constraint's labelKey
 81  
      * @return the validationMessageParams
 82  
      */
 83  
     public List<String> getValidationMessageParams() {
 84  0
         if(validationMessageParams == null){
 85  0
             validationMessageParams = new ArrayList<String>();
 86  0
             ConfigurationService configService = KRADServiceLocator.getKualiConfigurationService();
 87  0
             StringBuilder paramString = new StringBuilder("");
 88  0
             if (getAllowWhitespace()) {
 89  0
                 paramString.append(", " + configService
 90  
                         .getPropertyValueAsString(UifConstants.Messages.VALIDATION_MSG_KEY_PREFIX + "whitespace"));
 91  
             }
 92  0
             validationMessageParams.add(paramString.toString());
 93  
         }
 94  0
         return this.validationMessageParams;
 95  
     }
 96  
 
 97  
 }