Display All Versions of a Document
| March 2006 | |
|
Software Environment
| Feature | Tested on |
| Operating System | Windows 2000 Server SP4 |
| Compiler | Sun JDK 1.4.2_08 |
| Runtime | Sun JRE 1.4.2_08 |
| DFC | 5.2.x,5.3, 5.3 SP1 |
| Content Server | 5.3 |
Abstract
This code snippet displays all the versions of a document. It uses the DFC interface IDfVersionTreeLabels for this purpose.
Snippet
/*
* Created on Mar 8, 2006
*
* EMC Documentum Developer Program 2005
*/
package com.documentum.devprog.snippets;
import com.documentum.fc.common.DfException;
import com.documentum.fc.common.DfId;
import com.documentum.fc.common.IDfId;
import com.documentum.fc.common.IDfLoginInfo;
import com.documentum.fc.client.IDfClient;
import com.documentum.fc.client.IDfDocument;
import com.documentum.fc.client.IDfSession;
import com.documentum.fc.client.IDfSessionManager;
import com.documentum.fc.client.IDfVersionLabels;
import com.documentum.fc.client.IDfVersionTreeLabels;
import com.documentum.com.DfClientX;
import com.documentum.com.IDfClientX;
public class DisplayAllVersions
{
public static void main(String[] args)
{
String username = "dmadmin";
String password = "dmadmin";
String repoName = "devprog53sp1";
String docId = " 0900c3558127bd32";
IDfSessionManager sessMgr = null;
IDfSession sess = null;
try
{
sessMgr = createSessionManager();
addIdentity(sessMgr,username,password,repoName);
showVersionTree(sessMgr,repoName,docId);
}
catch(Exception ex)
{
ex.printStackTrace();
}
finally
{
if((sessMgr != null) && (sess != null))
{
sessMgr.release(sess);
}
}
}
private static void showVersionTree(IDfSessionManager sm,String repo,String docId) throws DfException
{
IDfSession sess = null;
try
{
IDfId id = new DfId(docId);
sess = sm.getSession(repo);
IDfDocument docObj = (IDfDocument) sess.getObject(id);
//get the chornicle id (i.e. id of the root obj)
IDfId chronId = docObj.getChronicleId();
IDfVersionTreeLabels tree = sess.getVersionTreeLabels(chronId);
int lblCnt = tree.getVersionCount();
for(int i = 0;i < lblCnt; i++)
{
IDfVersionLabels lbl = tree.getVersion(i);
System.out.println(lbl.getImplicitVersionLabel() + " : " + lbl.getObjectId());
}
}
finally
{
if(sess != null)
{
sm.release(sess);
}
}
}
/**
* Creates a new session manager instance. The session manager does not have
* any identities associated with it.
*
* @return a new session manager object.
* @throws DfException
*/
private static IDfSessionManager createSessionManager() throws DfException
{
IDfClientX clientX = new DfClientX();
IDfClient localClient = clientX.getLocalClient();
IDfSessionManager sessMgr = localClient.newSessionManager();
return sessMgr;
}
/**
* Adds a new identity to the session manager.
*/
private static void addIdentity(IDfSessionManager sm, String username,
String password, String repoName) throws DfException
{
IDfClientX clientX = new DfClientX();
IDfLoginInfo li = clientX.getLoginInfo();
li.setUser(username);
li.setPassword(password);
// check if session manager already has an identity.
// if yes, remove it.
if (sm.hasIdentity(repoName))
{
sm.clearIdentity(repoName);
}
sm.setIdentity(repoName, li);
}
}
|
 |
|