Our Blog > Blog Detail

Web Content Viewer- Asponte Custom Skin

Actions

WCM Tools Series: Get Items in a Project

  • Created By: Chris Knight
  • Updated: March 11, 2016
  • Tags: tools, jsp, wcm, custom

Introduction

We ran across a use case where we needed to be able to retrieve the assets that were associated with a published project, in order to generate a list of the assets that had been changed.

 

Using the WCM API, we can build a tool that allows you to pass the name of the project, and get (in this case a comma delimited list) of assets that had been changed.

 

For details on how to leverage custom JSPs from WCM, see the entry:

 

WCM Tools Series: Introduction to using custom JSPs

 

Expected Inputs

In order to properly retrieve the item and the projects, the JSP expects 2 parameters:

String projectName = request.getParameter("projectName");
String libName = request.getParameter("libName");

 

Basically, you pass the name of the project, and the library name because the WCM Workspace needs a library name..

 

Sample URL

testaddtoproject.jsp?libName=ASPONTE_TEST&projectName=testAPIProject

Expected Outcome

A comma delimited list of items within the project should be output.

 

Full Code

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%><%@ page session="false" isELIgnored="false"%><%@ page
    import="java.util.*,java.text.*,javax.naming.*,java.io.*,java.lang.*,com.ibm.workplace.wcm.api.query.*,com.ibm.workplace.wcm.api.*, com.ibm.workplace.wcm.api.query.*"%>


<%!public static String getAuthoringURL(String host, int port, DocumentId theDoc, Workspace ws)
   {
      String previewURL = "";

      StringBuilder sb = new StringBuilder();      
      String contextRoot = "/internet/myportal/us";      

      sb.append(host);
      sb.append(":"+port);
      sb.append(contextRoot);

      sb.append("/wcmAuthoring?wcmAuthoringAction=read&docid=" + theDoc);
      previewURL = sb.toString();

      return previewURL;

   }%>

<%
   // get a system workspace and dump the user
   Workspace ws = null;
   try
   {
      ws = WCM_API.getRepository().getSystemWorkspace();

      InitialContext ctx = new InitialContext();

      String host = request.getServerName();
      int port = request.getServerPort();
      // Retrieve WcmProjectService using JNDI name
      WcmProjectService service = (WcmProjectService) ctx.lookup("portal:service/wcm/WcmProjectService");
      // create the project 
      Project newProject = null;

      // get projname from the URL
      String projectName = request.getParameter("projectName"); 
      String libName = request.getParameter("libName");    
      // if its empty or null, bail
      if (projectName == null || projectName.isEmpty())
      {
         throw new Exception("no projectName passed");
      }
      
      
      ws.setCurrentDocumentLibrary(ws.getDocumentLibrary(libName));
      DocumentIdIterator projIt = ws.findByName(DocumentTypes.Project, projectName);
      if (projIt != null && projIt.hasNext())
      {
         newProject = (Project) ws.getById(projIt.nextId());
      }
      else
      {
          throw new Exception("could not retrieve project with name "+projectName);
      }
      // finally get the items in the project
      ResultIterator items = newProject.getItems();
      while(items.hasNext()) {
          Document theDoc = items.next();
          DocumentId itemId = theDoc.getId();
          out.println(newProject.getName()+",");
          out.println(getAuthoringURL(host,port,itemId, ws)+",");
          out.println(itemId.getName()+",");
          out.println(itemId.getId());
          out.println("
");
      }

   }
   catch (Exception e)
   {
      out.println(e.getMessage() + "
");
      e.printStackTrace();
   }
%>

Contact Form- Asponte Custom Skin

Actions

Contact Us

*
*


Submit
Call Us 888-926-9434
Complementary Content
${loading}