001    // Copyright (c) 2001 Hursh Jain (http://www.mollypages.org) 
002    // The Molly framework is freely distributable under the terms of an
003    // MIT-style license. For details, see the molly pages web site at:
004    // http://www.mollypages.org/. Use, modify, have fun !
005    
006    package fc.web.forms;
007    
008    import javax.servlet.*;
009    import javax.servlet.http.*;
010    import java.io.*;
011    import java.util.*;
012    
013    import fc.jdbc.*;
014    import fc.io.*;
015    import fc.util.*;
016    
017    /**
018    Encapsulates a password field.
019    */
020    public final class Password extends MaxSizable
021    {
022    boolean remember = false;
023    
024    /** 
025    Creates a new password element with the initial value set to
026    an empty string. 
027    **/
028    public Password(String name)
029      {
030      this(name, "");
031      }
032      
033    /** 
034    Creates a new password element with the specified initial
035    value. Note, in most cases the intial value should be and
036    will be an empty string. If the specified value is
037    <tt>null</tt>, then the initial value is set to "" (the
038    empty string).
039    **/
040    public Password(String name, String initialValue)
041      {
042      super(name, initialValue);
043      }
044      
045    public Field.Type getType() {
046      return Field.Type.PASSWORD;
047      }
048    
049    public void renderImpl(FormData fd, Writer writer) throws IOException 
050      {
051      String value = getRenderValue(fd);
052        
053      writer.write("<input type='");
054      writer.write(getType().toString());
055    
056      writer.write("' name='");
057      writer.write(name);
058      writer.write("'");  
059    
060      if (value != null) {
061        writer.write("' value='");
062        writer.write(value);
063        writer.write("'"); 
064        }
065        
066      if (! enabled || ! isEnabled(fd)) {
067        writer.write(" disabled");
068        }
069    
070      if (size > 0) {
071        writer.write(" size='");
072        writer.write(String.valueOf(size));
073        writer.write("'"); 
074        }
075        
076      if (maxlen > 0) {
077        writer.write(" maxlength='");
078        writer.write(String.valueOf(maxlen));
079        writer.write("'"); 
080        }
081        
082      if (renderStyleTag) {
083        writer.write(" style='");
084        writer.write(styleTag);
085        writer.write("'");
086        }
087        
088      final int arlen = arbitraryString.size();
089      for (int n = 0; n < arlen; n++) {
090        writer.write(" ");
091        writer.write(arbitraryString.get(n).toString());
092        }
093    
094      writer.write("</input>");
095      }
096                    
097    }          //~class Password