Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
searchChildren is failing
nas
Hi,
I need to find all documents in a container. Container could be a folder or catalog etc.
I am using following code for that:
Library lib1 = cmsSession.getLibraryByName("UKDMPILOTDEV1");
String curDocumentName="MYDOC";
SearchArgument sa = new SearchArgument();
sa.setProfileCondition("APP::NAME = \"" + curDocumentName + "\"");
Collection searchResults = null;
Container parent = null;
// Get parent container
//String parentId = "!V3!UKDMPILOTDEV1!C!F$110!C$200!"; // catalog container
String parentId = " !V3!UKDMPILOTDEV1!C!FD$14468!"; // folder container
parent = (Container) lib.getObjectById(parentId);
// Now find all documents inside the parent container
searchResults = parent.searchChildren(Document.class, sa);
out.println(String.valueOf(searchResults.size()));
The code is working fine when the parentId is a folder’s Id but when it is catalog folder code I throwing following error:
java.lang.ClassCastException on line searchResults = parent.searchChildren(Document.class, sa);
Any ideas what I am doing wrong here!
Thanks
Nas
Find more posts tagged with
Comments
tsconsultant
Hi Nas,
here is some sample method which will accept workspace object as an argument and returns all the documents available in that workspace.
You can change this code as per your requirement.
public ArrayList getAllDocuments(Workspace wSpace) throws WorkteamException
{
ArrayList aList = new ArrayList();
HashMap hMap;
String temp = null;
boolean noLabels = false,exclusionLabel = false;
try{
WorkspaceSearchArgument sArg = new WorkspaceSearchArgument();
sArg.setProfileCondition("APP::NAME LIKE \"%\"");
sArg.setItemsToReturn(new Integer(2000));
sArg.setItemsToSkip(new Integer(0));
SearchArgument.SearchReturnedItem[] searchItems = new SearchArgument.SearchReturnedItem[1];
// Set which properties will be filled in the return Item.
String[] props = new String[2];
props[0] = "BASE::CREATED_TIME";
props[1] = "APP::LABEL_RSID";
// Set the SearchReturnedItem[] element to return Document and Event items.
searchItems[0] = new SearchArgument.SearchReturnedItem(Document.class,props);
// Set the SearchReturnedItem[].
sArg.setReturnedItems(searchItems);
// Set the search parent.
sArg.setSearchParent(wSpace);
// Perform the search.
SearchResultList results = wSpace.search(sArg);
if (results.size()==0)
{
myLogger.info("No Objects Found");
}
else
{
myLogger.info("Objects Found");
// Get an Iterator and loop through the results.
Iterator iter = results.iterator();
while(iter.hasNext())
{
SearchResult result = (SearchResult)iter.next();
// Retrieve the Item & show some statistics. Item should be the type of Document
Item myItem = result.getItem();
System.out.println("Document Name : " + myItem.getName());
}
}catch(WorkteamException we){
}catch(Exception e){
}
return aList;
}