// profile sibling pages by aggregating all siblings in profiled folders
// using profiled general document order, (do not filter unordered siblings);
// force profiled page to exist as sibling to support pages profiled using
// alternate locators that may not select page in profiled folder: the
// profiled page must appear in the sibling pages collection.
siblingPages = new NodeSetImpl(null, documentComparator);
siblingPages = addUniqueOrDescribedUrlNode((NodeSetImpl) siblingPages, (AbstractNode) page);
foldersIter = profiledFolders.iterator();
while (foldersIter.hasNext())
{
FolderImpl aggregatePagesFolder = (FolderImpl) foldersIter.next();
NodeSet aggregatePages = aggregatePagesFolder.getPages(false);
Iterator aggregatePagesIter = aggregatePages.iterator();
while (aggregatePagesIter.hasNext())
{
AbstractNode siblingPageNode = (AbstractNode)aggregatePagesIter.next();
if (!siblingPageNode.isHidden())
{
siblingPages = addUniqueOrDescribedUrlNode((NodeSetImpl)siblingPages, setProfiledNodePathAndUrl(siblingPageNode));
}
}
}
// profile parent folder using profiled parent
if ((((AbstractNode)folder).getParent(false) != null) &&
!((AbstractNode)folder).getProfiledPath().equals(Folder.PATH_SEPARATOR))
{
AbstractNode parentFolderNode = (AbstractNode)((AbstractNode)folder).getParent(false);
if (!parentFolderNode.isHidden())
{
parentFolder = (Folder)setProfiledNodePathAndUrl(parentFolderNode);
allProfiledFolders.add(parentFolder);
}
}
// profile sibling folders by aggregating all siblings in profiled folders
// using profiled general document order, (do not filter unordered siblings)
siblingFolders = new NodeSetImpl(null, documentComparator);
foldersIter = profiledFolders.iterator();
while (foldersIter.hasNext())
{
FolderImpl aggregateFoldersFolder = (FolderImpl) foldersIter.next();
NodeSet aggregateFolders = aggregateFoldersFolder.getFolders(false).exclusiveSubset("^.*/" + PROFILE_NAVIGATION_PROPERTY_FOLDER_PREFIX + "[^/]*$").exclusiveSubset("^.*/" + PROFILE_PROPERTY_FOLDER_PREFIX + "[^/]*$");
Iterator aggregateFoldersIter = aggregateFolders.iterator();
while (aggregateFoldersIter.hasNext())
{
AbstractNode siblingFolderNode = (AbstractNode)aggregateFoldersIter.next();
if (!siblingFolderNode.isHidden())
{
siblingFolders = addUniqueOrDescribedUrlNode((NodeSetImpl)siblingFolders, setProfiledNodePathAndUrl(siblingFolderNode));
allProfiledFolders.add(siblingFolderNode);
}
}
}
// profile document sets by aggregating all document set documents by document
// set name in all profiled folders for page
Map aggregateDocumentSets = new HashMap(12);
foldersIter = searchProfiledFolders.iterator();
while (foldersIter.hasNext())
{
FolderImpl aggregateFolder = (FolderImpl) foldersIter.next();
NodeSet aggregateFolderDocumentSets = aggregateFolder.getDocumentSets(false);
Iterator aggregateFolderDocumentSetsIter = aggregateFolderDocumentSets.iterator();
while (aggregateFolderDocumentSetsIter.hasNext())
{
AbstractNode documentSetNode = (AbstractNode)setProfiledNodePathAndUrl((AbstractNode)aggregateFolderDocumentSetsIter.next());
if (!documentSetNode.isHidden())
{
String documentSetProfiledPath = documentSetNode.getProfiledPath();
if (!aggregateDocumentSets.containsKey(documentSetProfiledPath))
{
aggregateDocumentSets.put(documentSetProfiledPath, documentSetNode);
}
}
}
}
// generate profiled document sets from aggregated document set documents
if (! aggregateDocumentSets.isEmpty())
{
// profiled document sets to be returned
documentSets = new NodeSetImpl(null, documentComparator);
documentSetNames = new HashMap(aggregateDocumentSets.size() * 2);
documentSetNodeSets = new HashMap(aggregateDocumentSets.size() * 2);
// profile each aggregated document set
Iterator documentSetsIter = aggregateDocumentSets.values().iterator();
while (documentSetsIter.hasNext())
{
// expand and profile each document set
DocumentSet documentSet = (DocumentSet) documentSetsIter.next();
NodeSetImpl documentSetNodes = expandAndProfileDocumentSet(pageContext.getLocators(), documentSet, null, "", documentSetNames, documentSetNodeSets, allProfiledFolders);
if (documentSetNodes != null)
{
documentSets.add(documentSet);
}
}
}
// profile root links by aggregating all links in profiled root folders
if (! rootFallback && ! requestPath.equals(Folder.PATH_SEPARATOR))
{
// profile root folders if required
searchPaths = generateProfilingSearchPaths(Folder.PATH_SEPARATOR, locator, true);
profiled = findProfiledPageAndFolders(searchPaths, profiledPage, profiledFolder, profiledFolders, searchProfiledFolders);
}
if (profiled)
{
// profile root link document order folder meta data
List linkDocumentOrder = null;
foldersIter = profiledFolders.iterator();
while ((linkDocumentOrder == null) && foldersIter.hasNext())
{
FolderImpl profiledRootFolder = (FolderImpl) setProfiledNodePathAndUrl((AbstractNode) foldersIter.next());
if (((AbstractNode) profiledRootFolder).getProfiledPath().equals(Folder.PATH_SEPARATOR) &&
(profiledRootFolder.getMetaData() != null) && (profiledRootFolder.getMetaData().getDocumentOrder() != null) &&
! profiledRootFolder.getMetaData().getDocumentOrder().isEmpty())
{
linkDocumentOrder = profiledRootFolder.getMetaData().getDocumentOrder();
}
}
Comparator linkDocumentComparator = new DocumentOrderComparator(linkDocumentOrder);
// profile root links using profiled document order
rootLinks = new NodeSetImpl(null, linkDocumentComparator);
foldersIter = profiledFolders.iterator();
while (foldersIter.hasNext())
{
FolderImpl aggregateLinksFolder = (FolderImpl) setProfiledNodePathAndUrl((AbstractNode) foldersIter.next());
if (aggregateLinksFolder.getProfiledPath().equals(Folder.PATH_SEPARATOR))
{
NodeSet aggregateLinks = aggregateLinksFolder.getLinks(false);
Iterator aggregateLinksIter = aggregateLinks.iterator();
while (aggregateLinksIter.hasNext())
{
AbstractNode rootLinkNode = (AbstractNode)aggregateLinksIter.next();
if (!rootLinkNode.isHidden())
{
rootLinks = addUniqueOrDescribedUrlNode((NodeSetImpl)rootLinks, setProfiledNodePathAndUrl(rootLinkNode));
}
}
}
}
}
else
{
// return empty root links
rootLinks = new NodeSetImpl(null);
}
}
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);
}