package ants.servlets.taglib;

import java.io.IOException;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;

/**
 * Displays a boolean value as a tick/cross.
 */
public class BooleanTag extends TagSupport {

  private boolean value = false;
  private boolean showFalse = false;

  public int doStartTag() throws JspException {
    try {
      JspWriter out = pageContext.getOut();
      String statement = "";
      if (value) {
        statement= "<img border=\"0\" src=\"images/tick.gif\" alt=\"Y\" >";
      }
      else {
        if (showFalse) {
          statement = "<img border=\"0\" src=\"images/cross.gif\" alt=\"N\">";
        }
      }
      out.println(statement);
    } catch (IOException e) {
      throw new JspException("I/O exception " + e.getMessage());
    }
    return SKIP_BODY;
  }

  public void setValue(Boolean newValue) {
    value = newValue.booleanValue();
  }

  public Boolean isValue() {
    return new Boolean(value);
  }

  public void setShowFalse(boolean newShowFalse) {
    showFalse = newShowFalse;
  }

  public boolean isShowFalse() {
    return showFalse;
  }

}