Friday, December 17, 2010

Creating a New Site Area using the IBM WCM API

<%@ page import="com.ibm.workplace.wcm.api.*"%>
<%@ page import="java.util.*"%>
<% // retrieve repository Repository repository = WCM_API.getRepository(); // get workspace for current user Workspace workspace = repository.getWorkspace(request.getUserPrincipal()); // Set library workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("WebContent")); DocumentId documentId = null; Site parentSite = null; String parentSiteName = "Site"; DocumentId siblingId = null; // find parent site DocumentIdIterator siteIterator = workspace.findByName(DocumentTypes.Site,parentSiteName); if (siteIterator.hasNext()){ documentId = siteIterator.nextId(); parentSite = (Site) workspace.getById(documentId); // create new sitearea SiteArea newSiteArea = workspace.createSiteArea((DocumentId)parentSite.getId(),siblingId,ChildPosition.END); newSiteArea.setName("NewSiteArea"); newSiteArea.setTitle("NewSiteArea"); newSiteArea.setDescription("New Sitearea Created using WCM API String[] saveMessage = workspace.save((Document)newSiteArea); if (saveMessage.length==0) { out.println ("
Created new Sitearea under " + parentSiteName );
}
} else {
out.println ("
Could not find parent Site " + parentSiteName + ". Could not create a
new Sitearea." );
}
%>

No comments:

Post a Comment