1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.datadictionary.mask;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.krad.datadictionary.parse.BeanTag;
20 import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
21
22
23
24
25
26
27
28
29 @BeanTag(name = "maskFormatteSubString-bean")
30 public class MaskFormatterSubString implements MaskFormatter {
31 private static final long serialVersionUID = -876112522775686636L;
32
33 protected String maskCharacter = "*";
34 protected int maskLength;
35
36 public String maskValue(Object value) {
37 if (value == null) {
38 return null;
39 }
40
41
42 if (maskCharacter == null) {
43 throw new RuntimeException("Mask character not specified. Check DD maskTo attribute.");
44 }
45
46 String strValue = value.toString();
47 if (strValue.length() < maskLength) {
48 return StringUtils.repeat(maskCharacter, maskLength);
49 }
50 if (maskLength > 0) {
51 return StringUtils.repeat(maskCharacter, maskLength) + strValue.substring(maskLength);
52 } else {
53 return strValue;
54 }
55 }
56
57
58
59
60
61
62 @BeanTagAttribute(name = "maskCharacter")
63 public String getMaskCharacter() {
64 return maskCharacter;
65 }
66
67
68
69
70
71
72 public void setMaskCharacter(String maskCharacter) {
73 this.maskCharacter = maskCharacter;
74 }
75
76
77
78
79
80
81 @BeanTagAttribute(name = "maskLength")
82 public int getMaskLength() {
83 return maskLength;
84 }
85
86
87
88
89
90
91 public void setMaskLength(int maskLength) {
92 this.maskLength = maskLength;
93 }
94
95 }