}
}
else
{
log.error("computeProfiledPageContext(): Failed to find profiled page and/or folder for " + requestPath + " at " + locator);
throw new PageNotFoundException(requestPath + " at " + locator);
}
}
else
{
// return request folder and page
// managed folder and page
try
{
// retrieve managed folder and page from request
String folderPath = requestPath;
if (folderPath.endsWith(Page.DOCUMENT_TYPE) || folderPath.endsWith(Folder.PATH_SEPARATOR))
{
int lastSlashIndex = folderPath.lastIndexOf(Folder.PATH_SEPARATOR_CHAR);
if (lastSlashIndex > 0)
{
folderPath = folderPath.substring(0, lastSlashIndex);
}
else
{
folderPath = Folder.PATH_SEPARATOR;
}
}
folder = folderHandler.getFolder(folderPath);
String pagePath = requestPath;
if (! pagePath.endsWith(Page.DOCUMENT_TYPE))
{
pagePath = folder.getDefaultPage(true);
}
page = ((FolderImpl)folder).getPage(pagePath, false);
}
catch (NodeException ne)
{
}
if (page == null)
{
// fallback to default page for root folder
log.warn("computeProfiledPageContext(): Falling back to managed root default page for " + requestPath);
try
{
folder = folderHandler.getFolder(Folder.PATH_SEPARATOR);
String pagePath = folder.getDefaultPage(true);
page = ((FolderImpl)folder).getPage(pagePath, false);
}
catch (NodeException ne)
{
}
}
// managed page context
if (page != null)
{
// return folders and pages relative to requested page
siblingPages = ((FolderImpl)folder).getPages(false);
parentFolder = (Folder) ((AbstractNode)folder).getParent(false);
siblingFolders = ((FolderImpl)folder).getFolders(false);
try
{
Folder rootFolder = folderHandler.getFolder(Folder.PATH_SEPARATOR);
rootLinks = ((FolderImpl)rootFolder).getLinks(false);
}
catch (NodeException ne)
{
}
try
{
// get default document set order from folder
Comparator documentComparator = ((NodeSetImpl)((FolderImpl)folder).getAllNodes()).getComparator();
// aggregate and expand document sets from page to root folder;
documentSets = new NodeSetImpl(null, documentComparator);
documentSetNames = new HashMap(8);
documentSetNodeSets = new HashMap(8);
Set uniqueDocumentSetPaths = new HashSet(8);
FolderImpl aggregateFolder = (FolderImpl)folder;
do
{
// aggregate uniquely named and expand folder document sets
Iterator documentSetsIter = aggregateFolder.getDocumentSets(false).iterator();
while (documentSetsIter.hasNext())
{
DocumentSet documentSet = (DocumentSet) documentSetsIter.next();
String documentSetPath = documentSet.getPath();
// aggregate document sets
if (! uniqueDocumentSetPaths.contains(documentSetPath))
{
uniqueDocumentSetPaths.add(documentSetPath);
// expand document set using default document set order
NodeSetImpl documentSetNodes = new NodeSetImpl(null, documentComparator);
documentSetNodes = expandDocumentSet(documentSet, documentSetNodes, "", documentSetNames, documentSetNodeSets);
if (documentSetNodes != null)
{
documentSets.add(documentSet);
}
}
}
// aggregate document sets in parent
aggregateFolder = (FolderImpl) ((AbstractNode)aggregateFolder).getParent(false);
}
while (aggregateFolder != null);
}
catch (NodeException ne)
{
}
}
else
{
log.error("computeProfiledPageContext(): Failed to find managed page for " + requestPath);
throw new PageNotFoundException(requestPath);
}
}
// cache profiled page context result
cachedPageContext = new CacheablePageContext(page, folder, siblingPages, parentFolder, siblingFolders, rootLinks, documentSets, documentSetNames, documentSetNodeSets, allProfiledFolders);