fbpx

XML Transformations Using DFC Methods

Introduction

Documentum has added significant functionality support for XML in the 4i and 4.2 versions of their products. Additionally, Documentum has provided
documentation on how to utilize the XML functionality, “Managing XML Content In Documentum”. The purpose of this article is to summarize and supplement the Documentum documentation based on our experiences
utilizing the DFC XML Transformation classes.

DFC Classes And Methods For Transforming XML Documents

Documentum has provided support for Transforming XML documents using Stylesheets with addition of the following classes to DFC:

  • IDfXMLTransformNode
  • IDfXMLTransformOperation
  • public void setSession(IDfSession session) throws DfException
    Set the session that is to be used by the IDfXMLTransformOperation.
  • public void setTransformation(Object transformObject) throws DfException
    Specify the XSLT transformation object (the XSL stylesheet) that is used to transform the inputNode
    transformObj can be any one of the following types: IDfSysObject, URL, Reader, IDfFile.
  • public void setDestination(Object destinationObject) throws DfException
    Specify the resultant transformed document’s destination.destinationObject can be one of the following types: IDfSysObject, Writer, IDfFile, IDfImportOperation.

There are additional DFC classes and methods that support XML in Documentum Applications (IDfXMLDocType, DfXmlQuery) that this article doesn’t address, but that hopefully future articles will.

Examples And Tips On Using DFC XML Transform Methods

The following examples demonstrate how to use the DFC XML Transform Classes described above. The examples are based on the example taken from the “Managing XML Content In Documentum” document.
I have added additional code and comments to hopefully help you avoid problems I experienced when initially attempted to transfer the utilize the code in the example to transform XML documents used in an in-house Web based application.
The examples assume you have successfully connected to a docbase and have a corresponding IDfSession object.

XML Transform where XSL StyleSheet defining transform is a Documentum Object and Transformation Results in a new dm_document Object in the docbase


try {
// Instantiate a DFC TransformOperation object
IDfXMLTransformOperation transformOperation = new DfXMLTransformOperation();
// Associate your Session object to the DfXMLTransformOperation
transformOperation.setSession(sess);
// Get the DCTM object representing the XML to be transformed and add it to the transformOperation
IDfSysObject xmlObject = (IDfSysObject)
sess.getObjectByPath("/Some Cabinet/DMD XML Examples/ProjectData.xml");
IDfXMLTransformNode inputNode = (IDfXMLTransformNode)
transformOperation.add(xmlObject);
// Get the DCTM object representing the XSL defining the transform and add it to the transformOperation
IDfSysObject xslObject = (IDfSysObject)
sess.getObjectByPath("/Some Cabinet/DMD XML Examples/FinancialReport.xsl");
transformOperation.setTransformation(xslObject);
// Create a dm_document object where the result of the transformation will be written
IDfSysObject sysObj = (IDfSysObject)sess.newObject("dm_document");
sysObj.setObjectName("Translation Output.html");
sysObj.setSubject("Translated XML Document");
sysObj.setContentType("html");
sysObj.setFile("C:DFC ExamplesDFC ExamplesFinancialReport.html");
sysObj.link("/Some Cabinet/DMD XML Examples");
sysObj.save();
// Set the transformOperation destination to the dm_document DCTM Object previously created
transformOperation.setDestination(sysObj);
// You can either explicitly set the output here, or specify it in the stylesheet.
// If defining output format in stylesheet, use this line:
// <xsl:output method="html" encoding = "ISO-8859-1" indent="yes" media-type="text/html" />
// otherwise, include this line in the Java code:
inputNode.getProperties().putString(DfOpConstants.FILE_FORMAT, "html");
Failing to define the output format will result in the following error message:
Output format specified does not exist in docbase.
// Execute the Transform operation
boolean transformResult = transformOperation.execute();
// Check for errors in the transformOperation. transformOperation.execute() returns a boolean
// Error indicated by transformOpeation returning "false"
if (transformResult == false)
{
IDfList errorList = transformOperation.getErrors();
for (int i = 0; i < errorList.getCount(); i++)
{
IDfOperationError error =
(IDfOperationError)errorList.get(i);
System.out.println("Error Message: " + error.getMessage());
}
}
} catch (DfException dfex1) {
System.out.println("Error instantiating IDfSysObject:n " + dfex1.getMessage());
}

XML Transform XSL StyleSheet defining transform is a URL and Transformation Result is written to a file on Disk


try {
// Instantiate a DFC TransformOperation object
IDfXMLTransformOperation transformOperation = new DfXMLTransformOperation();
// Associate your Session object to the DfXMLTransformOperation
transformOperation.setSession(sess);
// Get the DCTM object representing the XML to be transformed and add it to the transformOperation</b>
IDfSysObject xmlObject = (IDfSysObject)
sess.getObjectByPath("/Some Cabinet/DMD XML Examples/ProjectData.xml");
IDfXMLTransformNode inputNode = (IDfXMLTransformNode)
transformOperation.add(xmlObject);
// Create a java.net.URL object that references to URL where the XSL is located
//and supply the java.net.URL object as the parameter to the setTranformation() method
URL xslURL = new URL("http://localhost/Finances.xsl");
transformOperation.setTransformation(xslURL);
// Create a DfFile object. Transformation result will be written to disk file.
DfFile outFile = new DfFile("C:DFC Examples\TransformOutput.html");
// Set the transformOperation destination to the disk file (DfFile object)
transformOperation.setDestination(outFile);
// You can either explicitly set the output here, or specify it in the stylesheet.
// If defining output format in stylesheet, use this line:
// <xsl:output method="html" encoding = "ISO-8859-1" indent="yes" media-type="text/html" />
// otherwise, include this line in the Java code:
inputNode.getProperties().putString(DfOpConstants.FILE_FORMAT, "html");
// Execute the Transform operation
boolean transformResult = transformOperation.execute();
// Check for errors in the transformOperation. transformOperation.execute() returns a boolean
// Error indicated by transformOpeation returning "false"
if (transformResult == false)
{
IDfList errorList = transformOperation.getErrors();
for (int i = 0; i < errorList.getCount(); i++)
{
IDfOperationError error =
(IDfOperationError)errorList.get(i);
System.out.println("Error Message: " + error.getMessage());
}
}
} catch (DfException dfex1) {
System.out.println("Error instantiating IDfSysObject:n " + dfex1.getMessage());
}

XML Transform where XSL StyleSheet defining transform is a Reader (or Reader sub class) and Transformation Result is a Writer (or Writer sub class)


try {
// Instantiate a DFC TransformOperation object
IDfXMLTransformOperation transformOperation = new DfXMLTransformOperation();
// Associate your Session object to the DfXMLTransformOperation
transformOperation.setSession(sess);
// Get the DCTM object representing the XML to be transformed and add it to the transformOperation
IDfSysObject xmlObject = (IDfSysObject)
sess.getObjectByPath("/Some Cabinet/DMD XML Examples/ProjectData.xml");
IDfXMLTransformNode inputNode = (IDfXMLTransformNode)
transformOperation.add(xmlObject);
// Set up the InpurtStream (Reader object) the XSL defining the transform will be read from
// In this case, we are using a FileReader, but any subclass of Reader can be used
FileReader reader = new FileReader("G:wallach_workXML XLSTStatusXMLFinances.xsl");
transformOperation.setTransformation(reader);
// Instantiate java Writer object where the result of the transformation will be written
// In this example, we are using a OutputStreamWriter, and just writing the translation to System.out
OutputStreamWriter output = new OutputStreamWriter(System.out);
transformOperation.setDestination(output);
// You can either explicitly set the output here, or specify it in the stylesheet.
// If defining output format in stylesheet, use this line:
// <xsl:output method="html" encoding = "ISO-8859-1" indent="yes" media-type="text/html" />
// otherwise, include this line in the Java code:
inputNode.getProperties().putString(DfOpConstants.FILE_FORMAT, "html");
Failing to define the output format will result in the following error message:
Output format specified does not exist in docbase.
// Execute the Transform operation
boolean transformResult = transformOperation.execute();
// Check for errors in the transformOperation. transformOperation.execute() returns a boolean
// Error indicated by transformOpeation returning "false"
if (transformResult == false)
{
IDfList errorList = transformOperation.getErrors();
for (int i = 0; i < errorList.getCount(); i++)
{
IDfOperationError error =
(IDfOperationError)errorList.get(i);
System.out.println("Error Message: " + error.getMessage());
}
}
} catch (DfException dfex1) {
System.out.println("Error instantiating IDfSysObject:n " + dfex1.getMessage());
}

Like this article?

Share on facebook
Share on Facebook
Share on twitter
Share on Twitter
Share on linkedin
Share on Linkdin
Share on pinterest
Share on Pinterest

Leave a comment