Examples: createNavigator method

This agent displays the number of elements of each type in the Body item of the selected document.

import lotus.domino.*;

public class JavaAgent extends AgentBase {

  public void NotesMain() {

    try {
      Session session = getSession();
      AgentContext agentContext = session.getAgentContext();

      // (Your code goes here) 
      // Open file - proceed only if file can be opened
      String filename = "c:\\lotus\\notesv6\\notes.ini";
      Stream stream = session.createStream();
      DocumentCollection dc = agentContext.getUnprocessedDocuments();
      Document doc = dc.getFirstDocument();
      RichTextItem rti = (RichTextItem)doc.getFirstItem("Body");
      RichTextNavigator rtnav = rti.createNavigator();
      System.out.println("Number of doc links = " +
        getCount(RichTextItem.RTELEM_TYPE_DOCLINK, rtnav));
      System.out.println("Number of file attachments = " +
        getCount(RichTextItem.RTELEM_TYPE_FILEATTACHMENT, rtnav));
      System.out.println("Number of OLE objects = " +
        getCount(RichTextItem.RTELEM_TYPE_OLE, rtnav));
      System.out.println("Number of sections = " +
        getCount(RichTextItem.RTELEM_TYPE_SECTION, rtnav));
      System.out.println("Number of tables = " +
        getCount(RichTextItem.RTELEM_TYPE_TABLE, rtnav));
      System.out.println("Number of  table cells = " +
        getCount(RichTextItem.RTELEM_TYPE_TABLECELL, rtnav));
      System.out.println("Number of text paragraphs = " +
        getCount(RichTextItem.RTELEM_TYPE_TEXTPARAGRAPH, rtnav));
      System.out.println("Number of text runs = " +
        getCount(RichTextItem.RTELEM_TYPE_TEXTRUN, rtnav));

    } catch(Exception e) {
      e.printStackTrace();
    }
  }
  
  int getCount(int elementType, RichTextNavigator rtnav) {
    int n = 0;
    try {
      if (rtnav.findFirstElement(elementType)) {
        do {
          n++; }
        while (rtnav.findNextElement(elementType));
      }
    } catch(Exception e) {
      e.printStackTrace(); }
    return n;
  }
  
}