Coverage Report - org.kuali.rice.kns.datadictionary.mask.MaskFormatterSubString
 
Classes in this File Line Coverage Branch Coverage Complexity
MaskFormatterSubString
0%
0/18
0%
0/8
2.6
 
 1  
 /*
 2  
  * Copyright 2006-2007 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.kns.datadictionary.mask;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 
 20  
 /**
 21  
   The maskTo element is to used hide the beginning part of the
 22  
   value for unauthorized users.  The number of leading characters
 23  
   to hide and the replacement character can be specified.
 24  
  */
 25  0
 public class MaskFormatterSubString implements MaskFormatter {
 26  0
     protected String maskCharacter = "*";
 27  
     protected int maskLength;
 28  
 
 29  
     public String maskValue(Object value) {
 30  0
         if (value == null) {
 31  0
             return null;
 32  
         }
 33  
 
 34  
         // TODO: MOVE TO UNIT TEST: move this validation into the unit tests
 35  0
         if (maskCharacter == null) {
 36  0
             throw new RuntimeException("Mask character not specified. Check DD maskTo attribute.");
 37  
         }
 38  
 
 39  0
         String strValue = value.toString();
 40  0
         if (strValue.length() < maskLength) {
 41  0
                 return StringUtils.repeat(maskCharacter, maskLength);
 42  
         }
 43  0
         if(maskLength >0){
 44  0
                 return StringUtils.repeat(maskCharacter, maskLength) + strValue.substring(maskLength);
 45  
         }else{
 46  0
                 return strValue;
 47  
         }
 48  
     }
 49  
 
 50  
     /**
 51  
      * Gets the maskCharacter attribute.
 52  
      * 
 53  
      * @return Returns the maskCharacter.
 54  
      */
 55  
     public String getMaskCharacter() {
 56  0
         return maskCharacter;
 57  
     }
 58  
 
 59  
     /**
 60  
      * Specify the character with which to mask the original value.
 61  
      *
 62  
      * @param maskCharacter for masking values
 63  
      */
 64  
     public void setMaskCharacter(String maskCharacter) {
 65  0
         this.maskCharacter = maskCharacter;
 66  0
     }
 67  
 
 68  
     /**
 69  
      * Gets the maskLength attribute.
 70  
      * 
 71  
      * @return Returns the maskLength.
 72  
      */
 73  
     public int getMaskLength() {
 74  0
         return maskLength;
 75  
     }
 76  
 
 77  
     /**
 78  
      * Set the number of characters to mask at the beginning of the string.
 79  
      * 
 80  
      * @param maskLength The maskLength to set.
 81  
      */
 82  
     public void setMaskLength(int maskLength) {
 83  0
         this.maskLength = maskLength;
 84  0
     }
 85  
 
 86  
 
 87  
 }