Skip to content

Instantly share code, notes, and snippets.

@wouterd
Last active December 31, 2015 17:49
Show Gist options
  • Save wouterd/8022632 to your computer and use it in GitHub Desktop.
Save wouterd/8022632 to your computer and use it in GitHub Desktop.
public class SubjectHstSiteMapHandler extends ContentBeanAwareHstSiteMapItemHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(SubjectHstSiteMapHandler.class);
@Override
public ResolvedSiteMapItem process(ResolvedSiteMapItem resolvedSiteMapItem,
HttpServletRequest request,
HttpServletResponse response)
throws HstSiteMapItemHandlerException {
HippoBean contentBean = getContentBeanForResolvedSiteMapItem(resolvedSiteMapItem);
if (contentBean == null) {
LOGGER.info("No content bean found, reverting to initial site map item.");
return resolvedSiteMapItem;
}
boolean contentBeanIsSubject = contentBean instanceof SubjectBean;
if (!contentBeanIsSubject) {
LOGGER.error("Content bean is not a SubjectBean, so this handler cannot do anything, reverting to " +
"initial ResolvedSiteMapItem");
return resolvedSiteMapItem;
}
SubjectBean subject = (SubjectBean) contentBean;
String componentConfigurationId = deriveComponentConfigurationIdForSubject(resolvedSiteMapItem, subject);
if (componentConfigurationId == null) {
LOGGER.error("Subject of type {} cannot be resolved to a component configuration id, reverting to " +
"initial ResolvedSiteMapItem");
return resolvedSiteMapItem;
}
HstComponentConfiguration componentConfiguration =
ResolvedSiteMapItemUtils.obtainComponentConfiguration(resolvedSiteMapItem, componentConfigurationId);
return new HstResolvedSiteMapItemDecorator(
resolvedSiteMapItem,
componentConfiguration
);
}
private String deriveComponentConfigurationIdForSubject(final ResolvedSiteMapItem resolvedSiteMapItem,
final SubjectBean subject) {
String subjectType = subject.getType();
return getSiteMapItemHandlerConfiguration().getProperty(subjectType, resolvedSiteMapItem, String.class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment