Untitled Document
Table of contents | Next | Previous
WCM API Samples used for the RiverBend site
In the following article, we discuss the second of two specific samples.
Sample 2 - WCM Reports
This WCM API sample provides some of the reports that can be generated for
an administrator of Web Content Management. This just a sample list and there
can be many more reports which can be generated.
The reports are generated by a JSP. So create a JSP component and refer in a
place where the reports have to be displayed.
The figure below illustrates the list of reports that would be generated by
this sample.

The following is the content of the jsp, which generates these reports.
<%@ page import="com.ibm.workplace.wcm.api.*"%>
<%@
page import="com.ibm.wps.services.ServiceManager"%>
<%@ page
import="java.util.*,java.security.Principal"%>
<%@ page
import="java.text.SimpleDateFormat"%>
<script>
function submitForm(funct)
{
document.findreplace.reportType.value = funct;
document.findreplace.submit();
}
</script>
<form name="findreplace" action=""
method="POST">
<input type="hidden" name="reportType"
value=""/>
<table>
<tr>
<td>
<ul>
<li><a href="javascript:submitForm('library');">Library
Details</a><br><br></li>
<li><a
href="javascript:submitForm('libraryResource');">Library Resource
Access Details</a><br><br> </li>
<li><a href="javascript:submitForm('lock');">Locked
Content List</a> <br><br></li>
<li><a href="javascript:submitForm('draft');">Draft
Content List</a><br><br></li>
<li><a href="javascript:submitForm('expired');">Expired
Content List </a><br><br></li>
<li><a href="javascript:submitForm('history');">Content
History</a><br><br></li>
</ul>
</td>
</tr>
</table>
</form>
<br>
<table border="1" cellpadding="0"
cellspacing="0"
bordercolor="gray" BORDERCOLORDARK="gray"
BORDERCOLORLIGHT="gray" valign="center">
<%
try
{
String reportType = "";
if(request.getMethod().equalsIgnoreCase("POST"))
{
reportType = request.getParameter("reportType");
if(reportType != null)
{
// Construct and inital Context
javax.naming.InitialContext ctx = new javax.naming.InitialContext();
// Retrieve WebContentService using JNDI name
WebContentService webContentService = (WebContentService)
ctx.lookup("portal:service/wcm/WebContentService");
//Get the WCM Repository
Repository rep = webContentService.getRepository();
//Get an authenticated WCM Workspace
Workspace wsa = rep.getWorkspace();
//Set the current library
wsa.setCurrentDocumentLibrary(wsa.getDocumentLibrary("Comment2Lib"));
if(reportType.equals("lock"))
{
%>
<tr>
<td colspan="2" align="center" height="25">
<b>Locked Content List</b>
</td>
</tr>
<%
DocumentIdIterator contentIterator = wsa.findByType(DocumentTypes.Content);
int displayHeader = 0;
while(contentIterator.hasNext())
{
DocumentId contentId = contentIterator.nextId();
if(wsa.isLocked(contentId))
{
displayHeader++;
Content content = (Content)wsa.getById(contentId);
if(displayHeader == 1)
{
%>
<tr align="center">
<td><b> Name
</b></td>
<td><b> Parent
</b></td>
</tr>
<%
}
%>
<tr>
<td>
<%= contentId.getName() %>
</td>
<td>
<%=content.getDirectParent().getName()%>&
;nbsp;
</td>
</tr>
<%
}
}
if(displayHeader == 0)
{
%>
<tr>
<td colspan="2">
There is no Locked Content
</td>
</tr>
<%
}
}
else if(reportType.equals("history"))
{
%>
<tr>
<td colspan="3" align="center" height="25">
<b> Content History </b>
</td>
</tr>
<%
DocumentIdIterator contentIterator = wsa.findByType(DocumentTypes.Content);
int displayHeader = 0;
while(contentIterator.hasNext())
{
DocumentId contentId = contentIterator.nextId();
displayHeader++;
Content content = (Content)wsa.getById(contentId);
HistoryLogIterator logIterator = content.getHistoryLog();
if(displayHeader == 1)
{
%>
<tr align="center">
<td><b> Name
</b></td>
<td><b> Parent
</b></td>
<td><b> History
</b></td>
</tr>
<%
}
%>
<tr>
<td>
<%= contentId.getName() %>
</td>
<td>
<%=content.getDirectParent().getName()%>&
;nbsp;
</td>
<td>
<%
while(logIterator.hasNext())
{
HistoryLogEntry history = logIterator.nextLogEntry();
%>
<%=history.getDate().toString() %>
- <%=history.getName()%> - <%=history.getMessage()%>
<br>
<%
}
%>
</td>
</tr>
<%
}
if(displayHeader == 0)
{
%>
<tr>
<td colspan="2">
There is no content in Draft stage
</td>
</tr>
<%
}
}
else if(reportType.equals("draft"))
{
%>
<tr>
<td colspan="2" align="center" height="25">
<b>Draft Content List</b>
</td>
</tr>
<%
DocumentIdIterator contentIterator = wsa.findByType(DocumentTypes.Content);
int displayHeader = 0;
while(contentIterator.hasNext())
{
DocumentId contentId = contentIterator.nextId();
if(contentId.isDraft())
{
displayHeader++;
Content content = (Content)wsa.getById(contentId);
if(displayHeader == 1)
{
%>
<tr align="center">
<td><b> Name
</b></td>
<td><b> Parent
</b></td>
</tr>
<%
}
%>
<tr>
<td>
<%= contentId.getName() %>
</td>
<td>
<%=content.getDirectParent().getName()%>&
;nbsp;
</td>
</tr>
<%
}
}
if(displayHeader == 0)
{
%>
<tr>
<td colspan="2">
There is no content in Draft stage
</td>
</tr>
<%
}
}
else if(reportType.equals("expired"))
{
%>
<tr>
<td colspan="2" align="center" height="25">
<b>Expired Content List</b>
</td>
</tr>
<%
DocumentIdIterator contentIterator = wsa.findByType(DocumentTypes.Content);
int displayHeader = 0;
while(contentIterator.hasNext())
{
DocumentId contentId = contentIterator.nextId();
if(contentId.isExpired())
{
displayHeader++;
Content content = (Content)wsa.getById(contentId);
if(displayHeader == 1)
{
%>
<tr align="center">
<td><b> Name
</b></td>
<td><b> Parent
</b></td>
</tr>
<%
}
%>
<tr>
<td>
<%= contentId.getName() %>
</td>
<td>
<%=content.getDirectParent().getName()%>&
;nbsp;
</td>
</tr>
<%
}
}
if(displayHeader == 0)
{
%>
<tr>
<td colspan="2">
There is no content in Expire stage
</td>
</tr>
<%
}
}
else if(reportType.equals("library"))
{
%>
<tr>
<td colspan="4" align="center" height="25">
<b>Library Details </b>
</td>
</tr>
<%
try
{
%>
<tr align="center">
<td><b> Name
</b></td>
<td><b> Description
</b></td>
<td><b> Enabled
</b></td>
<td><b> Language
</b></td>
</tr>
<%
WebContentLibraryService webContentLibraryService = (WebContentLibraryService)
ctx.lookup("portal:service/wcm/WebContentLibraryService");
java.util.Iterator it = wsa.getDocumentLibraries();
while(it.hasNext())
{
DocumentLibrary docLibrary = (DocumentLibrary)it.next();
//docLibrary.getLibraryResourceAccess(LibraryResourceType.AuthoringTemplate)
%>
<tr>
<td>
<%= docLibrary.getName() %>
</td>
<td>
<%=docLibrary.getDescription()%> &a
mp;nbsp;
</td>
<td>
<%=docLibrary.isEnabled()%> &nb
sp;
</td>
<td>
<%=docLibrary.getLocale().getLanguage()
%>
</td>
</tr>
<%
}
}
catch (Exception ne)
{
System.out.print("Exception: " + ne);
}
}
else if(reportType.equals("libraryResource"))
{
%>
<tr>
<td colspan="8" align="center" height="25">
<b>Library Resource Access Details* </b> <br>
</td>
</tr>
<%
try
{
%>
<tr align="center">
<td><b> Library
</b></td>
<td><b> Authoring Template
</b></td>
<td><b> Components
</b></td>
<td><b> Content
</b></td>
<td><b> Presentation Template
</b></td>
<td><b> Site Framework
</b></td>
<td><b> Taxomomy
</b></td>
<td><b> Workflow
</b></td>
</tr>
<%
WebContentLibraryService webContentLibraryService = (WebContentLibraryService)
ctx.lookup("portal:service/wcm/WebContentLibraryService");
LibraryResourceType resourceTypes[] =
{LibraryResourceTypes.AuthoringTemplate,
LibraryResourceTypes.Component,LibraryResourceTypes.Content,
LibraryResourceTypes.PresentationTemplate,
LibraryResourceTypes.SiteFramework,LibraryResourceTypes.Taxonomy,
LibraryResourceTypes.Workflow };
LibraryMemberRole roleTypes[] =
{LibraryMemberRoles.Administrator,LibraryMemberRoles.Security_Admin,LibraryMembe
rRoles.Contributor,
LibraryMemberRoles.Delegator,
LibraryMemberRoles.Editor,LibraryMemberRoles.Manager,
LibraryMemberRoles.Privileged_User,LibraryMemberRoles.User}
for(int i=0;i<roleTypes.length;i++)
{
%>
<tr>
<td>
<b><%=roleTypes[i]%>
</b>
</td>
<%
for(int j=0;j<resourceTypes.length;j++)
{
boolean noDisp = false;
%>
<td>
<%
java.util.Iterator it = wsa.getDocumentLibraries();
while(it.hasNext())
{
DocumentLibrary docLibrary = (DocumentLibrary)it.next();
String[] resourceMembers =
docLibrary.getLibraryResourceAccess(resourceTypes[j]).getMembers(roleTypes[i]);
if(resourceMembers.length > 0 )
{
noDisp = true;
%>
<%= docLibrary.getName() %> -
<%
System.out.println("resourceMembers.length
"+resourceMembers.length);
for(int k=0;k<resourceMembers.length;k++)
{
if(k == 0)
{
%<%=resourceMembers[k]%>
<%
}
else
{
%>
, <%=resourceMembers[k]%>
<%
}
}
%>
<br>
<%
}
}
if(!noDisp)
{
%>
-
<%
}
%>
</td>
<%
}
%>
</tr>
<%
}
}
catch (Exception ne)
{
System.out.print("Exception: " + ne);
}
%>
<tr>
<td colspan="8"> <br>
<i> * Details are displayed in the format "Libary Name - Member
Details" </i>
</td>
</tr>
<%
}
webContentService.getRepository().endWorkspace();
}
}
}
catch(Exception ex)
{
out.println("error in the code: " + ex .toString());
}
%>
</table>
The following figure depicts the Library Resource Access report generated.
