Documente Academic
Documente Profesional
Documente Cultură
Bhargavkumar Thakker
Staff Software Engineer
IBM Software Group
Pune, India
Soumitra Limaye
Staff Software Engineer
IBM Software Group
Pune, India
October 2009
Abstract: The IBM® Lotus® Web Content Management™ (hereafter called “Web Content
Management”) API provides an extension of standard features of Web Content Management. This
article provides usage and solutions with code samples of the most common implementations
carried out by customers using APIs. You can pick and choose the samples provided here, as is, to
incorporate into your system.
Contents
1 Introduction..................................................................................................................................... 2
2 Assumptions and considerations..................................................................................................... 4
3 Code samples to implement various scenarios using APIs per the requirement ............................ 4
Scenario 1: Find an item of a given type by name......................................................................... 4
Scenario 2: Find items based on the item type .............................................................................. 8
Scenario 3: Find content by various criteria ................................................................................ 12
Scenario 4: Search for content based on Authoring Template, Site Area, Category, and
Keywords criteria......................................................................................................................... 16
Scenario 5: Creating a new Site ................................................................................................... 18
Scenario 6: Creating a new Site Area .......................................................................................... 19
Scenario 7: Creating new Content ............................................................................................... 21
Scenario 8: Creating a new Content Link that is linked to existing Content............................... 23
Scenario 9: Creating various Library Components..................................................................... 24
-1-
Scenario 10: Creating a new Taxonomy and a new Category ..................................................... 25
Scenario 11: Creating and canceling drafts on published Content items..................................... 26
Scenario 12: Moving content to Next Stage of a Workflow, Restarting the Workflow, setting
another Workflow on specific content......................................................................................... 28
Scenario 13: Render Sites, Site Areas, Contents, Content components, or Library Components
...................................................................................................................................................... 29
Scenario 14: Moving or copying an entire Site Area within/between libraries........................... 31
Scenario 15: Moving or copying content within/between libraries ............................................. 33
Scenario 16: Moving or copying non-hierarchical or root items to another library .................... 35
Scenario 17: Moving or copying a Category within/between libraries ....................................... 39
Scenario 18: Deleting and purging Objects ................................................................................. 41
4 Standards for names specified in all examples ............................................................................. 43
5 Conclusion .................................................................................................................................... 43
6 Resources ...................................................................................................................................... 44
7 About the authors.......................................................................................................................... 44
1 Introduction
You can extend the standard features of Web Content Management using the product’s API and
JavaServer Pages™ (JSP) files. The Lotus Web Content Management API is focused on
processing the content programmatically and is an alternative way to access a Web Content
Management site. It allows content and other Web Content Management objects to be created,
edited, deleted, and rendered entirely by using Java™ code.
Additionally, you can always manipulate your site and integrate Web Content Management with
other applications in a way that was not previously possible using these APIs.
There are many functions that can be achieved using Web Content Management APIs; here are a
few examples:
-2-
• Content search (similar to the Menu Component search criteria but using item parameters
as ids).
• The ability to retrieve the following items from searches, (but NOT as an item):
• The ability to approve or reject content items in a workflow stage. Other item-types do not
support this function.
The Javadocs should be reviewed for a complete set of the features available using the API. The
Javadoc HTML files are located under the
was_profile_root\installedApps\nodename\wcm.ear\ilwwcm.war\webinterface\ folder.
All the samples provided below can be picked directly and used or incorporated into your code, to
achieve the required result based on the various scenarios you must carry out in your
environment. We have added comments (in italic font) on most of the lines, to make it easier to
understand the code and flow.
NOTE: For further information, refer to the IBM Lotus Web Content Management API information
center topic, from which the material in this Introduction section is excerpted.
-3-
2 Assumptions and considerations
Before beginning, note the following:
• The user must have access to all the objects mentioned in the code samples below.
• The Javadoc for moveToLibrary states "This method moves non-hierarchical or root items to
another library".
• Refer to Section 4, “Standards for names specified in all examples,” in this document for an
explanation of the standards used in the code samples.
This essentially returns an iterator of IDs of all objects of the given type with the specified name.
<%
// retrieve repository
Repository repository = WCM_API.getRepository();
-4-
String siteName = new String("Site");
if (siteIterator.hasNext()){
out.println("Site found : " + siteName + "<br>");
}else {
out.println("Could not find site : " + siteName + "<br>");
}
if (siteAreaIterator.hasNext()){
out.println("Sitearea found : " + siteArea + "<br>");
}else {
out.println("Could not find Sitearea : " + siteArea + "<br>");
}
if (contentIterator.hasNext()){
out.println("Content found : " + contentName + "<br>");
}else {
out.println("Could not find Content : " + contentName + "<br>");
}
-5-
// find authoring template by name
DocumentIdIterator authoringTemplateIterator =
workspace.findByName(DocumentTypes.AuthoringTemplate,authoringTemplateName);
if (authoringTemplateIterator.hasNext()){
out.println("Authoring template found : " + authoringTemplateName + "<br>");
}else {
out.println("Could not find Authoring template: " + authoringTemplateName + "<br>");
}
if (presentationTemplateIterator.hasNext()){
out.println("Presentation template found : " + presentationTemplateName + "<br>");
}else {
out.println("Could not find Presentation template: " + presentationTemplateName + "<br>");
}
if (libraryComponentIterator.hasNext()){
out.println("Library component found : " + libraryComponentName + "<br>");
}else {
out.println("Could not find Library component: " + libraryComponentName + "<br>");
}
-6-
DocumentIdIterator workflowIterator =
workspace.findByName(DocumentTypes.Workflow,workflowName);
if (workflowIterator.hasNext()){
out.println("Workflow found : " + workflowName + "<br>");
}else {
out.println("Could not find Workflow: " + workflowName + "<br>");
}
if (workflowStageIterator.hasNext()){
out.println("Workflow Stage found : " + workflowStageName + "<br>");
}else {
out.println("Could not find Workflow Stage: " + workflowStageName + "<br>");
}
if (taxonomyIterator.hasNext()){
out.println("Taxonomy found : " + taxonomyName + "<br>");
}else {
out.println("Could not find Taxonomy: " + taxonomyName + "<br>");
}
-7-
DocumentIdIterator categoryIterator =
workspace.findByName(DocumentTypes.Category,categoryName);
if (categoryIterator.hasNext()){
out.println("Category Found : " + categoryName + "<br>");
}else {
out.println("Could not find Category : " + categoryName + "<br>");
}
%>
<%
// retrieve repository
Repository repository = WCM_API.getRepository();
// set library
workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("WebContent"));
if(siteIterator.hasNext()){
while(siteIterator.hasNext())
{
siteId = siteIterator.nextId();
out.println("Found Site : " + siteId.getName() + "<br>");
}
-8-
} else {
out.println("Could not find any Site");
}
if(siteAreaIterator.hasNext()){
while(siteAreaIterator.hasNext())
{
siteAreaId = siteAreaIterator.nextId();
out.println("Found Sitearea : " + siteAreaId.getName() + "<br>");
}
} else {
out.println("Could not find any Sitearea");
}
if(contentIterator.hasNext()){
while(contentIterator.hasNext())
{
contentId = contentIterator.nextId();
out.println("Found Content : " + contentId.getName() + "<br>");
}
} else {
out.println("Could not find any Content");
}
if(authoringTemplateIterator.hasNext()){
while(authoringTemplateIterator.hasNext())
-9-
{
authoringTemplateId = authoringTemplateIterator.nextId();
out.println("Found Authoring Template : " + authoringTemplateId.getName() +
"<br>");
}
} else {
out.println("Could not find any Authoring Template");
}
if(presentationTemplateIterator.hasNext()){
while(presentationTemplateIterator.hasNext())
{
presentationTemplateId = presentationTemplateIterator.nextId();
out.println("Found Presentation Template : " + presentationTemplateId.getName()
+ "<br>");
}
} else {
out.println("Could not find any Presentation Template");
}
if(libraryComponentIterator.hasNext()){
while(libraryComponentIterator.hasNext())
{
libraryComponentId = libraryComponentIterator.nextId();
out.println("Found Library component : " + libraryComponentId.getName() +
"<br>");
}
} else {
out.println("Could not find any Library component");
}
- 10 -
// find all workflows
DocumentIdIterator workflowIterator = workspace.findByType(DocumentTypes.Workflow);
DocumentId workflowId = null;
if(workflowIterator.hasNext()){
while(workflowIterator.hasNext())
{
workflowId = workflowIterator.nextId();
out.println("Found Workflow : " + workflowId.getName() + "<br>");
}
} else {
out.println("Could not find any Workflow");
}
if(workflowStageIterator.hasNext()){
while(workflowStageIterator.hasNext())
{
workflowStageId = workflowStageIterator.nextId();
out.println("Found Workflow Stage : " + workflowStageId.getName() + "<br>");
}
} else {
out.println("Could not find any Workflow Stage");
}
if(taxonomyIterator.hasNext()){
while(taxonomyIterator.hasNext())
{
taxonomyId = taxonomyIterator.nextId();
out.println("Found Taxonomy : " + taxonomyId.getName() + "<br>");
}
} else {
out.println("Could not find any Taxonomy");
- 11 -
}
if(categoryIterator.hasNext()){
while(categoryIterator.hasNext())
{
categoryId = categoryIterator.nextId();
out.println("Found Category : " + categoryId.getName() + "<br>");
}
} else {
out.println("Could not find any Category");
}
%>
workspace.findContentByAuthoringTemplate
workspace.findContentByCategory
workspace.findContentByPath
workspace.findContentByWorkflowStage
workspace.findContentModifiedSince
workspace.findContentModifiedBetween
<%
// retrieve repository
Repository repository = WCM_API.getRepository();
// Set library
workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("WebContent"));
- 12 -
DocumentIdIterator contentIterator = null;
DocumentId contentId = null;
if (authoringTemplateIterator.hasNext()){
if(contentIterator.hasNext()){
contentId = contentIterator.nextId();
out.println("List of Content uses " + authoringTemplateName );
while(contentId!=null) {
out.println( "<BR>" + contentId.getName());
contentId = contentIterator.nextId();
}
} else {
out.println("Could not find any Content that uses " + authoringTemplateName );
}
}else {
out.println("Could not find Authoring Template: " + authoringTemplateName + "<br>");
}
// define category
String categoryName = new String("Category");
DocumentId categoryId = null;
- 13 -
if (categoryIterator.hasNext()){
out.println("Category found : " + categoryName + "<br>");
categoryId = categoryIterator.nextId();
if(contentIterator.hasNext()){
out.println("List of Content uses " + categoryName );
while(contentIterator.hasNext()) {
contentId = contentIterator.nextId();
out.println( "<BR>" + contentId.getName());
}
} else {
out.println("Could not find any Content that uses " + categoryName );
}
}else {
out.println("Could not find Category: " + categoryName + "<br>");
}
if (contentIterator.hasNext()){
contentId = contentIterator.nextId();
out.println("Content found on Path : " + contentPath + " : Content name : " +
contentId.getName() + "<br>");
}else {
out.println("Could not find Content on Path : " + contentPath + " <BR>");
}
- 14 -
DocumentIdIterator workflowStageIterator =
workspace.findByName(DocumentTypes.WorkflowStage,workflowStageName);
if (workflowStageIterator.hasNext()){
if(contentIterator.hasNext()){
contentId = contentIterator.nextId();
out.println("List of contents under Workflow Stage " + workflowStageName );
while(contentId!=null) {
out.println( "<BR>" + contentId.getName());
contentId = contentIterator.nextId();
}
} else {
out.println("Could not find any content under Workflow Stage " +
workflowStageName );
}
}else {
out.println("Could not find Workflow Stage: " + workflowStageName + "<br>");
}
if(contentIterator.hasNext()){
contentId = contentIterator.nextId();
out.println("List of contents modified since " + startDate );
while(contentId!=null) {
out.println( "<BR>" + contentId.getName());
contentId = contentIterator.nextId();
}
} else {
- 15 -
out.println("Could not find any content modified since " + startDate );
}
%>
// find all the contents modified between start date and end date
contentIterator = workspace.findContentModifiedBetween(startDate,endDate);
if(contentIterator.hasNext()){
contentId = contentIterator.nextId();
out.println("List of contents modified between " + startDate + "and" + endDate );
while(contentId!=null) {
out.println( "<BR>" + contentId.getName());
contentId = contentIterator.nextId();
}
} else {
out.println("Could not find any content modified between " + startDate + "and" +
endDate );
}
%>
The ContentSearch method behaves in a manner similar to the Menu Component. If Site Areas
have been specified, then all the ancestor and descendant Site Areas are also included in the
search.
This performs an "or" search, not an "and" search. This means that a search for two different
Categories and a Content Template will return content profiled with at least one of each profile
type (one Category and one Template), not just content that matches all the parameters. Content
that matches only one criteria type (Template only) will not be returned.
- 16 -
Note that the order of results is not guaranteed, and all parameters are optional except
matchAllKeys, the last parameter.
<%
// retrieve repository
Repository repository = WCM_API.getRepository();
// Set library
workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("WebContent"));
DocumentIdIterator authoringTemplateIterator =
workspace.findByName(DocumentTypes.AuthoringTemplate,authoringTemplateName);
if (authoringTemplateIterator.hasNext()){
authoringTemplateId = authoringTemplateIterator.nextId();
out.println("Authoring Template found : " + authoringTemplateName + "<br>");
}else {
out.println("Could not find Authoring Template: " + authoringTemplateName + "<br>");
}
// define siteare
String siteArea = new String("SiteArea");
DocumentIdIterator siteAreaIterator =
workspace.findByName(DocumentTypes.SiteArea,siteArea);
if (siteAreaIterator.hasNext()){
- 17 -
siteAreaId = siteAreaIterator.nextId();
out.println("Sitearea Found : " + siteArea + "<br>");
}else {
out.println("Could not find Sitearea : " + siteArea + "<br>");
}
// define category
String categoryName = new String("Category");
if (categoryIterator.hasNext()){
categoryId = categoryIterator.nextId();
out.println("Category Found : " + categoryName + "<br>");
}else {
out.println("Could not find Category : " + categoryName + "<br>");
}
// define keywords
String[] keywords = new String[]{"Keyword"};
// search all the contents based on authoring template , sitearea , category and keywords
if(contentIterator.hasNext()){
contentId = contentIterator.nextId();
while(contentId!=null)
{
out.println("Found Content : " + contentId.getName() + "<br>");
contentId = contentIterator.nextId();
}
} else {
out.println("Could not find any Content using the contentSearch Method");
}
%>
- 18 -
use the appropriate code provided in listing 5, which demonstrates only the creation of a new site,
setting its name, title, description, and then saving it to the repository.
We use workspace.createSite to achieve this, which returns the new Site object.
<%
// retrieve repository
Repository repository = WCM_API.getRepository();
// Set library
workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("WebContent"));
newSite.setName("NewSite");
newSite.setTitle("NewSite");
if (saveMessage.length==0){
out.println("Could not create new Site..<BR>");
}else{
out.println("New Site created successfully.");
}
%>
Listing 6 demonstrates only creating a new Site Area, setting its name, title, description, and
saving it to the repository. We use workspace.createSiteArea here, which creates a new Site
- 19 -
Area under the given parent. The parent can be a Site or a Site Area, and the method returns the
new Site Area object.
// retrieve repository
Repository repository = WCM_API.getRepository();
// Set library
workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("WebContent"));
SiteArea newSiteArea =
workspace.createSiteArea((DocumentId)parentSite.getId(),siblingId,ChildPosition.END);
newSiteArea.setName("NewSiteArea");
newSiteArea.setTitle("NewSiteArea");
newSiteArea.setDescription("New Sitearea Created using WCM API
if (saveMessage.length==0) {
out.println (" <BR> Created new Sitearea under " + parentSiteName );
}
} else {
out.println (" <BR> Could not find parent Site " + parentSiteName + ". Could not create a
new Sitearea." );
- 20 -
}
%>
The code also configures the Workflow while saving the content. We use
workspace.createContent for this purpose, which returns a new content object based on the
specified Authoring Template. The API code can be changed based on your requirements.
<%
// retrieve repository
Repository repository = WCM_API.getRepository();
// Set library
workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("WebContent"));
// define workflow
String workflowName = new String("Workflow");
- 21 -
if (authoringTemplateIterator.hasNext()){
authoringTemplateId = authoringTemplateIterator.nextId();
out.println("Authoring Template found : " + authoringTemplateName + "<br>");
}else {
out.println("Could not find Authoring Template: " + authoringTemplateName + "<br>");
}
if (siteAreaIterator.hasNext()){
parentSiteAreaId = siteAreaIterator.nextId();
out.println("Sitearea Found : " + parentSiteAreaName + "<br>");
}else {
out.println("Could not find Sitearea : " + parentSiteAreaName + "<br>");
}
if (workflowIterator.hasNext()){
workflowId = workflowIterator.nextId();
out.println("Workflow found : " + workflowName + "<br>");
}else {
out.println("Could not find Workflow: " + workflowName + "<br>");
}
if (saveMessage.length==0) {
out.println (" <BR> Created new Content under " + parentSiteAreaName );
}
- 22 -
}else {
out.println ("Could not create new content");
}
%>
We use workspace.createContentLink to achieve this, which returns a new Content Link object.
The code in listing 8 assumes that the Content Link is not present under the Site Area.
<%
// retrieve repository
Repository repository = WCM_API.getRepository();
// Set library
workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("WebContent"));
// define content
String contentName = new String("Content");
if (contentIterator.hasNext())
contentId = contentIterator.nextId();
- 23 -
// find sitearea by name
DocumentIdIterator parentSiteAreaIterator =
workspace.findByName(DocumentTypes.SiteArea,parentSiteArea);
if (parentSiteAreaIterator.hasNext())
parentSiteAreaId = parentSiteAreaIterator.nextId();
%>
The code in listing 9 demonstrates only creation, setting the name, title, description, and then
saving them in the Web Content Management repository. The code can be directly used to create
a File Component, Image Component, and Rich Text Component:
workspace.createFileComponent
workspace.createImageComponent
workspace.createRichTextComponent
<%
// retrieve repository
Repository repository = WCM_API.getRepository();
- 24 -
// Set library
workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("WebContent"));
LibraryRichTextComponent libraryRichTextComponent =
workspace.createRichTextComponent();
libraryRichTextComponent.setName("NewRichTextComponent");
libraryRichTextComponent.setTitle("NewRichTextComponent");
libraryRichTextComponent.setDescription("New Rich text component created using API");
saveMessage = workspace.save((Document)libraryRichTextComponent);
out.println ("<BR> New Rich text component created :" +
libraryRichTextComponent.getName());
%>
- 25 -
Listing 10. Example code to create a new Taxonomy and new Category
<%@ page import="com.ibm.workplace.wcm.api.*"%>
<%@ page import="java.util.*"%>
<%
// retrieve repository
Repository repository = WCM_API.getRepository();
// Set library
workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("WebContent"));
%>
- 26 -
Listing 11. Example code to create and cancel drafts
<%@ page import="com.ibm.workplace.wcm.api.*"%>
<%@ page import="java.util.*"%>
<%
// retrieve repository
Repository repository = WCM_API.getRepository();
// Set library
workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("WebContent"));
if (contentIterator.hasNext()){
contentId = contentIterator.nextId();
Content content = (Content) workspace.getById(contentId);
// cancel draft
if (content. hasDraft()) {
draftContent = content.cancelDraftDocument();
out.println("Draft cancled for " + contentName);
} else {
out.println("Draft does not exist for content : " + contentName);
}
}
%>
- 27 -
Scenario 12: Moving content to Next Stage of a Workflow, Restarting
the Workflow, setting another Workflow on specific content
You can move content to the next Workflow stage, restart the Workflow, and set another workflow
on specific content. You can use the code in listing 12 to move content from the draft stage to the
publish stage, restart the workflow, and to set another Workflow on a specific content item.
<%
// retrieve repository
Repository repository = WCM_API.getRepository();
// Set library
workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("WebContent"));
if (contentIterator.hasNext()){
contentId = contentIterator.nextId();
content = (Content) workspace.getById(contentId);
// below code may not be required if the next workflow stage does not exist
// restarting workflow
content.restartWorkflow();
- 28 -
out.println("<BR> Workflow restarted for content " + contentName);
}
if (workflowIterator.hasNext())
newWorkflowId = workflowIterator.nextId();
%>
Note that it’s not enough to specify only the ContentComponent to be rendered; the path to the
item containing the ContentComponent must also be specified in the RenderingContext.
The code in listing 13 demonstrates rendering Content, Content component, and the Library
component. You can always add or remove more components per your requirements.
<%
// retrieve repository
Repository repository = WCM_API.getRepository();
- 29 -
// Set library
workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("WebContent"));
if(renderingContext!=null) {
renderingContext.setRenderedContent(contentPath);
out.println("Rendering content " + contentPath );
out.println ("<BR>" + workspace.render(renderingContext));
} else {
out.println("Could not render content");
}
if (contentIterator.hasNext()){
content = (Content) workspace.getById(contentIterator.nextId());
component = content.getComponent("MyComponent");
}
- 30 -
DocumentIdIterator siteAreaIterator =
workspace.findByName(DocumentTypes.SiteArea,siteAreaName);
if (siteAreaIterator.hasNext())
siteArea = (SiteArea) workspace.getById(siteAreaIterator.nextId());
DocumentIdIterator libraryComponentIterator =
workspace.findByName(DocumentTypes.LibraryComponent,libraryComponentName);
if (libraryComponentIterator.hasNext()){
LibraryComponent libraryComponent = (LibraryComponent)
workspace.getById(libraryComponentIterator.nextId());
renderingContext.setRenderedContent(contentPath);
out.println("<BR> Rendering library component " + libraryComponentName );
out.println ("<BR>" + workspace.render(renderingContext,libraryComponent));
} else {
out.println("<BR> Could not render Library component" + libraryComponentName);
}
%>
To copy the Site Area, you can use the workspace.copySiteFrameworkDocument method to
replace the workspace.moveSiteFrameworkDocument method, using the same code below.
- 31 -
Listing 14. Example code to move or copy Site Area
<%@ page import="com.ibm.workplace.wcm.api.*"%>
<%@ page import="java.util.*"%>
<%
// retrieve repository
Repository repository = WCM_API.getRepository();
// define sibling id
DocumentId siblingId = null;.
DocumentId newParentsiteId = null;
if (siteAreaIterator.hasNext()){
siteAreaId = siteAreaIterator.nextId();
out.println("Sitearea Found : " + siteArea + "<br>");
}else {
out.println("Could not find Sitearea : " + siteArea + "<br>");
}
// target library. Not required while moving Sitearea to the same library
workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("Target Library"));
if (siteIterator.hasNext()){
newParentsiteId = siteIterator.nextId();
out.println("New parent site found : " + newParentSite + "<br>");
- 32 -
}else {
out.println("Could not find new parent site : " + newParentSite + "<br>");
}
out.println(" Moving Sitearea <b> " + siteArea + "</b> to new parent site <b>" +
newParentSite + "</b><br>");
workspace.moveSiteFrameworkDocument(siteAreaId,newParentsiteId,siblingId,ChildPosit
ion.START);
out.println(" Moved Sitearea <b>" + siteArea + " </b> to new parent site <b>" +
newParentSite + "</b><br>");
}else{
out.println(" Moving Sitearea <b> " + siteArea + "</b> to new parent site <b>" +
newParentSite + "</b> failed <br>");
}
%>
To copy the Site Area, you can use the workspace.copySiteFrameworkDocument method to
replace the workspace.moveSiteFrameworkDocument method, using the same code below.
<%
// retrieve repository
Repository repository = WCM_API.getRepository();
- 33 -
String newParentSitearea = new String("SiteArea");
// sibling id
DocumentId siblingId = null;
DocumentId contentId = null;
DocumentId newParentsiteareaId = null;
if (contentIterator.hasNext()){
contentId = contentIterator.nextId();
out.println("Content Found : " + contentName + "<br>");
}else {
out.println("Could not find Content : " + contentName + "<br>");
}
// set target library. Not required when moving content to the same library
workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("Target Library"));
if (newParentSiteareaIterator.hasNext()){
newParentsiteareaId = newParentSiteareaIterator.nextId();
out.println("New parent Sitearea found : " + newParentSitearea + "<br>");
}else {
out.println("Could not find new parent Sitearea : " + newParentSitearea + "<br>");
}
out.println(" Moving content <b> " + contentName + "</b> to new parent Sitearea <b>" +
newParentSitearea + "</b><br>");
- 34 -
out.println(" Moved content <b>" + contentName + " </b> to new parent Sitearea <b>" +
newParentSitearea + "</b><br>");
}else{
out.println(" Moving content <b> " + contentName + "</b> to new parent Sitearea <b>" +
newParentSitearea + "</b> failed.<br>");
}
%>
The code in listing 16 shows how we can achieve this for Authoring Templates, Presentation
Templates, Library components, Workflows, Workflow Stages, Sites, and Taxonomies.
Listing 16. Example code to move or copy root items to another library
<%@ page import="com.ibm.workplace.wcm.api.*"%>
<%@ page import="java.util.*"%>
<%
// retrieve repository
Repository repository = WCM_API.getRepository();
- 35 -
// find authoring template by name
DocumentIdIterator authoringTemplateIterator =
workspace.findByName(DocumentTypes.AuthoringTemplate,authoringTemplateName);
if (authoringTemplateIterator.hasNext()){
DocumentId authoringTemplateId = authoringTemplateIterator.nextId();
out.println("Authoring Template found : " + authoringTemplateName + "<br>");
out.println(" Moving Authoring Template <b> " + authoringTemplateName + "</b> to new
library <b> Target Library </b><br>");
}else {
out.println("Could not find Authoring Template: " + authoringTemplateName + "<br>");
}
if (presentationTemplateIterator.hasNext()){
DocumentId presentationTemplateId = presentationTemplateIterator.nextId();
out.println("Presentation Template found : " + presentationTemplateName + "<br>");
out.println(" Moving Presentation Template <b> " + presentationTemplateName + "</b> to
new library <b> Target Library </b><br>");
}else {
out.println("Could not find Presentation Template: " + presentationTemplateName + "<br>");
}
- 36 -
// define library component
String libraryComponentName = new String("LibraryComponent");
if (libraryComponentIterator.hasNext()){
DocumentId libraryComponentId = libraryComponentIterator.nextId();
out.println("Library Component found : " + libraryComponentName + "<br>");
out.println(" Moving Library Component <b> " + libraryComponentName + "</b> to new
library <b> Target Library </b><br>");
}else {
out.println("Could not find Library Component: " + libraryComponentName + "<br>");
}
// define workflow
String workflowName = new String("Workflow");
if (workflowIterator.hasNext()){
DocumentId workflowId = workflowIterator.nextId();
out.println("Workflow found : " + workflowName + "<br>");
out.println(" Moving Workflow <b> " + workflowName + "</b> to new library <b> Target
Library </b><br>");
}else {
out.println("Could not find Workflow: " + workflowName + "<br>");
}
- 37 -
// ************************ Move Site example ******************************
if (siteIterator.hasNext()){
out.println("Site found : " + siteName + "<br>");
out.println(" Moving Site <b> " + siteName + "</b> to new library <b> Target Library
</b><br>");
siteId = siteIterator.nextId();
if (workflowStageIterator.hasNext()){
DocumentId workflowStageId = workflowStageIterator.nextId();
out.println("Workflow Stage found : " + workflowStageName + "<br>");
out.println(" Moving Workflow Stage<b> " + workflowStageName + "</b> to new library
<b> Target Library </b><br>");
}else {
out.println("Could not find Workflow Stage: " + workflowStageName + "<br>");
- 38 -
}
// define taxonomy
String taxonomyName = new String("Taxonomy");
if (taxonomyIterator.hasNext()){
DocumentId taxonomyId = taxonomyIterator.nextId();
out.println("Taxonomy found : " + taxonomyName + "<br>");
out.println(" Moving Taxonomy <b> " + taxonomyName + "</b> to new library <b>
Target Library </b><br>");
}else {
out.println("Could not find Taxonomy: " + taxonomyName + "<br>");
}
%>
Note that the example below moves a category to another taxonomy; you can also move the
category to another parent category.
<%
// retrieve repository
Repository repository = WCM_API.getRepository();
- 39 -
// get workspace for current user
Workspace workspace = repository.getWorkspace(request.getUserPrincipal());
// Set library
workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("WebContent"));
DocumentIdIterator categoryIterator =
workspace.findByName(DocumentTypes.Category,categoryName);
if (categoryIterator.hasNext()){
categoryId = categoryIterator.nextId();
out.println("Category Found : " + categoryName + "<br>");
}else {
out.println("Could not find Category : " + categoryName + "<br>");
}
if (taxonomyIterator.hasNext()){
taxonomyId = taxonomyIterator.nextId();
out.println("Taxonomy found : " + newTaxonomy + "<br>");
}else {
out.println("Could not find Taxonomy: " + newTaxonomy + "<br>");
}
out.println(" Moving Category <b> " + categoryName + "</b> to new parent taxonomy
<b>" + newTaxonomy + "</b><br>");
// move category
- 40 -
workspace.moveCategory(categoryId,taxonomyId);
out.println(" Moved Category <b>" + categoryName + " </b> to new parent taxonomy <b>"
+ newTaxonomy + "</b><br>");
}else{
out.println(" Moving Category <b> " + categoryName + "</b> to new parent taxonomy
<b>" + newTaxonomy + "</b> failed <br>");
}
%>
We can also purge (permanently delete) the object from the repository. The code in listing 18
demonstrates deleting as well as purging a content item and as well as a Library Component.
To delete a Site / Site Area / Taxonomy, you must delete all the children prior to deleting the Sites
/ Site Areas / and Taxonomies.
<%
// retrieve repository
Repository repository = WCM_API.getRepository();
// Set library
workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("WebContent"));
// define content
String contentName = new String("Content");
String[] deleteMessage = new String[1];
- 41 -
if (contentIterator.hasNext()){
contentId = contentIterator.nextId();
// delete content
deleteMessage = workspace.delete(contentId);
out.println("Content deleted :" + deleteMessage);
// purge content
deleteMessage = workspace.purge(contentId);
out.println("<BR> Content purged:" + deleteMessage);
} else {
out.println("Could not delete content :" + contentName);
}
if (libraryComponentIterator.hasNext()){
libraryComponentId = libraryComponentIterator.nextId();
- 42 -
}
%>
A few standards have been set while writing the code for the API samples provided. These may
need to be modified and entered with values that are appropriate based on the specifics of the
Web Content Management artifacts on your system:
WebContent. This is taken as the standard library that we are setting in all scenarios
Site. Defined Site Name to be searched or the name already set for a site
NewSite. Name of new site created
SiteArea. Defined Site Area
NewSiteArea. Name of new site area created
Content. Defined Content Name
NewContent. Name of new content created
PublishedContent. Name of the published content
AuthoringTemplate. Defined Authoring Template
PresentationTemplate. Defined Presentation Template
LibraryComponent. Defined library component name
MyComponent. Defined component name
NewImageComponent. Name of new Image Component created
NewRichTextComponent. Name of new Rich Text Component created
Workflow. Defined Workflow name
WorkflowStageName. Defined Workflow Stage name
NewFileComponent. Name of new file resource created
Taxonomy. Defined Taxonomy name
NewParentTaxonomy. Name of new Taxonomy created
Category. Defined Category name to be searched
NewCategory. Name of new category created
Keyword. Defined Keyword
"/Web content/Site/SiteArea/Content. Content path
Source Library. Name of the Source Library defined
Target Library. Name of the Target Library defined
01/01/2008. Sample date selected for Start date
12/31/2009. Sample date selected for End date
5 Conclusion
This document has presented detailed code samples that you can use directly (copying/pasting)
to implement various scenarios using Web Content Management 6.1.0.x APIs, to extend usage of
Web Content Management. Hopefully we have targeted the most common issues faced by
customers in implementing and using APIs.
- 43 -
6 Resources
• IBM WebSphere Portal Version 6.1 Information Center: Web Content Management Edition:
http://publib.boulder.ibm.com/infocenter/wcmdoc/v6r0/index.jsp?topic=/com.ibm.lotus.wcm.do
c/wcm
• WebSphere Portal and Lotus Web Content Management product documentation page:
http://www.ibm.com/developerworks/websphere/zones/portal/proddoc.html
Soumitra Limaye is the Team Lead for the WebSphere Web Content Management team, working
out of IBM’s Pune, India, facility. He worked extensively with UNIX (admin-scripting) and other
Portal servers such as BEA WebLogic prior to joining IBM in 2006. Soumitra is a Web Content
Management certified developer and holds a degree in Computer Engineering. He can be
reached at soumitra.limaye@in.ibm.com
Trademarks
• IBM, Lotus, Web Content Management, and WebSphere are trademarks or registered
trademarks of IBM Corporation in the United States, other countries, or both.
• Java and all Java-based trademarks and logos are trademarks or registered trademarks of Sun
Microsystems, Inc. in the United States, other countries, or both.
• Other company, product, and service names may be trademarks or service marks of others.
- 44 -