KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > gui > control > Password


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.gui.control;
14
15 import info.magnolia.cms.core.Content;
16
17 import org.apache.commons.codec.binary.Base64;
18 import org.apache.commons.lang.StringUtils;
19
20
21 /**
22  * Password field.
23  * @author Vinzenz Wyser
24  * @version 2.0
25  */

26 public class Password extends ControlSuper {
27
28     public Password() {
29     }
30
31     public Password(String JavaDoc name, String JavaDoc value) {
32         super(name, value);
33     }
34
35     public Password(String JavaDoc name, Content websiteNode) {
36         super(name, websiteNode);
37     }
38
39     public String JavaDoc getHtml() {
40         StringBuffer JavaDoc html = new StringBuffer JavaDoc();
41         String JavaDoc value = StringUtils.EMPTY;
42         if (this.getEncoding() == ENCODING_BASE64) {
43             // show number of characters (using spaces)
44
String JavaDoc valueDecoded = new String JavaDoc(Base64.decodeBase64(this.getValue().getBytes()));
45
46             for (int i = 0; i < valueDecoded.length(); i++) {
47                 value += " "; //$NON-NLS-1$
48
}
49         }
50         else if (this.getEncoding() == ENCODING_UNIX) {
51             value = StringUtils.EMPTY;
52         }
53         else {
54             value = this.getValue();
55         }
56         html.append("<input type=\"password\""); //$NON-NLS-1$
57
html.append(" name=\"" + this.getName() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
58
html.append(" id=\"" + this.getName() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
59
html.append(" value=\"" + value + "\""); //$NON-NLS-1$ //$NON-NLS-2$
60
html.append(getHtmlEvents());
61         html.append(this.getHtmlCssClass());
62         html.append(this.getHtmlCssStyles());
63         html.append(" />"); //$NON-NLS-1$
64
if (this.getSaveInfo()) {
65             html.append(this.getHtmlSaveInfo());
66         }
67         return html.toString();
68     }
69 }
70
Popular Tags