例: remove method (NoteCollection - Java™)

次のエージェントは現在のデータベース内の文書を使用して、文書コレクションをビルドします。件名にテキスト「example」が含まれる文書をすべて削除し、修正されたコレクションを DXL としてエクスポートします。

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();
      
      // Open DXL file named after current database
      Stream stream = session.createStream();
      String filename = "c:¥¥dxl¥¥";
      filename = filename + db.getFileName();
      filename = filename.substring(0, filename.length() - 3) + "dxl";
      if (stream.open(filename)) {
        System.out.println("Opened " + filename);
        stream.truncate();
        
        // Create note collection of all agents
        NoteCollection nc = db.createNoteCollection(false);
        nc.setSelectDocuments(true);
        nc.buildCollection();
        
        if (nc.getCount() > 0) {
          // Remove documents whose Subject contains "example"
          String id = nc.getFirstNoteID();
          while (id.length() > 0) {
            String idZap = id;
            // Get next doc before zapping current
            id = nc.getNextNoteID(id);
            Document doc = db.getDocumentByID(idZap);
            String subject = doc.getItemValueString("Subject");
            if (subject.toLowerCase().indexOf("example") >= 0)
              nc.remove(idZap);
          }

          // Export note collection as DXL
          if (nc.getCount() > 0) {
            DxlExporter exporter = session.createDxlExporter();
            String output = exporter.exportDxl(nc);
            stream.writeText(output);
            stream.close();
            System.out.println(nc.getCount() + " notes exported");
          }
          else
            System.out.println("No notes exported");
        }
        else
          System.out.println("No agents in database");
      }
      else {
        System.out.println("Cannot open " + filename);
      }

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