<%@ page contentType="text/xml;charset=UTF-8"%>
<%@ page
import="com.ibm.workplace.wcm.searchseed.SearchSeedItem,
com.ibm.workplace.wcm.searchseed.SearchSeedServletConstants,
com.ibm.workplace.wcm.api.*,
com.ibm.workplace.wcm.api.exceptions.*,
com.ibm.wps.state.utils.Base64,
java.util.ArrayList,
java.util.Iterator,
java.util.List,
java.util.HashMap,
java.util.Map,
com.aptrix.util.HTMLCodec;"%>
<!DOCTYPE SeedList SYSTEM "SeedList.dtd">
<%@ taglib uri="/WEB-INF/tld/wcm.tld" prefix="wcm" %>
<%
String userId = request.getParameter("userid");
String userPwd = request.getParameter("password");
String siteId = request.getParameter(SearchSeedServletConstants.SITEID_ATTR );
String siteName=request.getParameter(SearchSeedServletConstants.SITE_ATTR );
String libName=request.getParameter(SearchSeedServletConstants.LIB_ATTR );
String urlRoot = " + request.getServerName() + ":"
+ request.getServerPort();
String urlPrefix = (String) request.getAttribute(SearchSeedServletConstants.URL_PREFIX_ATTR );
String wcmsearchseedRoot = (String) request
.getAttribute(SearchSeedServletConstants.SEARCHSEED_ROOT_ATTR );
ArrayList items = (ArrayList) request.getAttribute(SearchSeedServletConstants.SEED_LIST_ATTR );
String nextPageNumber = (String) request.getAttribute(SearchSeedServletConstants.NEXT_PAGE_ATTR );
String encodeString = request.getParameter("debug");
String altTemplate = request.getParameter("alttemplate");
boolean doAltTemplate = (!(altTemplate == null));
String navComponent = request.getParameter("navcomponent");
boolean hasNavComponent = (!(navComponent == null));
boolean doEncode = ((encodeString == null) || Boolean.valueOf(
encodeString).booleanValue());
String nextPage = "";
int pageNum = 0;
if (nextPageNumber != null) {
pageNum = Integer.parseInt(nextPageNumber);
}
if (pageNum != -1) {
StringBuffer sb = new StringBuffer(urlRoot);
sb.append(wcmsearchseedRoot );
%>
<wcm:initworkspace username="<%= userId %>" password="<%= userPwd %>">cannot login to workspace</wcm:initworkspace>
<!--When the encoding is turned off "&" should be represented as "&" for the XML to process it correctly-->
<%
String amp = doEncode ? "&" : "&";
if(siteId!=null)
{
sb.append(SearchSeedServletConstants.SEARCH_URL_PREFIX);
sb.append(siteId);
}
else
{
sb.append(SearchSeedServletConstants.SEARCH_SEED_SERVLET_ROOT );
sb.append("site=");
sb.append(siteName );
if(libName!=null)
{
sb.append(amp);
sb.append("lib=");
sb.append(libName);
}
}
sb.append(amp);
sb.append("pageNum=");
sb.append(pageNum);
if (!doEncode) {
sb.append(amp);
sb.append("debug=false");
}
StringBuffer sb2 = new StringBuffer(" nextPage=\"");
sb2.append(doEncode ? Base64.encodeString(sb.toString(), false)
: sb.toString());
sb2.append('"');
nextPage = sb2.toString();
}
%>
<SeedList <%= nextPage %>
<%
Workspace workspace;
// Get the workspace for the specified user and password
workspace = WCM_API.getRepository().getWorkspace(userId, userPwd);
HashMap map = new HashMap();
for (int i = 0; i < items.size(); i++) {
SearchSeedItem ssi = (SearchSeedItem) items.get(i);
String relPath = ssi.getPath();
String fullPath = urlRoot + request.getAttribute("contextPath")
+ urlPrefix + relPath;
if (doAltTemplate) {
fullPath = fullPath + "?presentationtemplate=" + altTemplate;
}
String displayURL = fullPath;
if (hasNavComponent) {
// Set the rendering context
RenderingContext context = workspace.createRenderingContext(request, response, map, urlRoot + request.getAttribute("contextPath"), urlPrefix);
// Set the path to the content to be rendered
context.setRenderedContent(relPath);
// Retrieve the component
DocumentIdIterator libComponentIter = workspace.findComponentByName(navComponent);
while (libComponentIter.hasNext()) {
DocumentId libComponentId = (DocumentId) libComponentIter.next();
if (libComponentId.getType().equals(DocumentTypes.LibraryComponent))
{
LibraryComponent libComponent = (LibraryComponent)workspace.getById(libComponentId);
displayURL = urlRoot + workspace.render(context, libComponent);
}
}
}
fullPath = HTMLCodec.encode(fullPath.toCharArray());
String encPath = Base64.encodeString(fullPath, false);
displayURL = HTMLCodec.encode(displayURL.toCharArray());
String encdisplayURL = Base64.encodeString(displayURL, false);
%>
<Page>
<CrawlUrl>
<%= (doEncode ? encPath : fullPath)%>
</CrawlUrl>
<DisplayUrl>
<%= (doEncode ? encdisplayURL : displayURL)%>
</DisplayUrl>
<%
if (ssi.hasMetadata()) {
Iterator metadataNames = ssi.getMetadataNames();
%>
<Fields>
<%while (metadataNames.hasNext()) {
String metaName = (String) metadataNames.next();
java.util.List metaValue = ssi.getMetadataValue(metaName);
for (int j = 0; j < metaValue.size(); j++) {
%>
<Field>
<Name>
<%= (doEncode ? Base64.encodeString(metaName,
false) : metaName)%>
</Name>
<Value>
<%= (doEncode ? Base64.encodeBytes(metaValue
.get(j).toString().getBytes("UTF-8"), false) : metaValue
.get(j).toString())%>
</Value>
</Field>
<%}
}
%>
</Fields>
<%}
if (ssi.hasSecurityIDs()) {
Iterator securityIDs = ssi.getSecurityIDs();
%>
<SecurityIDs>
<%while (securityIDs.hasNext()) {
String id = (String) securityIDs.next();
%>
<ID>
<%= (doEncode ? Base64.encodeString(id, false) : id)%>
</ID>
<%
}
%>
</SecurityIDs>
<%}
%>
</Page>
<%}
%>
</SeedList>