String requestPath = locator.getRequestPath();
// get profiled page context initialization parameters
Folder folder = null;
Page page = null;
NodeSet siblingPages = null;
Folder parentFolder = null;
NodeSet siblingFolders = null;
NodeSet rootLinks = null;
NodeSet documentSets = null;
Map documentSetNames = null;
Map documentSetNodeSets = null;
List allProfiledFolders = null;
if (profilingEnabled)
{
// profile page request using profile locator
Folder [] profiledFolder = new Folder[1];
Page [] profiledPage = new Page[1];
List profiledFolders = new ArrayList(16);
List searchProfiledFolders = new ArrayList(24);
// generate profile locator folder/page search paths
List searchPaths = generateProfilingSearchPaths(requestPath, locator, false);
// find page in page manager content using search paths
boolean profiled = findProfiledPageAndFolders(searchPaths, profiledPage, profiledFolder, profiledFolders, searchProfiledFolders);
// profile fallback to default root folder to locate folder/page
boolean rootFallback = false;
if (rootFallback = (! profiled && ! requestPath.equals(Folder.PATH_SEPARATOR)))
{
// profile default root folder, (ignoring request path)
searchPaths = generateProfilingSearchPaths(Folder.PATH_SEPARATOR, locator, true);
profiled = findProfiledPageAndFolders(searchPaths, profiledPage, profiledFolder, profiledFolders, searchProfiledFolders);
// if profiled successfully at root fallback but failed previous
// attempt, profile request path against available alternate profile
// locators. This is used only to select a page: all other context
// information remains determined from fallback.
if (profiled && (pageContext.getLocators().size() > 1))
{
// profile to locate request path using alternate locators
Page [] alternateProfiledPage = new Page[1];
Iterator locatorsIter = selectAlternatePageProfileLocators(pageContext.getLocators()).iterator();
while ((alternateProfiledPage[0] == null) && locatorsIter.hasNext())
{
ProfileLocator alternateLocator = (ProfileLocator) locatorsIter.next();
List alternateSearchPaths = generateProfilingSearchPaths(requestPath, alternateLocator, false);
findProfiledPageAndFolders(alternateSearchPaths, alternateProfiledPage);
}
// if request path matched, use just profiled page; note: page is
// not used to generate page context, (fallback default root folder
// is used instead); otherwise continue with root default page match
if (alternateProfiledPage[0] != null)
{
log.debug("computeProfiledPageContext(): Using alternate locator match " + alternateProfiledPage[0] + " for " + requestPath);
profiledPage[0] = alternateProfiledPage[0];
}
else
{
log.warn("computeProfiledPageContext(): No alternate locator match: falling back to profiled root default page for " + requestPath);
}
}
else
{
// fallback to root default page
log.warn("computeProfiledPageContext(): Falling back to profiled root default page for " + requestPath);
}
}
// profiled folder and page
if (profiled)
{
folder = (Folder) setProfiledNodePathAndUrl((AbstractNode) profiledFolder[0]);
page = (Page) setProfiledNodePathAndUrl((AbstractNode) profiledPage[0]);
}
// profile page context if page and folder found
if ((page != null) && (folder != null))
{
// add profiled folders to all profiled folders list
allProfiledFolders = new ArrayList(24);
Iterator foldersIter = profiledFolders.iterator();
while (foldersIter.hasNext())
{
FolderImpl profiledPageFolder = (FolderImpl) foldersIter.next();
if (!profiledPageFolder.isHidden())
{
allProfiledFolders.add(setProfiledNodePathAndUrl(profiledPageFolder));
}
}
// profile general document/folder order
List documentOrder = null;
foldersIter = searchProfiledFolders.iterator();
while ((documentOrder == null) && foldersIter.hasNext())
{
FolderImpl profiledPageFolder = (FolderImpl) setProfiledNodePathAndUrl((AbstractNode) foldersIter.next());
if ((profiledPageFolder.getMetaData() != null) && (profiledPageFolder.getMetaData().getDocumentOrder() != null) &&
! profiledPageFolder.getMetaData().getDocumentOrder().isEmpty())
{
documentOrder = profiledPageFolder.getMetaData().getDocumentOrder();
}
}
Comparator documentComparator = new DocumentOrderComparator(documentOrder);
// 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())
{