Hi,

Just a simple post concerning a useful functionality provided by Documentum in com.documentum.xml.xdql DFC package.

As you would see in my previous post http://www.javablog.fr/xstream-presentation-serialization-deserialization-xml.html, there is another solutions/frameworks like Xstream for the serialization and deserialization of XML in Java applications.

This package com.documentum.xml.xdql contains only the Interface IDfXmlQuery. This interface provides functionality for running queries against a repository, returning the results as XML.
The structure of the XML output is a root element, specified by setRootTag, followed by each query result row. The following is an example of the XML output:

<?xml version="1.0"?>
 <root>
     <object ID="09017e1080001932">
         <r_object_id>09017e1080001932</r_object_id>
         <object_name>catalog A</object_name>
     </object>
     <object ID="09017e10800019aa">
         <r_object_id>09017e10800019aa</r_object_id>
         <object_name>catalog B</object_name>
     </object>
 </root>

There are many options available for customizing the XML output, such as specifying the whether object content should be included in the output. Each option has a default value, so you only need to set the options that you want to override.

 
 
Sample DFC code to get document as XML

package com.huo.test.ecm.test2;

import java.io.FileOutputStream;
import java.io.IOException;

import com.documentum.fc.client.DfClient;
import com.documentum.fc.client.IDfClient;
import com.documentum.fc.client.IDfQuery;
import com.documentum.fc.client.IDfSession;
import com.documentum.fc.client.IDfSessionManager;
import com.documentum.fc.client.IDfSysObject;
import com.documentum.fc.common.DfException;
import com.documentum.fc.common.DfLoginInfo;
import com.documentum.fc.common.IDfLoginInfo;
import com.documentum.xml.xdql.DfXmlQuery;
import com.documentum.xml.xdql.IDfXmlQuery;

/*
 Documentum DFC Standalone Sample Program

 Sample DFC code to get document as XML
*/
public class DocumentRecordsAsXMLTest {

	IDfSysObject sysObject = null;
	IDfSession idfSession = null;
	IDfSessionManager sessMgr = null;

	public DocumentRecordsAsXMLTest(String user, String passwd, String docbase) throws Exception {
		getDfSession(user, passwd, docbase);
	}

	public IDfSession getDfSession(String args1, String args2, String args3) throws Exception {
		IDfLoginInfo login = new DfLoginInfo();
		login.setUser(args1);
		login.setPassword(args2);
		IDfClient client = DfClient.getLocalClient(); //new DfClient();
		sessMgr = client.newSessionManager();
		sessMgr.setIdentity(args3, login);
		idfSession = sessMgr.getSession(args3);

		if (idfSession != null)
			System.out.println("Session created successfully");

		return idfSession;
	}


	public void releaseSession() throws Exception {
		sessMgr.release(idfSession);
	}
	
	public String getdm_documentRecordsAsXML(String dql, String fileStoring) throws DfException {
		System.out.println("#################################################");

		IDfXmlQuery objDfXmlQuery = new DfXmlQuery();
		objDfXmlQuery.init();
		objDfXmlQuery.setDql(dql);
		objDfXmlQuery.setContentAsLink(true);
		objDfXmlQuery.setMetaDataAsAttributes(false);
		//objDfXmlQuery.setPreserveSpace(true);
		objDfXmlQuery.setRepeatingAsNested(true);
		objDfXmlQuery.setRepeatingIncludeIndex(true);
		objDfXmlQuery.includeMetaData(true);
		objDfXmlQuery.useNullAttributeIndicator(true);
		objDfXmlQuery.includeDCTMChunkInfo(true);
		objDfXmlQuery.includeContent(true);
		objDfXmlQuery.execute(IDfQuery.DF_READ_QUERY, idfSession);
		String xml = objDfXmlQuery.getXMLString();
		System.out.println("XML is  : " + xml);
		
		FileOutputStream fos = null;
		 try {
			fos = new FileOutputStream(fileStoring);
			objDfXmlQuery.getXMLString(fos);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			if(fos != null){
			 try { fos.flush(); } catch (IOException e) { e.printStackTrace(); }
			 try { fos.close(); } catch (IOException e) { e.printStackTrace(); }
			}
		}
		
		return xml;
	}

	
	
	public static void main(String[] args) throws Exception {

		String user = "myuser";
		String passwd = "passeord4myus";
		String docbase = "MY_DOC_BASE";
		DocumentRecordsAsXMLTest object = new DocumentRecordsAsXMLTest(user, passwd, docbase);

		try {
			// To get document as XML
			object.getdm_documentRecordsAsXML("select * from dm_document where r_object_id='090xxxxxxxxxxxxf1d'", "C:\\Workspaces\\TestDCTMHUO\\src\\com\\huo\\test\\ecm\\test2\\documentXML.xml");
		} finally {
			// to release a docbase session
			object.releaseSession();
		}
	}
}

….outputs:

Session created successfully
#################################################
XML is  : <?xml version="1.0"?>
<root>
    <object ID="090xxxxxxxxxxxxf1d">
        <r_object_id>090xxxxxxxxxxxxf1d</r_object_id>
        <object_name>Test 12</object_name>
        <title>null</title>
        <subject>null</subject>
        <resolution_label>null</resolution_label>
        <owner_name>gedadm</owner_name>
        <owner_permit>6</owner_permit>
        <group_name>null</group_name>
        <group_permit>1</group_permit>
        <world_permit>1</world_permit>
        <log_entry>null</log_entry>
        <acl_domain>PWCCOMPANYDEV</acl_domain>
        <acl_name>dm_450220c580068103_8005a971</acl_name>
        <language_code>null</language_code>
        <r_object_type>pwc_client_document</r_object_type>
        <r_creation_date>12/02/2014 15:20:56</r_creation_date>
        <r_modify_date>18/11/2016 15:18:21</r_modify_date>
        <a_content_type>dxl</a_content_type>
        <content r_object_id="090xxxxxxxxxxxxf1d">dctm://MY_DOC_BASE/090xxxxxxxxxxxxf1d?DMS_OBJECT_SPEC=OBJECT_ID</content>
    </object>
</root>

 
 
Document with aspect attached

// To get document-aspect as XML
object.getdm_documentRecordsAsXML("select r_object_id, r_modifier, r_modify_date, r_aspect_name, object_name, aspect_huo.huo_request_num from dm_document where r_object_id='090xxxxxxxxxxxx36'", "C:\\Workspaces\\TestDCTMHUO\\src\\com\\huo\\test\\ecm\\test2\\documentXML.xml");

….outputs:

Session created successfully
#################################################
XML is  : <?xml version="1.0"?>
<root>
    <object ID="090xxxxxxxxxxxx36">
        <r_object_id>090xxxxxxxxxxxx36</r_object_id>
        <r_modifier>gedadm</r_modifier>
        <r_modify_date>19/10/2016 14:38:41</r_modify_date>
        <r_aspect_name>
            <r_aspect_name-value index="0">aspect_huo</r_aspect_name-value>
            <r_aspect_name-value index="1">aspect_copy</r_aspect_name-value>
            <r_aspect_name-value index="2">aspect_email</r_aspect_name-value>
        </r_aspect_name>
        <object_name>HUO value object name.
            Residential II S.A.</object_name>
        <aspect_huo.huo_request_num>900971</aspect_huo.huo_request_num>
        <content r_object_id="090xxxxxxxxxxxx36">dctm://MY_DOC_BASE/090xxxxxxxxxxxx36?DMS_OBJECT_SPEC=OBJECT_ID</content>
    </object>
</root>

That’s all!!!

Huseyin OZVEREN