Wrap lotus.domino.Document as a DominoDocument, including MIME and RichText

/*
 * Wraps a lotus.domino.Document as a com.ibx.xsp.model.domino.wrapped.DominoDocument, including a RichText item
 *
 * @param doc document to be wrapped
 *
 * @param richTextItemName name of the rich text item containing standard RichText or MIME  contents that need to be wrapped
 */
private static DominoDocument wrapDocument(final Document doc, final String richTextItemName) throws NotesException {</code>
 
  DominoDocument wrappedDoc = null;
 
  Database db = doc.getParentDatabase();
 
  //disable MIME to RichText conversion
  db.getParent().setConvertMIME(false);
 
  //wrap the lotus.domino.Document as a lotus.domino.DominoDocument
  //see http://public.dhe.ibm.com/software/dw/lotus/Domino-Designer/JavaDocs/DesignerAPIs/com/ibm/xsp/model/domino/wrapped/DominoDocument.html
  wrappedDoc = DominoDocument.wrap(doc.getParentDatabase().getFilePath(), doc, null, null, false, null, null);
 
  //see http://public.dhe.ibm.com/software/dw/lotus/Domino-Designer/JavaDocs/DesignerAPIs/com/ibm/xsp/model/domino/wrapped/DominoRichTextItem.html
  DominoRichTextItem drti = null;
 
  Item itemRT = doc.getFirstItem(richTextItemName);
 
  if (null != itemRT) {
 
    if (itemRT.getType() == Item.RICHTEXT) {
 
      //create a DominoRichTextItem from the RichTextItem
      RichTextItem rt = (RichTextItem) itemRT;
      drti = new DominoRichTextItem(wrappedDoc, rt);
 
    } else if (itemRT.getType() == Item.MIME_PART) {
 
      //create a DominoRichTextItem from the Rich Text item that contains MIME
      MIMEEntity rtAsMime = doc.getMIMEEntity(richTextItemName);
      drti = new DominoRichTextItem(wrappedDoc, rtAsMime, richTextItemName);
 
    }
  }
 
  wrappedDoc.setRichTextItem(richTextItemName, drti);
 
  return wrappedDoc;
 
}





Use this function to 'wrap' a document as a DominoDocument, allowing you to easily access the HTML from a rich text field for example. See also http://linqed.eu/?p=487 and http://linqed.eu/?p=500

Java
Mark Leusink
July 3, 2014 8:38 AM
Rating
188

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.



No comments yetLogin first to comment...