Note:
Here Document Ids are presented in Xlsx file.
EngineConnection.java
package docdown;
import com.filenet.api.core.*;
import com.filenet.api.util.UserContext;
import javax.security.auth.Subject;
public class EngineConnection {
Connection giveConnection()
{
String url="http://192.168.1.134:9080/wsi/FNCEWS40MTOM";
Connection connection = Factory.Connection.getConnection(url);
Subject subject =UserContext.createSubject(connection, "p8admin", "filenet@12", null);
UserContext context=UserContext.get();
context.pushSubject(subject);
if(connection!=null)
return connection;
return connection;
}
}
DocumentDownloader.java
package docdown;
import com.filenet.api.collection.ContentElementList;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import com.filenet.api.core.*;
import com.filenet.api.util.Id;
import java.io.FileOutputStream;
public class DocumentDownloader {
public static void main(String args[])
{
try {
double currentId;
String curr;
ArrayList ids=new ArrayList();
InputStream input = new BufferedInputStream( new FileInputStream("D:\\excel\\filenet_id.xls"));
POIFSFileSystem fs = new POIFSFileSystem( input );
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
Iterator rows = sheet.rowIterator();
while( rows.hasNext() ) {
HSSFRow row = (HSSFRow) rows.next();
System.out.println("\n");
Iterator cells = row.cellIterator();
while( cells.hasNext() ) {
HSSFCell cell = (HSSFCell) cells.next();
if(HSSFCell.CELL_TYPE_NUMERIC==cell.getCellType()) {
currentId= cell.getNumericCellValue();
ids.add(currentId);
}
else if(HSSFCell.CELL_TYPE_STRING==cell.getCellType()) {
curr= cell.getStringCellValue();
ids.add(curr);
}
else
System.out.print("Unknown cell type");
}
}
System.out.println(""+ids);
EngineConnection connection=new EngineConnection();
Connection final_connection=connection.giveConnection();
Domain domain=null;
ObjectStore os=null;
Document doc1=null;
FileOutputStream output_data=null;
InputStream input_data=null;
ContentElementList content_element_list=null;
if(final_connection!=null)
{
domain=Factory.Domain.fetchInstance(final_connection, null, null);
os=Factory.ObjectStore.fetchInstance(domain, "CMTOS", null);
System.out.println(""+os.get_Name());
for(int index=0;index<ids.size();index++)
{
doc1=Factory.Document.fetchInstance(os,new Id(""+ids.get(index)+""), null);
output_data = new FileOutputStream("d:\\sample\\"+doc1.get_Name());
content_element_list=doc1.get_ContentElements();
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());
}
}
System.out.println("file copied is "+ids.get(index));
}
}
}
catch(Exception e)
{
System.out.println(""+e.getLocalizedMessage());
}
}
}
output:
here output is set of documents stored on local file path.
Here Document Ids are presented in Xlsx file.
EngineConnection.java
package docdown;
import com.filenet.api.core.*;
import com.filenet.api.util.UserContext;
import javax.security.auth.Subject;
public class EngineConnection {
Connection giveConnection()
{
String url="http://192.168.1.134:9080/wsi/FNCEWS40MTOM";
Connection connection = Factory.Connection.getConnection(url);
Subject subject =UserContext.createSubject(connection, "p8admin", "filenet@12", null);
UserContext context=UserContext.get();
context.pushSubject(subject);
if(connection!=null)
return connection;
return connection;
}
}
DocumentDownloader.java
package docdown;
import com.filenet.api.collection.ContentElementList;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import com.filenet.api.core.*;
import com.filenet.api.util.Id;
import java.io.FileOutputStream;
public class DocumentDownloader {
public static void main(String args[])
{
try {
double currentId;
String curr;
ArrayList ids=new ArrayList();
InputStream input = new BufferedInputStream( new FileInputStream("D:\\excel\\filenet_id.xls"));
POIFSFileSystem fs = new POIFSFileSystem( input );
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
Iterator rows = sheet.rowIterator();
while( rows.hasNext() ) {
HSSFRow row = (HSSFRow) rows.next();
System.out.println("\n");
Iterator cells = row.cellIterator();
while( cells.hasNext() ) {
HSSFCell cell = (HSSFCell) cells.next();
if(HSSFCell.CELL_TYPE_NUMERIC==cell.getCellType()) {
currentId= cell.getNumericCellValue();
ids.add(currentId);
}
else if(HSSFCell.CELL_TYPE_STRING==cell.getCellType()) {
curr= cell.getStringCellValue();
ids.add(curr);
}
else
System.out.print("Unknown cell type");
}
}
System.out.println(""+ids);
EngineConnection connection=new EngineConnection();
Connection final_connection=connection.giveConnection();
Domain domain=null;
ObjectStore os=null;
Document doc1=null;
FileOutputStream output_data=null;
InputStream input_data=null;
ContentElementList content_element_list=null;
if(final_connection!=null)
{
domain=Factory.Domain.fetchInstance(final_connection, null, null);
os=Factory.ObjectStore.fetchInstance(domain, "CMTOS", null);
System.out.println(""+os.get_Name());
for(int index=0;index<ids.size();index++)
{
doc1=Factory.Document.fetchInstance(os,new Id(""+ids.get(index)+""), null);
output_data = new FileOutputStream("d:\\sample\\"+doc1.get_Name());
content_element_list=doc1.get_ContentElements();
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());
}
}
System.out.println("file copied is "+ids.get(index));
}
}
}
catch(Exception e)
{
System.out.println(""+e.getLocalizedMessage());
}
}
}
output:
here output is set of documents stored on local file path.
No comments:
Post a Comment