KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > web > PasswordFieldEditor


1 /*
2   Copyright (C) 2001-2003 Laurent Martelli <laurent@aopsys.com>
3   
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful, but
10   WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17   USA */

18
19 package org.objectweb.jac.aspects.gui.web;
20
21 import java.io.PrintWriter JavaDoc;
22 import org.objectweb.jac.aspects.gui.Length;
23 import org.objectweb.jac.core.rtti.FieldItem;
24 import org.objectweb.jac.core.rtti.NamingConventions;
25 import org.objectweb.jac.util.Strings;
26
27
28 /**
29  * HTML editor for password types (int, long, float, double, short) and String
30  *
31  */

32 public class PasswordFieldEditor extends AbstractFieldEditor
33     implements HTMLEditor
34 {
35
36     public PasswordFieldEditor(Object JavaDoc substance, FieldItem field) {
37         super(substance,field);
38         width = new Length("15ex");
39     }
40
41     // HTMLEditor interface
42

43     public void genHTML(PrintWriter JavaDoc out) {
44         out.println("<INPUT type=\"password\" class=\"editor\""+
45                     " name=\""+label+"\""+sizeSpec());
46         printAttributes(out);
47         out.println(">");
48         out.println("<BR>");
49         out.print("<div class=\"label\">Retype " +
50                   NamingConventions.textForName(field.getName()) +
51                   ": </div>");
52         out.println("<INPUT type=\"password\" class=\"editor\""+
53                     " name=\""+label+"Confirm"+"\"");
54         printAttributes(out);
55         out.println(">");
56     }
57
58     protected boolean doReadValue(Object JavaDoc parameter)
59         throws RuntimeException JavaDoc
60     {
61         String JavaDoc string = (String JavaDoc)parameter;
62       
63         if (!((String JavaDoc) (WebDisplay.getRequest()
64                         .getParameter(label+"Confirm"))).equals(string)) {
65             throw new RuntimeException JavaDoc ("'" +
66                                         NamingConventions.textForName(field.getName()) +
67                                         "'" +
68                                         " and its confirmation are different");
69         } else {
70             if (Strings.isEmpty(string)) {
71                 return false;
72             }
73             setValue(string);
74         }
75         return true;
76     }
77 }
78
79
Popular Tags