01: /*
02: ItsNat Java Web Application Framework
03: Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
04: Author: Jose Maria Arranz Santamaria
05:
06: This program is free software: you can redistribute it and/or modify
07: it under the terms of the GNU Affero General Public License as published by
08: the Free Software Foundation, either version 3 of the License, or
09: (at your option) any later version. See the GNU Affero General Public
10: License for more details. See the copy of the GNU Affero General Public License
11: included in this program. If not, see <http://www.gnu.org/licenses/>.
12: */
13: package org.itsnat.impl.comp.html;
14:
15: import org.itsnat.comp.html.ItsNatHTMLInputPassword;
16: import org.itsnat.core.ItsNatException;
17: import javax.swing.text.BadLocationException;
18: import javax.swing.text.Document;
19: import javax.swing.text.Segment;
20: import org.itsnat.core.NameValue;
21: import org.w3c.dom.html.HTMLInputElement;
22:
23: /**
24: *
25: * @author jmarranz
26: */
27: public class ItsNatHTMLInputPasswordImpl extends
28: ItsNatHTMLInputTextBasedImpl implements ItsNatHTMLInputPassword {
29:
30: /**
31: * Creates a new instance of ItsNatHTMLInputPasswordImpl
32: */
33: public ItsNatHTMLInputPasswordImpl(HTMLInputElement element,
34: NameValue[] artifacts,
35: ItsNatHTMLComponentManagerImpl componentMgr) {
36: super (element, artifacts, componentMgr);
37:
38: init();
39: }
40:
41: public String getExpectedType() {
42: return "password";
43: }
44:
45: public char[] getPassword() {
46: // Igual que en JPasswordField, la verdad es que no entiendo bien por qué no usa el getText normal
47: Document doc = getDocument();
48: Segment txt = new Segment();
49: try {
50: doc.getText(0, doc.getLength(), txt);
51: } catch (BadLocationException ex) {
52: throw new ItsNatException(ex);
53: }
54: char[] retValue = new char[txt.count];
55: System.arraycopy(txt.array, txt.offset, retValue, 0, txt.count);
56: return retValue;
57: }
58:
59: }
|