List the Renditions of a Document
| February 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 snippet lists all the renditions of a document.
Snippet
/*
* Created on Feb 10, 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.IDfCollection;
import com.documentum.fc.client.IDfDocument;
import com.documentum.fc.client.IDfSession;
import com.documentum.fc.client.IDfSessionManager;
import java.util.LinkedList;
import com.documentum.com.DfClientX;
import com.documentum.com.IDfClientX;
public class ListRenditions
{
public static void main(String[] args)
{
String username = "aashish";
String password = "dmadmin";
String repoName = "devprog53SP1";
String docId = "0900c355812974b9";
IDfSessionManager sessMgr = null;
IDfSession sess = null;
try
{
sessMgr = createSessionManager();
addIdentity(sessMgr,username,password,repoName);
sess = sessMgr.getSession(repoName);
getAllRenditionFormatNames(sess,new DfId(docId));
}
catch(Exception ex)
{
ex.printStackTrace();
}
finally
{
if((sessMgr != null) && (sess != null))
{
sessMgr.release(sess);
}
}
}
/**
* Gets an array of all the format names of the renditions
* that a document exists in.
* @param sess
* @param docId The id of the document whose rendition format names are needed.
* @return
* @throws DfException
*/
public static void getAllRenditionFormatNames(
IDfSession sess,
IDfId docId)
throws DfException
{
IDfDocument doc = (IDfDocument) sess.getObject(docId);
IDfCollection coll = null;
try
{
coll = doc.getRenditions("full_format");
while (coll.next())
{
String fmtName = coll.getString("full_format");
System.out.println(fmtName);
}
}
finally
{
if (coll != null)
{
coll.close();
}
}
}
/**
* 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);
}
}
|
 |
|