Wednesday, January 22, 2014

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() %><%                                            
  }                                                                    
                                                                     


%>


3 comments:

  1. I am looking for how to generate a list of all file resource components in a WCM library using wcm api. Thank you so much, It’s extremely useful to me like custom essay writing service.

    ReplyDelete
  2. Most of SEO persons don't concentrate on sitemap. It's a mandatory part of seo. For example you have ecommerce site and there are various pages in your site all pages of your site will dynamically fetch if you use sitemap.

    professional dissertation writer

    ReplyDelete
  3. Jobs in Pakistan updated daily with latest public, private and Govt jobs it is Pakistan Jobs hub for fresh graduates, professionals and skilled people seo manager jobs.

    ReplyDelete

comments