Wednesday, April 15, 2009

Creating Content using WCM API

This time will tell how you can create a content using WCM API. Before I want you to see my sample code I would like to show the WCM API method to get what is required to create content into Web content management through WCM API.

JavaDoc description for Create Content method in WCM API:

createContent (In API JavaDoc)

Content createContent(DocumentId authoringTemplateId,
DocumentId parentSiteAreaId,
DocumentId siblingId,
int position)
throws DocumentCreationException,

Creates a new Content object, based on an AuthoringTemplate in the parent SiteArea. The template ID that is specified must be for a template that already exists in the WCM system.

If the ChildPosition is ChildPosition.PREVIOUS or ChildPosition.NEXT, then the siblingId parameter must be specified. If it is not, then an IllegalArgumentException will be thrown. If the ChildPosition is ChildPosition.START or ChildPosition.END then the siblingId parameter, if it is not null, will be ignored.

authoringTemplateId - the authoring template ID
parentSiteAreaId - the parent site area ID
siblingId - the DocumentId of the sibling document, if any. May be null, according to the rules stated
position - the position of the child (docId)

a new Content object based on the specified template

DocumentCreationException - if the object cannot be created
AuthorizationException - if the user does not have access
IllegalDocumentTypeException - if specified template is not an AuthoringTemplate, the parentSiteArea is not a SiteArea, or the sibling is not a Content or ContentLink.


String userName = USER_BALA;
String password = PASS_BALA;
String wcmLibraryName= LBRY_Test;
String contentName = CNTNT_Test;
String contentTitle = CNTNT_Test_Title;
String siteArea= SA_Test;
String authoringTemplate= AT_Test;

// Getting workspace object.
Workspace oWorkspace = WCM_API.getRepository().getWorkspace(username, password);

// Setting current document library

DocumentId oDocumentIdContent = Util.getDocumentId(oWorkspace, DocumentTypes.
Content, contentName);

// Check whether content is already existing or not
if( oDocumentIdContent==null){
* Getting Site Area document id.
DocumentId oDocumentIdSiteArea = Util.getDocumentId(oWorkspace, DocumentTypes.
SiteArea, siteArea);

// Get the authoring template document id.
DocumentId oDocumentIdAuthoringTemplate = Util.getDocumentId(oWorkspace, DocumentTypes.AuthoringTemplate, authoringTemplate);

// Creating content here ...
oContent = oWorkspace.createContent(oDocumentIdAuthoringTemplate, oDocumentIdSiteArea, null, ChildPosition.END);
oContent.setTitle(contentTitle );

String errors[] =;
for(int x=0;x LessThan errors.length;x++) {
out.println("Errors while saving the content into workspace "+errors[x]);


public static DocumentId getDocumentId(Workspace oWorkspace, DocumentType oDocumentType, String fileName) throws Exception{
DocumentId oDocumentID = null;
DocumentIdIterator oDocumentIdIteratorContents = oWorkspace.findByName(oDocumentType,fileName);
oDocumentID= (DocumentId);
return oDocumentID;


I hope this will give clear idea about how to add a content into IBM Web Content Management System using WCM API.

Monday, April 13, 2009

Tracing errors while saving content in to Workspace object using WCM API

This time would like to share my experience with issues which I faced & how I solved that while working with WCM API.
I have written code to upload an image into content management system using WCM API.
Due to missing of file extension I could not able to upload an image into content management system using WCM API.

The following code was very useful to find errors while saving a content into workspace object..

String errors[] =;
for(int x=0;x LessThan errors.length;x++)
{System.out.println("Errors while saving content into workspace object using WCM API"+errors[x]);

I hope this will help for the people who works with WCM API to write data into content management system.

Thursday, March 19, 2009

Navigating to other page in Portal from any portlet

The following steps will be used to navigate control from any portlet to any page/ any portlet in other page. Also this can be used to pass parameter to other portlet.

1> Keep the wp[1].l2.urlhelper.jar file under WEB-INF/lib folder.
2> Add the following code in your JSP to achieve the same.

String homeURL = PortletURLHelper.generateUrl(PAGE_UNIQUE_NAME, Portlet Name, null, true, renderRequest, renderResponse);

Use the value of homeURL in href attribute.
3> Download the jar from the following location.