Wednesday, May 14, 2008

How to export a Virtual Document in Documentum.

First you will need to convert the IDfSysObject to an IDfVirtualDocument.

        //verify the object is a virtual document
//the variable doc is the IDfSysObject that you are working with
if (doc.isVirtualDocument()) {
IDfVirtualDocument v = doc.asVirtualDocument("CURRENT",false);
exportVirtualDocument(v, exportDir, "");
} else {
throw new DfException("Must be a virtual document to export.");
}


Then take the doc variable and call this method:

    /**
* Exports virtual document to the destination directory
*
* @param doc virtual document to be exported
* @param destDir directory virtual document should be exported to
* @param exportFormat export format (such as html, or you can use the da to create a new one)
* @throws Exception
*/

private void exportVirtualDocument(IDfVirtualDocument doc,
String destDir, String exportFormat) throws Exception {
IDfClientX clientx = new DfClientX();

IDfExportOperation operation = clientx.getExportOperation();
operation.setDestinationDirectory(destDir);
IDfExportNode node = (IDfExportNode) operation.add(doc);
node.setFormat(exportFormat);

// Execute the operation
boolean executeFlag = operation.execute();

// Check if any errors occured during the execution of the operation
if (executeFlag == false) {
// Get the list of errors
IDfList errorList = operation.getErrors();
String message = "";
IDfOperationError error = null;

// Iterate through the errors and concatenate the error messages
for (int i = 0; i < errorList.getCount(); i++) {
error = (IDfOperationError) errorList.get(i);
message += error.getMessage();
}

if (message.length() > 0) {
// Create a DfException to report the errors
DfException e = new DfException();
e.setMessage(message);
throw e;
}
}
}

No comments: