Examples: clone method (RichTextRange - Java)

This agent gets the first paragraph in the Body item of the current document in a created range, then gets the second paragraph in a cloned range.

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();
      RichTextRange rtrange = body.createRange();
      if (rtnav.findFirstElement(
      RichTextItem.RTELEM_TYPE_TEXTPARAGRAPH)) {
        rtrange.setBegin(rtnav);
        if (rtnav.findNextElement(
        RichTextItem.RTELEM_TYPE_TEXTPARAGRAPH)) {
          RichTextRange rtrange2 = rtrange.Clone();
          rtrange2.setBegin(rtnav);
          // Print first 2 paragraphs
          System.out.println(rtrange.getTextParagraph());
          System.out.println(rtrange2.getTextParagraph());
        }
        else
          System.out.println("Body does not have a second paragraph");
      }
      else
        System.out.println("Body does not contain any text");

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