if (breadcrumbs.size() < 3) { return null; }
List<NavigationNode> menu = new ArrayList<NavigationNode>();
SitemapNode overviewBreadcrumb = breadcrumbs.get(2);
SitemapNode overviewMapNode = sitemap.getNode(overviewBreadcrumb.getId());
String resolvedPath = sitemap.resolve(overviewMapNode.getPath(), context);
NavigationNode overviewNavNode =
new NavigationNode(overviewMapNode.getId(), "Overview", resolvedPath, false, false);
menu.add(overviewNavNode);
List<SitemapNode> children = overviewMapNode.getChildren();
for (SitemapNode child : children) {
if (!child.getShowInDetailsSidebar()) { continue; }
String resolvedChildName = sitemap.resolve(child.getName(), context);
String resolvedChildPath = sitemap.resolve(child.getPath(), context);
List<SitemapNode> grandchildren = child.getChildren();
NavigationNode childNavNode =
new NavigationNode(child.getId(), resolvedChildName, resolvedChildPath, false, false);
menu.add(childNavNode);
boolean foundGrandchild = false;
for (SitemapNode grandchild : grandchildren) {
if (!grandchild.getShowInDetailsSidebar()) { continue; }
foundGrandchild = true;
String resolvedGcName = sitemap.resolve(grandchild.getName(), context);
String resolvedGcPath = sitemap.resolve(grandchild.getPath(), context);
NavigationNode gcNavNode =
new NavigationNode(grandchild.getId(), resolvedGcName, resolvedGcPath, false, false);
menu.add(gcNavNode);
}
if (foundGrandchild) {
childNavNode.setHeader(true);
}
}
// Find the active node. Search from the end of the list to ensure that we check lower nodes before higher ones.
int menuSize = menu.size();
matchMenuItem: for (int i = menuSize - 1; i >= 0; i--) {
NavigationNode menuItem = menu.get(i);
String menuItemId = menuItem.getId();
// Compare the current node to the current menu item's ancestry to find a match.
SitemapNode sitemapNode = getCurrentNode();
while (!sitemapNode.getId().equals(menuItemId)) {
sitemapNode = sitemapNode.getParent();
if (sitemapNode == null) {
continue matchMenuItem;
}
}