searchFolders.clear();
}
// iterate through search paths looking for page in page manager content
int numSearchFoldersFound = 0;
Folder lastSearchFolderFound = null;
String lastSearchFolderFoundPath = null;
Iterator pathsIter = pageSearchPaths.iterator();
while (pathsIter.hasNext())
{
String searchRequestPath = (String) pathsIter.next();
log.debug("findProfiledPageAndFolders(), searchPath = " + searchRequestPath);
// search for matching folder and/or page in search path
String folderPath = searchRequestPath;
Folder searchFolder = null;
Page searchPage = null;
try
{
// match folder
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;
}
}
searchFolder = folderHandler.getFolder(folderPath);
// match page if not previously matched
if (page[0] == null)
{
String pagePath = searchRequestPath;
if (! pagePath.endsWith(Page.DOCUMENT_TYPE))
{
// only allow aggressive default page defaulting if
// trying to find page as last resort in root directory;
// otherwise, return only fallback page or explicitly
// specified default page name
boolean allowDefaulting = folderPath.equals( Folder.PATH_SEPARATOR );
pagePath = searchFolder.getDefaultPage(allowDefaulting);
// if page path not fallback default page, profile again
// to make sure the default page is not overridden, note
// that the fallback page has already been profiled since
// it would have been matched previously and that no
// override is possible in first maching folder.
if ((pagePath != null) && ! pagePath.equals(FolderImpl.FALLBACK_DEFAULT_PAGE) && (numSearchFoldersFound > 0))
{
// append default page to search paths
ListIterator pageSearchPathsIter = pageSearchPaths.listIterator();
while (pageSearchPathsIter.hasNext())
{
String pageSearchPath = (String) pageSearchPathsIter.next();
if (pageSearchPath.endsWith( Folder.PATH_SEPARATOR ))
{
pageSearchPathsIter.set(pageSearchPath + pagePath);
}
else
{
pageSearchPathsIter.set(pageSearchPath + Folder.PATH_SEPARATOR + pagePath);
}
}
// profile default page
log.debug("findProfiledPageAndFolders(): invoking again with default page: " + pagePath);
return findProfiledPageAndFolders(pageSearchPaths, page, folder, folders, searchFolders);
}
}
// access matched page
if (pagePath != null)
{
searchPage = ((FolderImpl)searchFolder).getPage(pagePath, false);
}
}
// track found search folders
numSearchFoldersFound++;
lastSearchFolderFound = searchFolder;
lastSearchFolderFoundPath = searchRequestPath;
}
catch (NodeException ne)
{
}
if (searchFolder != null)
{
log.debug("findProfiledPageAndFolders(), matched searchFolder = " + searchFolder);
}
if (searchPage != null)
{
log.debug("findProfiledPageAndFolders(), matched searchPage = " + searchPage);
}
// return matching page and related folders
if ((page[0] == null) && (searchPage != null))
{
// matched profiled folder/page
page[0] = searchPage;
if (folder != null)
{
folder[0] = searchFolder;
}
log.debug("findProfiledPageAndFolders(), using matched searchFolder = " + searchFolder);
log.debug("findProfiledPageAndFolders(), using matched searchPage = " + searchPage);
}
// return profiled folders and search profiled folders; the search
// profiled folders are used to find other profiled documents, (i.e
// document sets).
if ((folders != null) && (searchFolders != null))
{
if (searchFolder != null)
{
// profiled folder
folders.add(searchFolder);
// search parent profiled folders, (excluding profile property folders
// and including only first profile navigation folder found)
if (!searchFolder.getName().startsWith(PROFILE_NAVIGATION_PROPERTY_FOLDER_PREFIX))
{
do
{
searchFolders.add(searchFolder);
searchFolder = (Folder) ((AbstractNode)searchFolder).getParent(false);
}
while ((searchFolder != null) &&
!searchFolder.getName().startsWith(PROFILE_PROPERTY_FOLDER_PREFIX) &&
!searchFolder.getName().startsWith(PROFILE_NAVIGATION_PROPERTY_FOLDER_PREFIX));
}
if ((searchFolder != null) && searchFolder.getName().startsWith(PROFILE_NAVIGATION_PROPERTY_FOLDER_PREFIX))
{
searchFolders.add(searchFolder);
}
}
else
{
// add parents of missing profiled folders to search profiled
// folders if they exist
String searchFolderName = null;
do
{
// find parent path or folder
if (searchFolder == null)
{
// get parent folder path
int separatorIndex = folderPath.lastIndexOf(Folder.PATH_SEPARATOR);
if (separatorIndex > 0)
{
folderPath = folderPath.substring(0, separatorIndex);
}
else
{
folderPath = Folder.PATH_SEPARATOR;
}
// get folder if it exists and folder name
try
{
searchFolder = folderHandler.getFolder(folderPath);
searchFolderName = searchFolder.getName();
}
catch (NodeException ne)
{
separatorIndex = folderPath.lastIndexOf(Folder.PATH_SEPARATOR);
if (separatorIndex > 0)
{
searchFolderName = folderPath.substring(separatorIndex+1);
}
else
{
searchFolderName = Folder.PATH_SEPARATOR;
}
}
}
else
{
// get folder as parent of search folder
searchFolder = (Folder) ((AbstractNode)searchFolder).getParent(false);
if (searchFolder != null)
{
searchFolderName = searchFolder.getName();
}
}
// add to search profiled folders if it exists, (excluding
// profile property folders and including only first profile