/**
  * contains help doc
  *
  * @param helpDocId
  * @param resources
  * @return true if contained
  */
 private boolean containsHelpDoc(String helpDocId, Set resources) {
   boolean contains = false;
   if (resources != null) {
     for (Iterator i = resources.iterator(); i.hasNext(); ) {
       Resource resource = (Resource) i.next();
       if (resource.getDocId().equals(helpDocId)) {
         contains = true;
         break;
       }
     }
   }
   return contains;
 }
  /**
   * encode recursively
   *
   * @param writer
   * @param categories
   * @param helpDocId
   * @throws IOException
   */
  private void encodeRecursive(ResponseWriter writer, Set categories, String helpDocId)
      throws IOException {
    for (Iterator i = categories.iterator(); i.hasNext(); ) {
      Category category = (Category) i.next();

      Set resources = new TreeSet(category.getResources());
      String id = category.getName();

      writer.write("<li class=\"dir helpIndex\">");
      writer.write("<h1>");
      writer.write("<img src=\"../image/toc_closed.gif\" alt=\"\" /></td>");
      writer.write(
          "<a id=\""
              + id
              + "\" href=\"#"
              + category.getName()
              + "\" onclick=\"toggle(this)\">"
              + category.getName()
              + "</a></td>");
      writer.write("</h1>");

      writer.write("<ol class=\"docs\">");
      Set subCategories = new TreeSet(category.getCategories());
      encodeRecursive(writer, subCategories, helpDocId);
      if (resources != null) {
        for (Iterator j = resources.iterator(); j.hasNext(); ) {
          writer.write("<li>");
          Resource resource = (Resource) j.next();

          // helpDocId will be a helpDocId (coming from search) or
          // will be a tool id coming from portal
          if (helpDocId != null
              && (helpDocId.equals(resource.getDefaultForTool())
                  || helpDocId.equals(resource.getDocId()))) {
            writer.write("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td>");
            writer.write("<img src=\"../image/topic.gif\" alt=\"\"/></td>");
            writer.write(
                "<td><a id=\"default\""
                    + " href=\"content.hlp?docId="
                    + resource.getDocId()
                    + "\" target = \"content\">"
                    + resource.getName()
                    + "</a></td>");
            writer.write("</tr></table></li>\n");
          } else {
            writer.write("<h2>");
            writer.write("<img src=\"../image/topic.gif\" alt=\"\"/>");
            writer.write(
                "<a id=\""
                    + resource.getDocId()
                    + "\" href=\"content.hlp?docId="
                    + resource.getDocId()
                    + "\" target = \"content\">"
                    + resource.getName()
                    + "</a>");
            writer.write("</h2></li>\n");
          }
        }
      }
      writer.write("</ol></li>\n");
    }
  }