Dowload Document API Filenet
package createdoc_api;
import com.filenet.api.collection.ContentElementList;
import com.filenet.api.collection.DocumentSet;
import com.filenet.api.core.*;
import com.filenet.api.util.Id;
import java.util.Iterator;
import java.io.*;
public class BulkDownloading {
public static void main(String []args)
{
EngineConnection mine=new EngineConnection();
Connection connection= mine.giveConnection();
if(connection !=null)
{
Domain domain=Factory.Domain.fetchInstance(connection, null, null);
ObjectStore object_store=Factory.ObjectStore.fetchInstance(domain, "CMTOS", null);
System.out.println(""+object_store.get_DisplayName());
Folder folder=Factory.Folder.fetchInstance(object_store, "/Banking/New Account Opening", null);
System.out.println(""+folder.get_FolderName());
//get all documents from this folder now
DocumentSet document_set=folder.get_ContainedDocuments();
Document current_document=null;
FileOutputStream output_data=null;
InputStream input_data=null;
Document working_document=null;
ContentElementList content_element_list=null;
Iterator<DocumentSet>doc_iterator= document_set.iterator();
while(doc_iterator.hasNext())
{
current_document=(Document)doc_iterator.next();
//System.out.println(""+current_document.get_Name()+current_document.get_MimeType());
String mime=current_document.get_MimeType();
if(mime.startsWith("applica"))
{
mime="pdf";
}
try
{
System.out.println(" duong dan "+current_document.get_Id());
output_data = new FileOutputStream("C:\\data_sample\\"+current_document.get_Name());
System.out.println(" output_data "+ output_data);
working_document=Factory.Document.fetchInstance(object_store,current_document.get_Id(), null);
content_element_list=working_document.get_ContentElements();
//iterate through these
Iterator ite=content_element_list.iterator();
while(ite.hasNext())
{
ContentTransfer ct=(ContentTransfer)ite.next();
input_data=ct.accessContentStream();
int data_length=ct.get_ContentSize().intValue();
byte buff[]=new byte[data_length];
try
{
input_data.read(buff);
output_data.write(buff);
}
catch(Exception e)
{
System.out.println(""+e.getLocalizedMessage());
}
}
}
catch(Exception e)
{
System.out.println(""+e.getLocalizedMessage());
}
}
System.out.println("Operation completed");
}
}
}
Không có nhận xét nào:
Đăng nhận xét