java - Convert embedded pictures in database -


i have 'small' problem. in database documents contain richtextfield. richtextfield contains profile picture of contact. problem content not saved mime , therefore can not calculate url of image.

i'm using pojo retrieve data person profile , use in xpage control display contents. need build convert agent takes content of richtextitem , converts mime able calculate url like

http://host/database.nsf/($users)/d40fe4181f2b86ccc12579ab0047bd22/photo/m2?openelement 

could me converting contents of richtextitem mime? when check embedded objects in rt field there none. when content of field stream , save new richtext field using following code. new field not created somehow.

system.out.println("check if document contains field name "+fieldname);         if(!doc.hasitem(fieldname)){             throw new pictureconvertexception("could not locate richtextitem name"+fieldname);         }           richtextitem picturefield = (richtextitem) doc.getfirstitem(fieldname);          system.out.println("its richtextfield..");         system.out.println("copy field backup field");          if(doc.hasitem("old_"+fieldname)){              doc.removeitem("old_"+fieldname);          }           picturefield.copyitemtodocument(doc, "old_"+fieldname);       //      vector embeddedpictures = picturefield.getembeddedobjects(); //      system.out.println(doc.hasembedded()); //      system.out.println("retrieved embedded objects"); //      if(embeddedpictures.isempty()){ //          throw new pictureconvertexception("no embedded objects found."); //      } //         //      embeddedobject photo = (embeddedobject) embeddedpictures.get(0);         system.out.println("create inputstream");          //s.setconvertmime(false);         inputstream istream = picturefield.getinputstream();         system.out.println("create notesstream");         stream nstream = s.createstream();         nstream.setcontents(istream);          system.out.println("create mime entity");          mimeentity mentity = doc.createmimeentity("picturetest");         mimeheader cdheader = mentity.createheader("content-disposition");         system.out.println("set header withfilename picture.gif");          cdheader.setheaderval("attachment;filename=picture.gif");         system.out.println("setcontent type header");         mimeheader cidheader = mentity.createheader("content-id");         cidheader.setheaderval("picture.gif");         system.out.println("set content stream");         mentity.setcontentfrombytes(nstream, "application/gif", mentity.enc_identity_binary);         system.out.println("save document..");          doc.save();         //s.setconvertmime(true);           system.out.println("done");          // clean if done..          //doc.removeitem(fieldname); 

its been little while , didn't go down route of converting existing data mime. not work , after more research seemed unnecessary. because issue displaying images bound richtextbox did research on how compute url image , came 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 check if given rt field present. if case assumes few things:

  • if there files in rtfield first file picture display
  • else create specified url if item of type rt otherwhise assume mime entity , generate url.

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -