No replies
4672 Posts

Pinned topic Download attachments from table in Team Room document

‏2010-10-27T10:50:48Z |

I am working on a simple Lotus Notes tool which should download attachments from Team Room document and save them to folders in local PC's hard disk. Folder name consists of the content of first and third column separated by “_”. The attachments are placed in last column of the table.
I use Java / CORBA classes. I have a problem with going through table cells. The algorithm which you can see below works fine if the table doesn't contain any attachments. In case of the table contains attachments, the algorithm suddenly stop working at the beginning of 5th row in one test case or continue to next table in another test case. For simplification, I read only 2 attachments from the last column (I don't know how to do it a general way now - I have problems with proper function of findNextElement() method).

I would really appreciate any ideas and solution which would help to solve my problem.
Thank you very much for your comments.

//shows table elements plus attachments and store them to HDD System.out.println(
"-----------shows table elements------------"); 
//find body part of the document RichTextItem body = (RichTextItem)doc.getFirstItem(
//set navigator for body part RichTextNavigator bodynav = body.createNavigator(); 
//access to 8th table bodynav.findNthElement(RichTextItem.RTELEM_TYPE_TABLE, 8); 
//set body range RichTextRange bodyrange = body.createRange(); bodyrange.setBegin(bodynav); bodyrange.setEnd(bodynav); 
//set tab navigator RichTextNavigator tabnav = bodyrange.getNavigator(); tabnav.findFirstElement(RichTextItem.RTELEM_TYPE_TABLECELL); RichTextRange tabrange = body.createRange(); 
//set attachment navigator RichTextNavigator attachnav = tabrange.getNavigator(); 
//going through table cells 

int firstRun = 0; 

int columnCount = 0; StringBuffer directoryName = 

new StringBuffer(); EmbeddedObject attachment; 

boolean success; 

{ tabrange.setBegin(tabnav); tabrange.setEnd(tabnav); 
//creating directory name 

{ directoryName.append(tabrange.getTextParagraph()); directoryName.append(

{ directoryName.append(tabrange.getTextParagraph()); 
//display cell content System.out.println(tabrange.getTextParagraph()); 
//attachment searching 

if (tabrange.getTextParagraph().toString().equals(


if (firstRun==0) 
//create directory in c:\My_app_download success = (

new File(
"C:\\My_app_download\\" + directoryName.toString())).mkdir(); 

if (success) 
{ System.out.println(
"Directory: " + directoryName.toString() + 
" created"); 
} attachment = (EmbeddedObject)attachnav.getFirstElement(RichTextItem.RTELEM_TYPE_FILEATTACHMENT); System.out.println(attachment); 
//save attachment to particular folder attachment.extractFile(
"C:\\My_app_download\\" + directoryName.toString() + "\\
" + attachment.toString()); 

{ System.out.println((attachment = (EmbeddedObject)attachnav.getNextElement(RichTextItem.RTELEM_TYPE_FILEATTACHMENT)).toString()); attachment.extractFile(
"C:\\My_app_download\\" + directoryName.toString() + "\\
" + attachment.toString()); 
//temporary solution - max 2 attachment restriction 

if (firstRun==1) 

} firstRun++; 

while (firstRun > 0); firstRun = 0; 
} columnCount++; 
//row checking 

if (columnCount==6) 
{ columnCount=0; System.out.println(
"Jmeno adesare je: " + directoryName.toString()); 
//delete string buffer directoryName.delete(0, directoryName.length()); 

while (tabnav.findNextElement(RichTextItem.RTELEM_TYPE_TABLECELL));