JAVA/CORBA CLASSES
Examples: getFirstItem method
1. This agent gets an item and a rich text item for all documents in a database.
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();
DocumentCollection dc = db.getAllDocuments();
Document doc = dc.getFirstDocument();
while (doc != null) {
Item subject = doc.getFirstItem("Subject");
if (subject == null)
System.out.println("[ No subject ]");
else
System.out.println("[ " +
subject.getText() + " ]");
RichTextItem body =
(RichTextItem)doc.getFirstItem("Body");
if (body == null)
System.out.println("No body");
else
System.out.println(
body.getFormattedText(true, 0, 0));
doc = dc.getNextDocument(); }
} catch(Exception e) {
e.printStackTrace();
}
}
}
2. This agent demonstrates the work-around for getting multiple items of the same name. This is a work-around and creating multiple items of the same name is not recommended.
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();
Item item = doc.getFirstItem("FooBar");
while(item != null) {
System.out.println(item.getName() + ": " + item.getText());
item.remove();
item = doc.getFirstItem("FooBar");
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
Véase también
getFirstItem method
Glosario
¿Desea opinar sobre la Ayuda?
Ayuda sobre la Ayuda
Abrir la Ayuda en pantalla completa
Glosario
¿Desea opinar sobre la Ayuda?
Ayuda sobre la Ayuda
Abrir la Ayuda en pantalla completa