001 /* 002 Copyright (C) 2001-2003 Laurent Martelli <laurent@aopsys.com> 003 004 This program is free software; you can redistribute it and/or modify 005 it under the terms of the GNU Lesser General Public License as 006 published by the Free Software Foundation; either version 2 of the 007 License, or (at your option) any later version. 008 009 This program is distributed in the hope that it will be useful, but 010 WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 Lesser General Public License for more details. 013 014 You should have received a copy of the GNU Lesser General Public 015 License along with this program; if not, write to the Free Software 016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 017 USA */ 018 019 package org.objectweb.jac.aspects.gui.web; 020 021 import java.io.PrintWriter; 022 import org.objectweb.jac.core.rtti.FieldItem; 023 import org.objectweb.jac.core.rtti.NamingConventions; 024 import org.objectweb.jac.util.Strings; 025 026 027 /** 028 * HTML editor for password types (int, long, float, double, short) and String 029 * 030 */ 031 public class PasswordFieldEditor extends AbstractFieldEditor 032 implements HTMLEditor 033 { 034 035 public PasswordFieldEditor(Object substance, FieldItem field) { 036 super(substance,field); 037 width = 15; 038 } 039 040 // HTMLEditor interface 041 042 public void genHTML(PrintWriter out) { 043 out.println("<INPUT type=\"password\" class=\"editor\""+ 044 " name=\""+label+"\""+ 045 " style=\"width:"+width+"ex\""+"\""); 046 printAttributes(out); 047 out.println(">"); 048 out.println("<BR>"); 049 out.print("<div class=\"label\">Retype " + 050 NamingConventions.textForName(field.getName()) + 051 ": </div>"); 052 out.println("<INPUT type=\"password\" class=\"editor\""+ 053 " name=\""+label+"Confirm"+"\""+ 054 " style=\"width:"+width+"ex\""+"\""); 055 printAttributes(out); 056 out.println(">"); 057 } 058 059 protected boolean doReadValue(Object parameter) 060 throws RuntimeException 061 { 062 String string = (String)parameter; 063 064 if (!((String) (WebDisplay.getRequest() 065 .getParameter(label+"Confirm"))).equals(string)) { 066 throw new RuntimeException ("'" + 067 NamingConventions.textForName(field.getName()) + 068 "'" + 069 " and its confirmation are different"); 070 } else { 071 if (Strings.isEmpty(string)) { 072 return false; 073 } 074 setValue(string); 075 } 076 return true; 077 } 078 } 079