Debian Codegraph @

src/com/jidesoft/converter/PasswordConverter.java

raw
1 /*
2 * @(#)PasswordConverter.java 7/30/2005
3 *
4 * Copyright 2002 - 2005 JIDE Software Inc. All rights reserved.
5 */
6 package com.jidesoft.converter;
7
8 import java.util.Arrays;
9
10
11 /**
12 * Converter which converts String to String and converts it back.
13 */
14 public class PasswordConverter extends DefaultObjectConverter {
15 /**
16 * ConverterContext if the String is a file name.
17 */
18 public static ConverterContext CONTEXT = new ConverterContext("Password");
19 private char _echoChar = '*';
20
21 public PasswordConverter() {
22 }
23
24 /**
25 * Creates a PasswordConverter.
26 *
27 * @param echoChar The echo char. It is used to replace the real password so that other people can't see what user is typing.
28 */
29 public PasswordConverter(char echoChar) {
30 _echoChar = echoChar;
31 }
32
33 @Override
34 public String toString(Object object, ConverterContext context) {
35 if (object instanceof char[]) {
36 int length = ((char[]) object).length;
37 char[] chars = new char[length];
38 Arrays.fill(chars, getEchoChar());
39 return new String(chars);
40 }
41 else if (object != null) {
42 int length = object.toString().length();
43 char[] chars = new char[length];
44 Arrays.fill(chars, getEchoChar());
45 return new String(chars);
46 }
47 else {
48 return "";
49 }
50 }
51
52 public char getEchoChar() {
53 return _echoChar;
54 }
55
56 public void setEchoChar(char echoChar) {
57 _echoChar = echoChar;
58 }
59
60 @Override
61 public boolean supportFromString(String string, ConverterContext context) {
62 return false;
63 }
64
65 @Override
66 public Object fromString(String string, ConverterContext context) {
67 return null;
68 }
69 }