A lot of administrative tasks in Intralink 3.x are much more difficult than necessary, and in some cases nearly impossible. Folder information is one of those tasks. Without running the DSMU, getting information on folders can be extremely tedious.
Fortunately with the right Java code, we can put some of the internal features of the Intralink client to use. These are the same data model classes that the client Java code uses, but now we can use them to get the information that you want, how you want it, and whenever you want it. Remember, it's your data.
To traverse the Commonspace folder structure, my utility method getFolderList() will be used. It uses an ILFolderTreeModel object, which is a folder tree data model class, and a TreeNode, which is a node within a tree structure. The method calls itself recursively to traverse a folder tree, which need not start at the Commonspace root folder.
Initially, the method builds a new ArrayList. Then, the root node is added to the ArrayList. The method then iterates over the children, if any, of the current node. If there are child nodes, the method calls itself using the same ILFolderTreeModel object, but this time with the child node. The resulting ArrayList of the child node recursion is added to the higher level ArrayList. The child ArrayList is then cleared and nulled. The first ArrayList is returned when recursion has completed.
public List getFolderList ( ILFolderTreeModel treemodel, TreeNode tree ) throws Exception {
List list = new ArrayList();
list.add(tree.getKeyName());
for (int i=0; i<treemodel.getChildCount(tree); i++) {
TreeNode child = (TreeNode)treemodel.getChild(tree,i);
List sublist = getFolderList(treemodel, child);
list.addAll(sublist);
sublist.clear();
sublist = null;
}
return list;
}
In order to call this function, an ILFolderTreeModel and a TreeNode object are required.
For the ILFolderTreeModel object, we can simply call the constructor:
ILFolderTreeModel tm = new ILFolderTreeModel();
If the root node is the Commonspace Root Folder, then the TreeNode object is obtained as follows from the ILFolderTreeModel object:
TreeNode tree = (TreeRootNode)tm.getRoot();
If another folder is the root for the TreeNode, things get a bit more complicated. First, an ILAppObject is created representing the folder of interest, then TreeObject.createCSTree() is executed using the ILAppObject. Running the getRoot() method of the resulting TreeObject gives us a TreeNode that we can use.
String startFolderName = "Root Folder/ProjectX";
ILAppObject start_fol_ao = ObjectInfo.getObjectByKey( ObjectInfo.tFolder, startFolderName );
TreeNode tree = TreeObject.createCSTree(start_fol_ao).getRoot();
To get the ArrayList, getFolderList() is executed:
List folders = getFolderList(tm, tree);
To iterate over the resulting ArrayList, use code like this:
for (int i=0; i<folders.size(); i++) {
String folderName = folders.get(i).toString();
System.out.println( " " + (i+1) + ": " + folderName );
}
The output will appear in the .proi.log file on Unix or the most recent .pro.log.N file on Windows.
Here is the complete program. Please note the addition of three import statements beyong the typical two that Intralink provides in each Intralink Scripting application.
import com.ptc.intralink.client.script.*;
import com.ptc.intralink.script.*;
import com.ptc.intralink.client.admin.folder.*;
import com.ptc.intralink.ila.*;
import java.util.*;
public class Folder_List extends ILIntralinkScript {
ILIntralinkScriptInterface IL = (ILIntralinkScriptInterface)getScriptInterface();
public void run () throws Exception {
TreeNode tree = null;
ILFolderTreeModel tm = new ILFolderTreeModel();
String startFolderName = null;
startFolderName = "";
startFolderName = "/";
startFolderName = "Root Folder";
startFolderName = "Root Folder/ProjectX";
if ( startFolderName == null || startFolderName.matches("^/?$") ) {
tree = (TreeNode)tm.getRoot(); // Casting to TreeNode required
}
else {
ILAppObject start_fol_ao = ObjectInfo.getObjectByKey( ObjectInfo.tFolder, startFolderName );
tree = TreeObject.createCSTree(start_fol_ao).getRoot();
}
System.out.println( " tree: " + tree );
List folders = getFolderList(tm, tree);
for (int i=0; i<folders.size(); i++) {
String folderName = folders.get(i).toString();
System.out.println( " " + (i+1) + ": " + folderName );
System.out.flush();
}
folders.clear();
folders = null;
tm = null;
}
public List getFolderList ( ILFolderTreeModel treemodel, TreeNode tree ) throws Exception {
List list = new ArrayList();
list.add(tree.getKeyName());
for (int i=0; i<treemodel.getChildCount(tree); i++) {
TreeNode child = (TreeNode)treemodel.getChild(tree,i);
List sublist = getFolderList(treemodel, child);
list.addAll(sublist);
sublist.clear();
sublist = null;
}
return list;
}
}
In the next installment, I'll show how more information about folders can be gathered, along with a more sophisticated presentation of the data.
1 comment:
Refactored code, was overly complicated.
Post a Comment