コード例 #1
0
  /**
   * Generate the trailing breadcrumb items. By default, the trailing items are derived from the
   * bean structure of the resolved sitemap item of the current request.
   *
   * @param request
   * @param deepestMenuItem
   * @return list of trailing breadcrumb items
   */
  protected List<BreadcrumbItem> getTrailingBreadcrumbItems(
      HstRequest request, HstSiteMenuItem menuItem) {

    List<BreadcrumbItem> items = new ArrayList<BreadcrumbItem>();

    ResolvedSiteMapItem currentSmi = request.getRequestContext().getResolvedSiteMapItem();
    HippoBean currentBean = getComponent().getBeanForResolvedSiteMapItem(request, currentSmi);

    if (currentBean != null) {

      if (addTrailingDocumentOnly) {
        if (currentBean instanceof HippoDocument) {
          items.add(getBreadcrumbItem(request, currentBean));
        }
      } else {
        ResolvedSiteMapItem menuItemSmi = menuItem.resolveToSiteMapItem(request);
        HippoBean menuItemBean = getComponent().getBeanForResolvedSiteMapItem(request, menuItemSmi);

        // parent steps based on ancestor bean
        if (menuItemBean != null && menuItemBean.isAncestor(currentBean)) {

          while (!currentBean.isSelf(menuItemBean)) {
            items.add(getBreadcrumbItem(request, currentBean));
            currentBean = currentBean.getParentBean();
          }
        }

        // try to determine parent steps based on path info in case the
        // menuItemBean is not an ancestor, which occurs for instance
        // when faceted navigation is used on the menu item
        else {
          String ancestorPath = menuItemSmi.getPathInfo();
          String currentPath = currentSmi.getPathInfo();

          if (currentPath.startsWith(ancestorPath)) {
            String trailingPath = currentPath.substring(ancestorPath.length());

            if (trailingPath.startsWith("/")) {
              trailingPath = trailingPath.substring(1);
            }

            int steps = trailingPath.split("/").length;

            for (int i = 0; i < steps; i++) {
              items.add(getBreadcrumbItem(request, currentBean));
              currentBean = currentBean.getParentBean();
            }
          }
        }

        Collections.reverse(items);
      }
    }

    return items;
  }
コード例 #2
0
  /**
   * Generate the breadcrumb items which correspond to the expanded menu item tree.
   *
   * @param request
   * @param deepestMenuItem
   * @return list of menu breadcrumb items
   */
  protected List<BreadcrumbItem> getMenuBreadcrumbItems(
      HstRequest request, HstSiteMenuItem menuItem) {
    List<BreadcrumbItem> items = new ArrayList<BreadcrumbItem>();

    while (menuItem != null) {
      items.add(getBreadcrumbItem(request, menuItem));
      menuItem = menuItem.getParentItem();
    }

    Collections.reverse(items);

    return items;
  }
コード例 #3
0
 /**
  * Creates a breadcrumb item belonging to a sitemenu item
  *
  * @param request
  * @param menuItem
  * @return breadcrumb item
  */
 protected BreadcrumbItem getBreadcrumbItem(HstRequest request, HstSiteMenuItem menuItem) {
   return new BreadcrumbItem(menuItem.getHstLink(), menuItem.getName());
 }