/**
   * Perform the action of the plugin.
   *
   * @param document the current document.
   */
  public boolean perform(Document document) throws IOException {
    // Interact with the user to get the layer tag/

    Tag layerTag = getLayerTagFromUser(document);
    if (layerTag == null) return false; // User cancled.
    Tag endTag = new Tag(layerTag.getName(), false);
    // Get the output stream to hold the new document text.
    PrintWriter out = new PrintWriter(document.getOutput());
    // Create a lexical stream to tokenize the old document text.
    LexicalStream in = new LexicalStream(new SelectedHTMLReader(document.getInput(), out));
    for (; ; ) {
      // Get the next token of the document.
      Token token = in.next();
      if (token == null) break; //  Null means we've finished the document.
      else if (token instanceof Comment) {
        Comment comment = (Comment) token;
        if (comment.isSelectionStart()) {
          out.print(layerTag);
        } else if (comment.isSelectionEnd()) {
          out.print(comment);
          out.print(endTag);
          continue; // So comment isn't printed twice.
        }
      }
      out.print(token);
    }
    out.close();
    return true;
  }
  void insertButton(Document document, PrintWriter out) {
    String fileName = "netnow3.gif";
    String imgURLString =
        "http://home.netscape.com/comprod/products/navigator/version_3.0/images/" + fileName;

    writeImageToDisk(document, imgURLString, fileName);

    try {
      // Write the HTML for the button
      Tag anchor = new Tag("A");
      anchor.addAttribute("HREF", "http://www.netscape.com");
      Tag anchorEnd = new Tag("A", false);
      Tag img = new Tag("IMG");
      URL imgURL = new URL(document.getWorkDirectoryURL(), fileName);
      img.addAttribute("SRC", imgURL.toString());
      out.print(anchor);
      out.print(img);
      out.print(anchorEnd);
    } catch (Throwable t) {
      t.printStackTrace();
    }
  }