Convert embedded pictures in database

不打扰是莪最后的温柔 提交于 2019-12-03 16:47:42

Its been a little while now and I didn't go down the route of converting existing data to mime. I could not get it to work and after some more research it seemed to be unnecessary. Because the issue is about displaying images bound to a richtextbox I did some research on how to compute the url for an image and I came up with the following lines of code:

function getImageURL(doc:NotesDocument, strRTItem,strFileType){
    if(doc!=null && !"".equals(strRTItem)){
        var rtItem = doc.getFirstItem(strRTItem);
        if(rtItem!=null){
            var personelDB = doc.getParentDatabase();
            var dbURL = getDBUrl(personelDB);
            var imageURL:java.lang.StringBuffer = new java.lang.StringBuffer(dbURL);

            if("file".equals(strFileType)){
                var embeddedObjects:java.util.Vector = rtItem.getEmbeddedObjects();
                if(!embeddedObjects.isEmpty()){
                    var file:NotesEmbeddedObject = embeddedObjects.get(0); 

                    imageURL.append("(lookupView)\\");
                    imageURL.append(doc.getUniversalID());
                    imageURL.append("\\$File\\");
                    imageURL.append(file.getName());
                    imageURL.append("?Open");

                }
            }else{              
                imageURL.append(doc.getUniversalID());
                imageURL.append("/"+strRTItem+"/");
                if(rtItem instanceof lotus.domino.local.RichTextItem){
                    imageURL.append("0.C4?OpenElement");
                }else{
                    imageURL.append("M2?OpenElement");
                }
            }
            return imageURL.toString()
        }
    }
}

It will check if a given RT field is present. If this is the case it assumes a few things:

  • If there are files in the rtfield the first file is the picture to display
  • else it will create a specified url if the item is of type Rt otherwhise it will assume it is a mime entity and will generate another url.

Not sure if this is an answer but I can't seem to add comments yet. Have you verified that there is something in your stream?

if (stream.getBytes() != 0) {

The issue cannot be resolved "ideally" in Java.

1) if you convert to MIME, you screw up the original Notes rich text. MIME allows only for sad approximation of original content; this might or might not matter.

If it matters, it's possible to convert a copy of the original field to MIME used only for display purposes, or scrape it out using DXL and storing separately - however this approach again means an issue of synchronization every time somebody changes the image in the original RT item.

2) computing URL as per OP code in the accepted self-answer is not possible in general as the constant 0.C4 in this example relates to the offset of the image in binary data of the RT item. Meaning any other design of rich text field, manually entered images, created by different version of Notes - all influence the offset.

3) the url can be computed correctly only by using C API that allows to investigate binary data in rich text item. This cannot be done from Java. IMO (without building JNI bridges etc)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!