private String showCatalog(ModelMap model, HttpServletRequest request, CatalogSort catalogSort) {
    addCategoryToModel(request, model);
    boolean productFound = addProductsToModel(request, model, catalogSort);

    String view = defaultCategoryView;
    if (productFound) {
      // TODO: Nice to have: product logic similar to category below
      view = defaultProductView;
    } else {
      Category currentCategory = (Category) model.get("currentCategory");
      if (currentCategory.getUrl() != null && !"".equals(currentCategory.getUrl())) {
        return "redirect:" + currentCategory.getUrl();
      } else if (currentCategory.getDisplayTemplate() != null
          && !"".equals(currentCategory.getUrl())) {
        view = categoryTemplatePrefix + currentCategory.getDisplayTemplate();
      } else {
        if ("true".equals(request.getParameter("ajax"))) {
          view = "catalog/categoryView/mainContentFragment";
        } else {
          view = defaultCategoryView;
        }
      }
    }

    if (catalogSort == null) {
      model.addAttribute("catalogSort", new CatalogSort());
    }

    List<Order> wishlists =
        cartService.findOrdersForCustomer(customerState.getCustomer(request), OrderStatus.NAMED);
    model.addAttribute("wishlists", wishlists);

    return view;
  }
  protected void addCategorySiteMapEntries(
      Category parentCategory,
      int currentDepth,
      CategorySiteMapGeneratorConfiguration categorySMGC,
      SiteMapBuilder siteMapBuilder) {
    // If we've reached beyond the ending depth, don't proceed
    if (currentDepth > categorySMGC.getEndingDepth()) {
      return;
    }

    // If we're at or past the starting depth, add this category to the site map
    if (currentDepth >= categorySMGC.getStartingDepth()) {
      constructSiteMapURL(categorySMGC, siteMapBuilder, parentCategory);
    }

    // Recurse on child categories in batches of size rowLimit
    int rowOffset = 0;
    List<Category> categories;
    do {
      categories =
          categoryDao.readActiveSubCategoriesByCategory(parentCategory, rowLimit, rowOffset);
      rowOffset += categories.size();
      for (Category category : categories) {
        if (StringUtils.isNotEmpty(category.getUrl())) {
          addCategorySiteMapEntries(category, currentDepth + 1, categorySMGC, siteMapBuilder);
        } else {
          LOG.debug("Skipping empty category URL: " + category.getId());
        }
      }
    } while (categories.size() == rowLimit);
  }
  protected void addCategoryToModel(HttpServletRequest request, ModelMap model) {
    Category rootCategory = null;
    if (getRootCategoryId() != null) {
      rootCategory = catalogService.findCategoryById(getRootCategoryId());
    } else if (getRootCategoryName() != null) {
      rootCategory = catalogService.findCategoryByName(getRootCategoryName());
    }

    if (rootCategory == null) {
      throw new IllegalStateException(
          "Catalog Controller configured incorrectly - rootId category not found: "
              + rootCategoryId);
    }

    String url =
        pathHelper.getRequestUri(request).substring(pathHelper.getContextPath(request).length());
    String categoryId = request.getParameter("categoryId");
    if (categoryId != null) {
      Category category = catalogService.findCategoryById(new Long(categoryId));
      if (category != null) {
        url = category.getUrl();
      }
    }

    List<Long> categoryIdList =
        catalogService.getChildCategoryURLMapByCategoryId(rootCategory.getId()).get(url);
    List<Category> categoryList = null;
    if (categoryIdList != null) {
      categoryList = new ArrayList<Category>(categoryIdList.size());
      for (Long id : categoryIdList) {
        categoryList.add(catalogService.findCategoryById(id));
      }
    }

    addCategoryListToModel(categoryList, rootCategory, url, model);
    model.addAttribute("rootCategory", rootCategory);
  }
 protected String generateUri(SiteMapBuilder siteMapBuilder, Category category) {
   return BroadleafFileUtils.appendUnixPaths(siteMapBuilder.getBaseUrl(), category.getUrl());
 }