Coverage Report - org.kuali.rice.kns.datadictionary.validation.constraint.AlphaNumericPatternConstraint
 
Classes in this File Line Coverage Branch Coverage Complexity
AlphaNumericPatternConstraint
0%
0/68
0%
0/30
1.941
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.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/ecl1.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.kns.datadictionary.validation.constraint;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 
 20  
 /**
 21  
  * A ValidCharactersConstraint based on AlphaNumericValidationPattern.
 22  
  * 
 23  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 24  
  */
 25  0
 public class AlphaNumericPatternConstraint extends ValidCharactersPatternConstraint{
 26  0
     protected boolean allowWhitespace = false;
 27  0
     protected boolean allowUnderscore = false;
 28  0
     protected boolean allowPeriod = false;
 29  0
     protected boolean allowParenthesis = false;
 30  0
     protected boolean allowDollar = false;
 31  0
     protected boolean allowForwardSlash = false;
 32  0
     protected boolean lowerCase = false;
 33  
     
 34  
     /**
 35  
      * A label key is auto generated for this bean if none is set.  This generated message can be overridden
 36  
      * through setLabelKey, but the generated message should cover most cases.
 37  
      * 
 38  
      * @see org.kuali.rice.kns.datadictionary.validation.constraint.BaseConstraint#getLabelKey()
 39  
      */
 40  
     @Override
 41  
     public String getLabelKey() {
 42  0
             if(StringUtils.isEmpty(labelKey)){
 43  0
                     StringBuilder key = new StringBuilder("");
 44  0
                     if(lowerCase){
 45  0
                             key.append("alphanumericPatternLowerCase,");
 46  
                     }
 47  
                     else{
 48  0
                             key.append("alphanumericPattern,");
 49  
                     }
 50  0
                 if (allowWhitespace) {
 51  0
                         key.append("whitespace,");
 52  
                 }
 53  0
                 if (allowUnderscore) {
 54  0
                     key.append("underscore,");
 55  
                 }
 56  0
                 if (allowPeriod) {
 57  0
                     key.append("period,");
 58  
                 }
 59  0
                 if(allowParenthesis) {
 60  0
                         key.append("parenthesis,");
 61  
                 }
 62  0
                 if(allowDollar) {
 63  0
                         key.append("dollar,");
 64  
                 }
 65  0
                 if(allowForwardSlash) {
 66  0
                         key.append("forwardSlash");
 67  
                 }
 68  
                 
 69  0
                     return key.toString();
 70  
             }
 71  0
             return labelKey;
 72  
     }
 73  
     
 74  
     /**
 75  
      * The labelKey should only be set if the auto generated message by this class needs to be overridden
 76  
      * @see org.kuali.rice.kns.datadictionary.validation.constraint.BaseConstraint#setLabelKey(java.lang.String)
 77  
      */
 78  
     @Override
 79  
     public void setLabelKey(String labelKey) {
 80  0
             super.setLabelKey(labelKey);
 81  0
     }
 82  
     
 83  
         /**
 84  
          * @see org.kuali.rice.kns.datadictionary.validation.constraint.ValidCharactersPatternConstraint#getRegexString()
 85  
          */
 86  
         @Override
 87  
         protected String getRegexString() {
 88  
                 //Exact same logic is used here as old KS AlphaNumericValidationPattern for server side value
 89  0
             StringBuilder regexString = new StringBuilder("[A-Za-z0-9");
 90  
             /*
 91  
              * This check must be first because we are removing the base 'A-Z' if lowerCase == true
 92  
              */
 93  0
             if(lowerCase){
 94  0
                     regexString = new StringBuilder("[a-z0-9");
 95  
             }
 96  
 
 97  0
         if (allowWhitespace) {
 98  0
             regexString.append("\\s");
 99  
         }
 100  0
         if (allowUnderscore) {
 101  0
             regexString.append("_");
 102  
         }
 103  0
         if (allowPeriod) {
 104  0
             regexString.append(".");
 105  
         }
 106  0
         if(allowParenthesis) {
 107  0
                 regexString.append("(");
 108  0
                 regexString.append(")");
 109  
         }
 110  0
         if(allowDollar) {
 111  0
                 regexString.append("$");
 112  
         }
 113  0
         if(allowForwardSlash) {
 114  0
                 regexString.append("/");
 115  
         }
 116  0
         regexString.append("]");
 117  
 
 118  0
         return regexString.toString();
 119  
         }
 120  
 
 121  
         /**
 122  
          * @return the allowWhitespace
 123  
          */
 124  
         public boolean isAllowWhitespace() {
 125  0
                 return this.allowWhitespace;
 126  
         }
 127  
         /**
 128  
          * @param allowWhitespace the allowWhitespace to set
 129  
          */
 130  
         public void setAllowWhitespace(boolean allowWhitespace) {
 131  0
                 this.allowWhitespace = allowWhitespace;
 132  0
         }
 133  
         /**
 134  
          * @return the allowUnderscore
 135  
          */
 136  
         public boolean isAllowUnderscore() {
 137  0
                 return this.allowUnderscore;
 138  
         }
 139  
         /**
 140  
          * @param allowUnderscore the allowUnderscore to set
 141  
          */
 142  
         public void setAllowUnderscore(boolean allowUnderscore) {
 143  0
                 this.allowUnderscore = allowUnderscore;
 144  0
         }
 145  
         /**
 146  
          * @return the allowPeriod
 147  
          */
 148  
         public boolean isAllowPeriod() {
 149  0
                 return this.allowPeriod;
 150  
         }
 151  
         /**
 152  
          * @param allowPeriod the allowPeriod to set
 153  
          */
 154  
         public void setAllowPeriod(boolean allowPeriod) {
 155  0
                 this.allowPeriod = allowPeriod;
 156  0
         }
 157  
         /**
 158  
          * @return the allowParenthesis
 159  
          */
 160  
         public boolean isAllowParenthesis() {
 161  0
                 return this.allowParenthesis;
 162  
         }
 163  
         /**
 164  
          * @param allowParenthesis the allowParenthesis to set
 165  
          */
 166  
         public void setAllowParenthesis(boolean allowParenthesis) {
 167  0
                 this.allowParenthesis = allowParenthesis;
 168  0
         }
 169  
         /**
 170  
          * @return the allowDollar
 171  
          */
 172  
         public boolean isAllowDollar() {
 173  0
                 return this.allowDollar;
 174  
         }
 175  
         /**
 176  
          * @param allowDollar the allowDollar to set
 177  
          */
 178  
         public void setAllowDollar(boolean allowDollar) {
 179  0
                 this.allowDollar = allowDollar;
 180  0
         }
 181  
         /**
 182  
          * @return the allowForwardSlash
 183  
          */
 184  
         public boolean isAllowForwardSlash() {
 185  0
                 return this.allowForwardSlash;
 186  
         }
 187  
         /**
 188  
          * @param allowForwardSlash the allowForwardSlash to set
 189  
          */
 190  
         public void setAllowForwardSlash(boolean allowForwardSlash) {
 191  0
                 this.allowForwardSlash = allowForwardSlash;
 192  0
         }
 193  
         /**
 194  
          * @return the lowerCase
 195  
          */
 196  
         public boolean isLowerCase() {
 197  0
                 return this.lowerCase;
 198  
         }
 199  
         /**
 200  
          * @param lowerCase the lowerCase to set
 201  
          */
 202  
         public void setLowerCase(boolean lowerCase) {
 203  0
                 this.lowerCase = lowerCase;
 204  0
         }
 205  
 
 206  
 
 207  
 
 208  
 }