
// Copyright (c) 1999, 2000 Oracle Corporation
package oracle.jbo.html.jsp.datatags;

import oracle.jbo.html.jsp.datatags.*;
import javax.servlet.jsp.tagext.*;
import oracle.jdeveloper.html.*;
import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;
import javax.servlet.*;
import oracle.jbo.*;

/**
 * A Class class.
 * <P>
 * @author Juan Oropeza
 */
public class InputPasswordTag extends InputTagBase {

  /**
   * Constructor
   */
  public InputPasswordTag() {
  }

  public HTMLFieldRenderer getFieldRenderer()
   {
      return new PasswordField();
   }

   /**
     * Process the start tag for this instance.
     *
     * The doStartTag() method assumes that all setter methods have been
     * invoked before.
     *
     * When this method is invoked, the body has not yet been invoked.
     *
     * @returns EVAL_BODY_INCLUDE if the tag wants to process body, SKIP_BODY if it
     * does ont want to process it.
     */
   public int doStartTag() throws JspException
   {
         try
         {
               internalInitialize();
               
               String sOutput = rndObj.renderToString(ctx, rs, row , sDataItem);

               pageContext.getOut().print(sOutput);
         }
         catch(Exception ex)
         {
            throw new JspException(ex.getMessage());
         }
         return Tag.SKIP_BODY;
   }
}

class PasswordField extends HTMLFieldRendererImpl
{
  public PasswordField()
  {
  }

  /**
   *	Adds a textarea text field with a target number of rows.
   *
   *	@param	sLabel		The label for the field.
   *	@param	sName		The field name.
   *	@param	sValue		The field value.
   *	@param	rows		Number of rows
   */
   public String createPasswordField(String sName , String sValue)
   {
      String sText;

      if(this.getDisplayWidth() <= 0)
      {
         this.setDisplayWidth(20);
      }

      sText = "<INPUT TYPE=\"PASSWORD\" NAME=\""+ sName + " COLS=\"" + this.getDisplayWidth() +"\" VALUE=\"" + sValue + "\"/>";

      return sText;
  }

  public String renderToString(HTMLRenderingContext ctx , RowSet rs, Row row , String sAttribute)
   {
      String sText;

      Object obj = row.getAttribute(sAttribute);

      if(obj == null)
      {
         sText = createPasswordField(sAttribute , "&nbsp;");
      }
      else
      {
         sText = createPasswordField(sAttribute , obj.toString());
      }
      return sText;
   }
}
