String decocedTargetUrl = null;
String encoding = request.getCharacterEncoding();
if (encoding == null)
encoding = "utf-8";
decocedTargetUrl = URLDecoder.decode(targetPage, encoding);
target = new PageURIImpl(site, decocedTargetUrl);
} catch (UnsupportedEncodingException e) {
logger.warn("Error while decoding target url {}: {}", targetPage, e.getMessage());
target = new PageURIImpl(site, "/");
}
}
// Check the action configuration
else if (action instanceof HTMLAction) {
HTMLAction htmlAction = (HTMLAction) action;
if (htmlAction.getPageURI() != null) {
target = htmlAction.getPageURI();
targetForced = true;
}
}
// Nothing found, let's choose the site's homepage
if (target == null) {
target = new PageURIImpl(site, "/");
}
// We are about to render the action output in the composers of the target
// page. This is why we have to make sure that this target page exists,
// otherwise the user will get a 404.
ContentRepository contentRepository = site.getContentRepository();
if (contentRepository == null) {
logger.warn("Content repository not available to read target page for action '{}'", action, target);
return null;
}
// Does the page exist?
page = (Page) contentRepository.get(target);
if (page == null) {
if (targetForced) {
logger.warn("Output of action '{}' is configured to render on non existing page {}", action, target);
return null;
}
// Fall back to site homepage
target = new PageURIImpl(site, "/");
page = (Page) contentRepository.get(target);
if (page == null) {
logger.debug("Site {} has no homepage as fallback to render actions", site);
return null;
}