Examples: getNthElement method

This agent displays in reverse order the file path of the target database of all the doclinks in the Body item of the current or first 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) 
      DocumentCollection dc = agentContext.getUnprocessedDocuments();
      Document doc = dc.getFirstDocument();
      RichTextItem body = (RichTextItem)doc.getFirstItem("Body");
      RichTextNavigator rtnav = body.createNavigator();
      if (rtnav.findFirstElement(RichTextItem.RTELEM_TYPE_DOCLINK)) {
        int count = 0;
        do {
          count++;
        } while (rtnav.findNextElement());
        for (int i = count; i > 0; i--) {
          RichTextDoclink rtlink = (RichTextDoclink)rtnav.getNthElement(
          RichTextItem.RTELEM_TYPE_DOCLINK, i);
          DbDirectory dbdir = session.getDbDirectory("");
          Database db = dbdir.openDatabaseByReplicaID(
            rtlink.getDBReplicaID());
          if (db.isOpen())
            System.out.println(i + ") " + db.getFilePath());
          else
            System.out.println("No local replica");
          db.recycle();
        }
      }
      else
        System.out.println("No doclinks in Body");
      
      /*
      
      if (rtlink != null) {
        rtlink = (RichTextDoclink)rtnav.getNextElement();
      }
      */

    } catch(Exception e) {
      e.printStackTrace();
    }
  }
}