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