次のエージェントは、現在の文書の Body アイテム内での最初の (または唯一の) 文書リンクで使用されている参照先ビューの名前を表示します。
import lotus.domino.*;
import java.util.Vector;
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)) {
String idzero = new String("00000000000000000000000000000000");
RichTextDoclink rtlink = (RichTextDoclink)rtnav.getElement();
String viewunid = rtlink.getViewUnID();
if (!viewunid.equals(idzero)) {
DbDirectory dbdir = session.getDbDirectory(rtlink.getServerHint());
Database db = dbdir.openDatabaseByReplicaID(
rtlink.getDBReplicaID());
if (db.isOpen()) {
Vector views = db.getViews();
View view = null;
for (int i = 0; i < views.size(); i++) {
view = (View)views.elementAt(i);
if (view.getUniversalID().equals(rtlink.getViewUnID())) {
System.out.println(view.getName());
break;
}
}
}
else
System.out.println("Cannot open database");
}
else
System.out.println("Link does not have view component");
}
else
System.out.println("No doclinks in Body");
} catch(Exception e) {
e.printStackTrace();
}
}
}