Friday, January 7, 2011

Find an item by name

So you want to find an item using the WCM API ha?No problem....


<%@ page import="com.ibm.workplace.wcm.api.*"%>
<%@ page import="java.util.*"%>
<% // retrieve repository Repository repository = WCM_API.getRepository(); // get the workspace for current user Workspace workspace = repository.getWorkspace(request.getUserPrincipal()); // set the library workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("WebContent")); // **************************** Find Site example *************************** // define site name String siteName = new String("Site"); // find site by name DocumentIdIterator siteIterator = workspace.findByName(DocumentTypes.Site,siteName); if (siteIterator.hasNext()){ out.println("Site found : " + siteName + "
");
}else {
out.println("Could not find site : " + siteName + "
");
}

// ************************* Find Sitearea example **************************
// define sitearea name
String siteArea = new String("SiteArea");
// find sitearea by name
DocumentIdIterator siteAreaIterator = workspace.findByName(DocumentTypes.SiteArea,siteArea);
if (siteAreaIterator.hasNext()){
out.println("Sitearea found : " + siteArea + "
");
}else {
out.println("Could not find Sitearea : " + siteArea + "
");
}

// ************************* Find Content example ***************************

// define content name
String contentName = new String("Content");
// find content by name
DocumentIdIterator contentIterator = workspace.findByName(DocumentTypes.Content,contentName);
if (contentIterator.hasNext()){
out.println("Content found : " + contentName + "
");
}else {
out.println("Could not find Content : " + contentName + "
");
}

// *********************** Find Authoring Template example *******************

// define authoring template name
String authoringTemplateName = new String("AuthoringTemplate");

// find authoring template by name
DocumentIdIterator authoringTemplateIterator = workspace.findByName(DocumentTypes.AuthoringTemplate,authoringTemplateName);
if (authoringTemplateIterator.hasNext()){
out.println("Authoring template found : " + authoringTemplateName + "
");
}else {
out.println("Could not find Authoring template: " + authoringTemplateName + "
");
}

// *********************** Find Presentation Template example *****************

// define presentation template name
String presentationTemplateName = new String("PresentationTemplate");
// find presentation template by name
DocumentIdIterator presentationTemplateIterator = workspace.findByName(DocumentTypes.PresentationTemplate,presentationTemplateName);
if (presentationTemplateIterator.hasNext()){
out.println("Presentation template found : " + presentationTemplateName + "
");
}else {
out.println("Could not find Presentation template: " + presentationTemplateName + "
");
}

// *********************** Find Library Component example *******************

// define library component name
String libraryComponentName = new String("LibraryComponent");
// find library component by name
DocumentIdIterator libraryComponentIterator = workspace.findByName(DocumentTypes.LibraryComponent,libraryComponentName);
if (libraryComponentIterator.hasNext()){
out.println("Library component found : " + libraryComponentName + "
");
}else {
out.println("Could not find Library component: " + libraryComponentName + "
");
}

// *************************** Find Workflow example ***********************

// define workflow name
String workflowName = new String("Workflow");

// find workflow by name
DocumentIdIterator workflowIterator = workspace.findByName(DocumentTypes.Workflow,workflowName);
if (workflowIterator.hasNext()){
out.println("Workflow found : " + workflowName + "
");
}else {
out.println("Could not find Workflow: " + workflowName + "
");
}

// ************************* Find Workflow Stage example ********************

// define workflow stage name
String workflowStageName = new String("WorkflowStageName");
// find workflow stage by name
DocumentIdIterator workflowStageIterator = workspace.findByName(DocumentTypes.WorkflowStage,workflowStageName);
if (workflowStageIterator.hasNext()){
out.println("Workflow Stage found : " + workflowStageName + "
");
}else {
out.println("Could not find Workflow Stage: " + workflowStageName + "
");
}

// ************************** Find Taxonomy example ************************

// define taxonomy name
String taxonomyName = new String("Taxonomy");
// find taxonomy by name
DocumentIdIterator taxonomyIterator = workspace.findByName(DocumentTypes.Taxonomy,taxonomyName);
if (taxonomyIterator.hasNext()){
out.println("Taxonomy found : " + taxonomyName + "
");
}else {
out.println("Could not find Taxonomy: " + taxonomyName + "
");
}

// ************************** Find Category example *************************

// define category name
String categoryName = new String("Category");
// find category by name
DocumentIdIterator categoryIterator = workspace.findByName(DocumentTypes.Category,categoryName);
if (categoryIterator.hasNext()){
out.println("Category Found : " + categoryName + "
");
}else {
out.println("Could not find Category : " + categoryName + "
");
}
%>

No comments:

Post a Comment