Wednesday, January 22, 2014

Create a SiteMap in IBM web content manager.

Login to WCM and navigate to the library where you want to create the sitemap.
then select 

New -> components -> Navigator

name the component as NAV_SiteMap and enter the displaytitle and description.

in the start type dropdown select option " selected"

Selected Site area = "select the top level site area of you site "

and enter the rest of the details as shows below. 








 

save the component and preview the component

preview should look something like the screenshot below


 

Generate a list of all File resource components in a WCM library using wcm api.

this below code snippet will generate a list of all file resource components in a given WCM library.

save this code as a jsp deploy it to the server and create a jsp component and add it to a content page

you will see a list of all file resource components with links to the component. clicking the link will open the component in a new tab/window. 



<%@ page import="com.ibm.workplace.wcm.api.*"%>
<%@ page import="java.util.*"%>


<%
// retrieve repository
 try { 
System.out.println("************enter jsp ");
Repository repository = WCM_API.getRepository();
// get the workspace for current user
System.out.println("************repository.getHostName() " +repository.getHostName());
Workspace workspace = repository.getWorkspace(request.getUserPrincipal());
// set the library
System.out.println("************repository.getHostName() " +workspace.getCurrentDocumentLibrary());
workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("YourLibraryName"));


                                          

                                                                       
    // need to get a list of all File Components                       
    DocumentIdIterator fileIterator;                                   
    DocumentId fileId;                                                 
    LibraryFileComponent tempFile;                                     
    DocumentIdIterator siteAreaIdIterator;                             
    DocumentId siteAreaId;                                             
    SiteArea mySiteArea;                                               
                                                                       
    RenderingContext rc = workspace.createRenderingContext(request, response, new  HashMap(),"http://hostname:10039/wps/wcm/","/myconnect");                                                  
                                                              
                                                                       
    String renderedContent;                                            
                                                                       
    siteAreaIdIterator = workspace.findByType(DocumentTypes.SiteArea);   
                                                  
    siteAreaId = (DocumentId)siteAreaIdIterator.next();                
    mySiteArea = (SiteArea)workspace.getById(siteAreaId);                     
                                                                       
    rc.setRenderedContent(mySiteArea);                                 
                                                                       
                                                                       
    fileIterator = workspace.findByType(DocumentTypes.LibraryFileComponent);  
    while(fileIterator.hasNext()) {                                    
        out.println("<br>");                                           
        fileId = (DocumentId)fileIterator.next();                      
        if(fileId != null) {                                           
          tempFile = (LibraryFileComponent)workspace.getById(fileId);         
          out.println("<a  href=\""+workspace.render(rc, tempFile)+  "&CACHE=NONE\" target=\"_blank\" >"+tempFile.getName()+"</a><br>");                  
                              
        }                                                              
    }                                                                  
                                                                       
  } catch (Exception e)  {                                             
    %><%= e.toString() %><%                                            
  }                                                                    
                                                                     


%>