Reputation: 3524
XPages application uses "template" documents containing two fields binded to RichText editor and file upload/download controls. Regular documents initially link to template document, with one datasource for common fields (title, category, readers/authors...) of current document, and second datasource shows read only RT+attachments from template.
When user decides to alter RT/attachments, he unlinks document from template - by copying RT+attachments from template to current document.
The problem: standard Java snippet for RT copy (and attachments too) is:
session.setConvertMime(true);
RichTextItem rti = (RichTextItem)docTemplate.getFirstItem("Body");
rti.copyItemToDocument(docCurrent, "Body");
rti = (RichTextItem)docTemplate.getFirstItem("Files"); <====
rti.copyItemToDocument(docCurrent, "Files");
docCurrent.save(); //saves in RT format, next save via XPage converts to MIME
This always works for Body field (although it alters formatting a bit), but it rarely works for attachments. Resave of template document in Notes client converts RT from MIME to native RT format and code works without problem.
Not working means:
java.lang.ClassCastException: lotus.domino.local.Item incompatible with lotus.domino.RichTextItem
at line with arrow.LotusScript alternative of above code called as agent does not help either. Datasource property computeWithForm is not used by purpose.
Question: what is proper technique for copying MIME attachment(s) between documents?
Upvotes: 2
Views: 1427
Reputation: 868
The quickest way would be using Document.copyAllItems(Document doc, boolean replace) and than removing what is unnecessary.
Upvotes: 0