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:
- exception
java.lang.ClassCastException: lotus.domino.local.Item incompatible with lotus.domino.RichTextItem
at line with arrow. - missing Files field (Body is created correctly tho) For some attachments code seem to work (text file), for bigger or binary it fails (23k .doc, 3M .pdf).
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?