// only request folders with pages can be
// selected by request; otherwise, fall back to
// parent folders assuming that immediate parents
// will have the most appropriate default page
NodeSet requestFolderPages = null;
if (requestFolder != null)
{
try
{
requestFolderPages = requestFolder.getPages();
while (((requestFolderPages == null) || requestFolderPages.isEmpty()) && (requestFolder.getParent() != null))
{
requestFolder = (Folder)requestFolder.getParent();
requestFolderPages = requestFolder.getPages();
}
}
catch (NodeException ne)
{
requestFolderPages = null;
}
catch (SecurityException se)
{
requestFolderPages = null;
accessException = se;
}
}
if ((requestFolder != null) && (requestFolderPages != null) && !requestFolderPages.isEmpty())
{
Page requestPage = null;
// attempt to lookup last visited page by folder proxy
// path, (proxies are hashed by their path), contains
// test must be performed since identical paths may
// occur in multiple site views
if (useHistory)
{
requestPage = (Page)folderPageHistory.get(requestFolder);
if ((requestPage != null) && requestFolderPages.contains(requestPage))
{
// log selected request page
if (log.isDebugEnabled())
{
log.debug("Selected folder historical page: path=" + view.getManagedPage(requestPage).getPath());
}
return requestPage;
}
}
// get default page for folder proxy if more than one
// page is available to choose from
if (requestFolderPages.size() > 1)
{
String defaultPageName = requestFolder.getDefaultPage();
if (defaultPageName == null)
{
// use fallback default if default page
// not explicitly specified
defaultPageName = Folder.FALLBACK_DEFAULT_PAGE;
}
try
{
// save last visited non-hidden page for folder proxy
// path, (proxies are hashed by their path), and
// return default page
requestPage = requestFolder.getPage(defaultPageName);
if (!requestPage.isHidden())
{
folderPageHistory.put(requestFolder, requestPage);
}
// log selected request page
if (log.isDebugEnabled())
{
log.debug("Selected folder default page: path=" + view.getManagedPage(requestPage).getPath());
}
return requestPage;
}
catch (NodeException ne)
{
}
catch (NodeNotFoundException nnfe)
{
}
catch (SecurityException se)
{
accessException = se;
}
}
// default page not available, select first page
// proxy in request folder; save last visited
// non-hidden page for folder proxy path, (proxies
// are hashed by their path), and return default page
requestPage = (Page)requestFolderPages.iterator().next();
if (!requestPage.isHidden())
{
folderPageHistory.put(requestFolder, requestPage);
}