Beispiel 7.22. Laden von Attachment
s
Das Beispiel zeigt, wie Attachment
s eines Document
s als weitere
Instanzen von Document
geladen werden. Die so entstandenen Dokumente könnten
dem Nutzer beispielsweise in einer Liste präsentiert oder in einem PageView
angezeigt werden.
public void loadAttachments(InputStream documentInputStream) throws JadiceException, IOException { Document doc = readDocument(documentInputStream); Collection<Attachment> attachments = Attachments.getDefaultLayerAttachments(doc); for (Attachment a : attachments) { InputStream attachedStream = Attachments.createDefaultStream(a); Document attachedDocument = readDocument(attachedStream); // Set the document name based on the attachment's description (if present) // It is also possible to use the attachment name or ID instead, for example. String description = (String) a.getProperties().get(Attachment.PROPERTY_KEY_ATTACHMENT_DESCRIPTION); if (description != null && !description.isEmpty()) { attachedDocument.setName(description); } // present attachedDocument to the user … } } private Document readDocument(InputStream documentInputStream) throws JadiceException, IOException { Reader reader = new Reader(); reader.read(documentInputStream); reader.complete(); Document doc = reader.getDocument(); return doc; }