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