Display Version Information 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 prints version information of a document such as its current version, next major version and next minor version. It uses the interface IDfVersionPolicy to obtain this information.
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.IDfVersionPolicy;
import com.documentum.com.DfClientX;
import com.documentum.com.IDfClientX;
public class DisplayVersionInformation
{
public static void main(String[] args)
{
String username = "dmadmin";
String password = "dmadmin";
String repoName = "devprog53sp1";
String docId = "09017a1280005275";
IDfSessionManager sessMgr = null;
IDfSession sess = null;
try
{
sessMgr = createSessionManager();
addIdentity(sessMgr,username,password,repoName);
showVersionInfo(sessMgr,repoName,docId);
}
catch(Exception ex)
{
ex.printStackTrace();
}
finally
{
if((sessMgr != null) && (sess != null))
{
sessMgr.release(sess);
}
}
}
private static void showVersionInfo(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);
IDfVersionPolicy verPol = docObj.getVersionPolicy();
System.out.println("Current Version: " + verPol.getSameLabel());
System.out.println("Next Major Label: " + verPol.getNextMajorLabel());
System.out.println("Next Minor Label: " + verPol.getNextMinorLabel());
System.out.println("Branch Label: " + verPol.getBranchLabel());
System.out.println("Can Version to Same Version: " +
verPol.canVersion(IDfVersionPolicy.DF_SAME_VERSION));
System.out.println("Can Version to Next Major: " +
verPol.canVersion(IDfVersionPolicy.DF_NEXT_MAJOR));
System.out.println("Can Version to Next Minor: " +
verPol.canVersion(IDfVersionPolicy.DF_NEXT_MINOR));
System.out.println("Can Version to Branch: " +
verPol.canVersion(IDfVersionPolicy.DF_BRANCH_VERSION));
System.out.print("Default Checkin Version: ");
switch(verPol.getDefaultCheckinVersion())
{
case IDfVersionPolicy.DF_SAME_VERSION:
System.out.println("Same Version");
break;
case IDfVersionPolicy.DF_NEXT_MAJOR:
System.out.println("Next Major");
break;
case IDfVersionPolicy.DF_NEXT_MINOR:
System.out.println("Next Minor");
break;
case IDfVersionPolicy.DF_BRANCH_VERSION:
System.out.println("Branch Version");
break;
case IDfVersionPolicy.DF_CANNOT_VERSION:
System.out.println("Cannot Version");
break;
}
}
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);
}
}
|
 |
|