targetPage = (Page) getRequest().getAttribute(WebloungeRequest.PAGE);
// If no page was specified, take homepage instead.
if (targetPage == null) {
ResourceURI homeURI = new PageURIImpl(site, "/");
try {
targetPage = (Page) contentRepository.get(homeURI);
if (targetPage == null) {
logger.warn("No page was found while processing composer on " + url);
return;
}
} catch (SecurityException e) {
logger.warn("Composer '" + id + "' was unable to choose homepage as fallback: " + e.getMessage());
return;
} catch (ContentRepositoryException e) {
logger.warn("Composer '" + id + "' was unable to choose homepage as fallback: " + e.getMessage());
return;
}
}
if (contentProvider == null)
contentProvider = targetPage;
Pagelet[] content = contentProvider.getPagelets(id);
Pagelet[] ghostContent = new Pagelet[0];
// If composer is empty and ghost content is enabled, go up the page
// hierarchy and try to find content for this composer
Page contentPage = contentProvider;
if (content.length == 0 && inheritFromParent) {
String pageUrl = contentPage.getURI().getPath();
while (ghostContent.length == 0 && pageUrl.length() > 1) {
if (pageUrl.endsWith("/") && !"/".equals(pageUrl))
pageUrl = pageUrl.substring(0, pageUrl.length() - 1);
int urlSeparator = pageUrl.lastIndexOf("/");
if (urlSeparator < 0) {
contentPage = null;
break;
} else {
pageUrl = pageUrl.substring(0, urlSeparator);
if ("".equals(pageUrl))
pageUrl = "/";
ResourceURI pageURI = new PageURIImpl(site, pageUrl);
try {
contentPage = (Page) contentRepository.get(pageURI);
} catch (SecurityException e) {
logger.debug("Prevented loading of protected content from inherited page {} for composer {}", pageURI, id);
}