Beispiel zur Verwendung der Attachments API

Beispiel 7.22. Laden von Attachments

Das Beispiel zeigt, wie Attachments eines Documents 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;
}

[jadice document platform Version 5.6.10.6: Dokumentation für Entwickler. Veröffentlicht: 2024-01-18]