Introduction In version 6.1 a new method was introduced to the Web Content Management API that allows customers to export a list with information about all documents and web content artefacts in a web content library without exporting these items itself.
Users can use this list and the information about the contents of a library to build various tools that ease administration and syndication of web content libraries. Good examples for such tools include:
- Programs that compare exported lists from different libraries
- Programs that compare exported lists from the same libraries but from different web content management system in a syndication setup
In order to ease to build such library comparision tools the items written are grouped by generic web library item types (e.g. Workspace, Content, Components etc.) and the items in each group are ordered by their ID.
The new library catalog export functionality is based on a streaming approach and thus is able to handle exports of large web content libraries with many thousands of items without holding all the items in memory. Additionally it provides a plug-point to allow customers to change the format of the list while exporting.
Document list exported
The following properties are exported for each item in the web content library in this order.
- Name of the library the item belongs to
- The ID of the item
- The name of the item
- The type of the item in english
- The type of the item localized in the language specified
- Timestamp of the last modification of the item in milliseconds since 1th January 1970
- Code that indicates the current state of the item with the following possible values:
0 - Item is in draft workflow state
1 - Item is published
2 - Item is expired
3 - Item was deleted - Description of the current state of the item localized in the language specified
As mentioned before all items are written in groups of the generic types they belong to and ordered by their ID within each group. This is the order in which the different item types are written:
- Workflow
- Workflow Stage
- Workflow Action
- Category
- Taxonomy
- Component
- Content
- Presentation Template
- Authoring Template
- Site Area
- Site
This is an example of such a document list.
| mylib | 083b7a80497913b4a88ebbe757e40b02 | wf_3stages | Workflow | Workflow | 1208962059734 | 1PUBLISHED |
| mylib | 1df87200497913aba83cbbe757e40b02 | start_stage | Workflow Stage | Workflow Stage | 1208962055812 | 1PUBLISHED |
| mylib | 0ff42280497913a6a830bbe757e40b02 | publish_sample | Publish Action | Publish Action | 1208962053812 | 1PUBLISHED |
| mylib | 163fca00497913b9a8b8bbe757e40b02 | cat_1_2 | Category | Category | 1208962061796 | 1PUBLISHED |
| mylib | de378780497913b6a8a0bbe757e40b02 | tax_a | Taxonomy | Taxonomy | 1208962060843 | 1PUBLISHED |
| mylib | 37ef8000497913bea8ecbbe757e40b02 | cmpnt_rft_1 | Rich Text | Rich Text | 1208962064015 | 1PUBLISHED |
| mylib | 4f7d3780497913c3a925bbe757e40b02 | cmpnt_img_1 | Image | Image | 1208962066203 | 1PUBLISHED |
| mylib | 7300ac00497913dcaa1dbbe757e40b02 | content_1_4 | Content | Content | 1209029023843 | 1PUBLISHED |
| mylib | 80686700497913d9aa03bbe757e40b02 | content_1_1 | Content | Content | 1209028693296 | 3DELETED |
| mylib | 97f32000497913d8a9f7bbe757e40b02 | content_2_2 | Content | Content | 1208962075390 | 1PUBLISHED |
| mylib | d095f800497913deaa20bbe757e40b02 | Content with Gaps | Content | Content | 1208962078078 | 0DRAFT |
| mylib | e824af00497913e5aa67bbe757e40b02 | content_b_1_2 | Content | Content | 1208962081093 | 1PUBLISHED |
| mylib | 50b26280497913cba965bbe757e40b02 | pt2 | Presentation Template | Presentation Template | 1208962069750 | 1PUBLISHED |
| mylib | cec43880497913cea984bbe757e40b02 | at3 | Authoring Template | Authoring Template | 1208962071140 | 1PUBLISHED |
| mylib | fddda880497913d4a9d3bbe757e40b02 | site_area_a_1 | Site Area | Site Area | 1208962073796 | 1PUBLISHED |
| mylib | f3b9ab00497913d0a999bbe757e40b02 | site_a | Site | Site | 1208962072046 | 1PUBLISHED |
Usage in syndication scenarios The web content library catalog export function can be very usefull in syndication scenarios to find out differences between libraries on the syndicator and subscriber web content management system.
A comparison of the document lists of the source (syndicator) and target system (subscriber) can reveal items that haven’t been syndicated yet or where syndication didn’t work.
Items that can be found in the list of the syndicator but are missing in the list exported from the subscriber identify items that either haven’t been syndicated yet e.g. draft items or items where syndication failed in previous syndication operations.
Items that can only be found in the subscriber list identify items that either have been created on the subscriber system only or items that have been purged on the syndicator and haven’t been syndicated yet.
Items that exist in the document list from the syndicator and subscriber but have different modification timestamps or different workflow state are also an indicator for items that haven’t been syndicated correctly.
Web Content Library Service
The following method in web content library service API (com.ibm.workplace.wcm.api.WebContentLibraryService) can be used to export a list with information about all contents of a web content library.
public LibraryTaskResult outputDocumentListToStream(
Workspace workspace, String libraryName,
DocumentListWriter out, java.util.Locale locale)
throws OperationFailedException, UnsupportedOperationException;
Parameters:
workspace – The Web Content Management workspace used for the export operation
libraryName – The name of the library the list should be exported for
out – The DocumentListWriter object used to write the information about the exported library items to
locale – Specifies the language used to localize information about the exported items
Returns:
LibraryTaskResult object that represents that status of this operation after it finished
Exceptions:
OperationFailedException – If an exception occurred while occurred
&nb
sp; UnsupportedOperationException – If the used web content library service implementation does not support this method
Depending on the number of items in the web content library the export can take longer and users might experience timeout issues. If this happens customers should consider usage of the asynchronous bean feature the IBM WebSphere Application Server provides to run the export operation asynchronously. Further information about asynchronous beans and how to use them can be found in the IBM WebSphere Application Server Information Center. E.g at http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.ejbfep.multiplatform.doc/info/ae/asyncbns/tasks/tasb_epasb.html
A reference to the WebContentLibraryService Portal service can be retrieved via a JNDI lookup.
try
{
Construct an inital Context
javax.naming.InitialContext ctx = new javax.naming.InitialContext ();
Retrieve WebContentLibraryService using JNDI name
WebContentLibraryService webContentLibraryService = (WebContentLibraryService)
ctx.lookup("portal:service/wcm/WebContentLibraryService");
}
catch (NamingException ne)
{
System.out.print("WebContentLibraryService could not be retrived. Exception: " + ne);
}
Note: Please make sure that the WebContentLibraryService is registered as Portal service and listed in the PortalServer\shared\app\config\services.properties. If not add the following line to this files and restart the Portal Server.
com.ibm.workplace.wcm.api.WebContentLibraryService = com.ibm.workplace.wcm.api.WebContentLibraryServiceImpl
DocumentListWriter Interface
In order to use the above outputDocumentListToStream method in the WebContentLibraryService you will need to provide a document list writer object that is used to actually write the information of the library documents to a underlying stream or file.
Users can either provide their own custom implementation of the interface (com.ibm.workplace.wcm.api.DocumentListWriter) or make use of a sample implementation (com.ibm.workplace.wcm.api.CSVDocumentListWriter) that writes the information in a comma separated format with each item in a separate row.
Code example:
The following code snippet shows how to make use of the library catalog functionality.
import java.io.*;
import java.util.*;
import javax.naming.*;
import com.ibm.workplace.wcm.api.*;
import com.ibm.workplace.wcm.api.exceptions.*;
public class Exporter
{
public void lisItems()
{
try
{
  Construct an inital context
javax.naming.InitialContext ctx = new javax.naming.InitialContext ();
Retrieve WebContentLibraryService using JNDI name
WebContentLibraryService webContentLibraryService =
(WebContentLibraryService)ctx.lookup("portal:service/wcm/WebContentLibraryService");
  get WCM workspace
Workspace workspace = WCM_API.getRepository().getWorkspace("user", "password");
Writer fileWriter = null;
try
{
create writer object
fileWriter = new FileWriter("C:\test.csv");
use default
CSV document list writer
DocumentListWriter out = new CSVDocumentListWriter(fileWriter);
write library catalog
LibraryTaskResult opResult = webContentLibraryService.outputDocumentListToStream(
workspace,"Mylibrary", out, Locale.ENGLISH);
finalize
fileWriter.flush();
check result
if(! ResultTypes.OPERATION_SUCCESS.equals(opResult.getResultType()))
{
System.err.println("outputDocumentListToStream did not finish successfully");
}
}
catch (IOException ioe)
{
System.err.println("Unable to write to file. Exception: " + ioe);
}
finally
{
  make sure file stream is closed
if(fileWriter != null)
{
try
{
fileWriter.close();
}
catch (IOException ioec)
{
System.err.println("Unable to close file stream. Exception: " + ioec);
}
}
}
}
catch (NamingException ne)
{
System.err.println("WebContentLibraryService could not be retrived. Exception: " + ne);
}
catch (ServiceNotAvailableException se)
{
System.err.println("WCM Repository not avalable. Exception: " + se);
}
catch
(OperationFailedException oe)
{
System.err.println("WCM Repository not avalable. Exception: " + oe);
}
}
}