// 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 path;
// page id test must be performed since identical paths
// may occur in multiple site views
if (useHistory)
{
String requestPageId = (String)getFolderPageHistory().get(requestFolder.getPath());
if (requestPageId != null)
{
// find page by id in request folder pages
Iterator requestFolderPagesIter = requestFolderPages.iterator();
while ((requestPage == null) && (requestFolderPagesIter.hasNext()))
{
Page requestFolderPage = (Page)requestFolderPagesIter.next();
if (requestPageId.equals(requestFolderPage.getId()))
{
requestPage = requestFolderPage;
}
}
// log selected request page
if (requestPage != null)
{
if (log.isDebugEnabled())
{
log.debug("Selected folder historical page: path=" + view.getManagedPage(requestPage).getPath());
}
return requestPage;
}
}
}
// get default page for folder view 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 path
// and return default page
requestPage = requestFolder.getPage(defaultPageName);
if (!requestPage.isHidden())
{
getFolderPageHistory().put(requestFolder.getPath(), requestPage.getId());
}
// 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
// view in request folder; save last visited
// non-hidden page for folder path and return default page
requestPage = (Page)requestFolderPages.iterator().next();
if (!requestPage.isHidden())
{
getFolderPageHistory().put(requestFolder.getPath(), requestPage.getId());
}