use of org.broadleafcommerce.common.breadcrumbs.dto.BreadcrumbDTO in project BroadleafCommerce by BroadleafCommerce.
the class CategoryBreadcrumbServiceExtensionHandler method modifyBreadcrumbList.
public ExtensionResultStatusType modifyBreadcrumbList(String url, Map<String, String[]> params, ExtensionResultHolder<List<BreadcrumbDTO>> holder) {
// ProductBreadcrumb Handler strips off the productId and last fragment
String testUrl = (String) holder.getContextMap().get(BreadcrumbServiceExtensionManager.CONTEXT_PARAM_STRIPPED_URL);
if (StringUtils.isEmpty(testUrl)) {
testUrl = url;
}
Category category = determineFirstCategory(testUrl, params, holder);
if (category != null) {
BreadcrumbDTO categoryCrumb = buildCrumbForCategory(category, url, params);
BreadcrumbDTO categorySearchCrumb = buildCategorySearchCrumb(category, url, params);
List<BreadcrumbDTO> parentCrumbs = new ArrayList<BreadcrumbDTO>();
addParentCrumbs(parentCrumbs, category, url, params);
if (categorySearchCrumb != null) {
holder.getResult().add(0, categorySearchCrumb);
}
if (categoryCrumb != null) {
holder.getResult().add(0, categoryCrumb);
}
if (!parentCrumbs.isEmpty()) {
holder.getResult().addAll(0, parentCrumbs);
}
}
return ExtensionResultStatusType.HANDLED_CONTINUE;
}
use of org.broadleafcommerce.common.breadcrumbs.dto.BreadcrumbDTO in project BroadleafCommerce by BroadleafCommerce.
the class DefaultLinkedDataGeneratorImpl method addBreadcrumbData.
/**
* Generates an object representing the Schema.org BreadcrumbList
*
* @return JSON representation of BreadcrumbList from Schema.org
*/
protected JSONObject addBreadcrumbData(final HttpServletRequest request) throws JSONException {
final JSONObject breadcrumbObjects = new JSONObject();
breadcrumbObjects.put("@context", getStructuredDataContext());
breadcrumbObjects.put("@type", "BreadcrumbList");
final String requestUri = getRequestUri();
final Map<String, String[]> params = getRequestParams();
final List<BreadcrumbDTO> breadcrumbs = breadcrumbService.buildBreadcrumbDTOs(requestUri, params);
final JSONArray breadcrumbList = new JSONArray();
int index = 1;
for (final BreadcrumbDTO breadcrumb : breadcrumbs) {
final JSONObject listItem = new JSONObject();
listItem.put("@type", "ListItem");
listItem.put("position", index);
final JSONObject item = new JSONObject();
item.put("@id", getSiteBaseUrl() + breadcrumb.getLink());
item.put("name", breadcrumb.getText());
extensionManager.getProxy().addBreadcrumbItemData(request, item);
listItem.put("item", item);
extensionManager.getProxy().addBreadcrumbListItemData(request, listItem);
breadcrumbList.put(listItem);
index++;
}
extensionManager.getProxy().addBreadcrumbData(request, breadcrumbObjects);
breadcrumbObjects.put("itemListElement", breadcrumbList);
return breadcrumbObjects;
}
Aggregations