Examples: addDocument method

This agent combines two document collections putting the result in the first collection.

Note: See merge for a simpler way to do this.
import lotus.domino.*;
public class JavaAgent extends AgentBase {
  public void NotesMain() {
    try {
      Session session = getSession();
      AgentContext agentContext = session.getAgentContext();
      // (Your code goes here) 
      Database db = agentContext.getCurrentDatabase();
      if (db.isFTIndexed()) db.updateFTIndex(false);
      else db.updateFTIndex(true);
      DocumentCollection dc1 = db.getAllDocuments();
      DocumentCollection dc2 = db.getAllDocuments();
      dc1.FTSearch("blue");
      dc2.FTSearch("red");
      Document tmpdoc;
      Document doc = dc2.getFirstDocument();
      while (doc != null) {
        // Make sure it's not already there before adding
        if (dc1.getDocument(doc) == null)
          dc1.addDocument(doc);
        tmpdoc = dc2.getNextDocument();
        doc.recycle();
        doc = tmpdoc;
      }
      doc = dc1.getFirstDocument();
      while (doc != null) {
        System.out.println(doc.getItemValueString("Subject"));
        tmpdoc = dc1.getNextDocument();
        doc.recycle();
        doc = tmpdoc;
      }
    } catch(NotesException e) {
      System.out.println(e.id + " " + e.text);
      e.printStackTrace();
    }
  }
}