Examples: Working with attachments and embedded objects in Java™ classes
- This agent extracts the file attachments in the Body item of the
current document using NotesRichTextNavigator methods to get the attachments.
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(); if (doc.hasEmbedded()) { RichTextItem body = (RichTextItem)doc.getFirstItem("Body"); RichTextNavigator rtnav = body.createNavigator(); if (rtnav.findFirstElement( RichTextItem.RTELEM_TYPE_FILEATTACHMENT)) { do { EmbeddedObject att = (EmbeddedObject)rtnav.getElement(); String path = "c:\\Files\\" + att.getSource(); att.extractFile(path); System.out.println(path + " extracted"); } while (rtnav.findNextElement()); } else System.out.println("No attachments"); } else System.out.println("No attachments or embedded objects"); } catch(Exception e) { e.printStackTrace(); } } }
- This agent extracts the file attachments in the Body item of the
current document using the RichTextItem.EmbeddedObjects property to
get the attachments.
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(); if (doc.hasEmbedded()) { RichTextItem body = (RichTextItem)doc.getFirstItem("Body"); Vector atts = body.getEmbeddedObjects(); int n = 0; for (int i = 0; i < atts.size(); i++) { EmbeddedObject att = (EmbeddedObject)atts.elementAt(i); if (att.getType() == EmbeddedObject.EMBED_ATTACHMENT) { String path = "c:\\Files\\" + att.getSource(); att.extractFile(path); System.out.println(path + " extracted"); n++; } } if (n == 0) System.out.println("No attachments"); } else System.out.println("No attachments or embedded objects"); } catch(Exception e) { e.printStackTrace(); } } }
- This agent example displays properties of all the embedded objects
in a document.
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(); if (doc.hasEmbedded()) { RichTextItem body = (RichTextItem)doc.getFirstItem("Body"); Vector objects = body.getEmbeddedObjects(); for (int i = 0; i < objects.size(); i++) { EmbeddedObject object = (EmbeddedObject)objects.elementAt(i); System.out.println(object.getSource()); switch (object.getType()) { case EmbeddedObject.EMBED_ATTACHMENT: System.out.println("\tAttachment"); System.out.println("\t" + object.getFileSize() + " bytes"); break; case EmbeddedObject.EMBED_OBJECT: System.out.println("\tObject"); System.out.println("\tName: " + object.getName()); System.out.println("\tClass name: " + object.getClassName()); break; case EmbeddedObject.EMBED_OBJECTLINK: System.out.println("\tObject link"); System.out.println("\tName: " + object.getName()); System.out.println("\tClass name: " + object.getClassName()); break; } } } else System.out.println("No embedded objects"); } catch(Exception e) { e.printStackTrace(); } } }