01: /*
02: * Copyright 2006 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.core.datadictionary.mask;
17:
18: import org.apache.commons.lang.StringUtils;
19:
20: /**
21: * Mask a value using the specified char up to a given length.
22: *
23: *
24: */
25: public class MaskFormatterSubString implements MaskFormatter {
26: private String maskCharacter;
27: private int maskLength;
28:
29: public String maskValue(Object value) {
30: if (value == null) {
31: return null;
32: }
33:
34: if (maskCharacter == null) {
35: throw new RuntimeException(
36: "Mask character not specified. Check DD maskTo attribute.");
37: }
38:
39: String strValue = value.toString();
40: if (strValue.length() < maskLength) {
41: throw new RuntimeException(
42: "Data value length exceeds mask length defined in field authorization.");
43: }
44:
45: return StringUtils.repeat(maskCharacter, maskLength)
46: + strValue.substring(maskLength - 1);
47: }
48:
49: /**
50: * Gets the maskCharacter attribute.
51: *
52: * @return Returns the maskCharacter.
53: */
54: public String getMaskCharacter() {
55: return maskCharacter;
56: }
57:
58: /**
59: * Sets the maskCharacter attribute value.
60: *
61: * @param maskCharacter The maskCharacter to set.
62: */
63: public void setMaskCharacter(String maskCharacter) {
64: this .maskCharacter = maskCharacter;
65: }
66:
67: /**
68: * Gets the maskLength attribute.
69: *
70: * @return Returns the maskLength.
71: */
72: public int getMaskLength() {
73: return maskLength;
74: }
75:
76: /**
77: * Sets the maskLength attribute value.
78: *
79: * @param maskLength The maskLength to set.
80: */
81: public void setMaskLength(int maskLength) {
82: this.maskLength = maskLength;
83: }
84:
85: }
|