<%@ page import="com.ibm.workplace.wcm.api.*"%>
<%@ page import="java.util.*"%>
<%
// retrieve repository
Repository repository = WCM_API.getRepository();
//Creating a workspace
Workspace workspace = repository.getWorkspace("username","password");
// Set library
workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("LibraryName"));
// define authoring template
String authoringTemplateName = new String("Authoring Template");
// define parent sitearea
String parentSiteAreaName = new String("SiteArea Name");
// define workflow
String workflowName = new String("Workflow Name");
DocumentId authoringTemplateId = null;
DocumentId parentSiteAreaId = null;
DocumentId siblingId = null;
DocumentId workflowId = null;
// find authoring template by name
DocumentIdIterator authoringTemplateIterator = workspace.findByName(DocumentTypes.AuthoringTemplate,authoringTemplateName);
if (authoringTemplateIterator.hasNext()){
authoringTemplateId = authoringTemplateIterator.nextId();
System.out.println("Authoring Template found : " + authoringTemplateName + "
");
}else {
out.println("Could not find Authoring Template: " + authoringTemplateName + "
");
}
// find sitearea by name
DocumentIdIterator siteAreaIterator = workspace.findByName(DocumentTypes.SiteArea,parentSiteAreaName );
if (siteAreaIterator.hasNext()){
parentSiteAreaId = siteAreaIterator.nextId();
out.println("Sitearea Found : " + parentSiteAreaName + "
");
}else {
out.println("Could not find Sitearea : " + parentSiteAreaName + "
");
}
// find workflow by name
DocumentIdIterator workflowIterator = workspace.findByName(DocumentTypes.Workflow,workflowName);
if (workflowIterator.hasNext()){
workflowId = workflowIterator.nextId();
out.println("Workflow found : " + workflowName + "
");
}else {
out.println("Could not find Workflow: " + workflowName + "
");
}
if((authoringTemplateId!=null) && (parentSiteAreaId!=null) && (workflowId!=null)){
// create new content
Content newContent = workspace.createContent(authoringTemplateId,parentSiteAreaId,siblingId,ChildPosition.END);
newContent.setName("NewContent");
newContent.setTitle("NewContent");
newContent.setDescription("New Content created using WCM API"); newContent.setWorkflowId(workflowId);
workspace.save(newContent);
DocumentIdIterator contentIterator = workspace.findByName(DocumentTypes.Content,"Almost there");
DocumentId contentId = null;
if(contentIterator.hasNext()) {
contentId = contentIterator.nextId();
}
//Get the content using getById
Content content = (Content)workspace.getById(contentId);
//Approving the Content
newContent.nextWorkflowStage();
System.out.println("Content page '" + parentSiteAreaName + newContent + "' moved to the approved state
");
String[] saveMessage = workspace.save((Document)newContent);
workspace.save(content);
if (saveMessage.length==0) {
out.println ("
Created new Content under " + parentSiteAreaName );
}
}else {
out.println ("Could not create new content");
}
%>
Subscribe to:
Post Comments (Atom)
Generate reports from Opportunities using a Visualforce Page in Salesforce
Step 1: Create a Visualforce Page Go to the Setup menu in Salesforce. Search for "Visualforce Pages" in the Quick Find box and c...
-
Inline Editing So now I have tested the inline editing jsp done by David De Vos.Simply brilliant! Really offers you the ability to offe...
-
It is sometimes taken for granted that we need to reconcile permissions or permission sets. It is crucial to ensure that we can audit our e...
Nice tutorial. Thanks for this.
ReplyDeleteCould you also provide a sample code to create a content with file resource component?
sure will do...give me a few days :-)
ReplyDelete