@Override
 protected void fillModel(
     final HttpServletRequest request,
     final Model model,
     final CategoryFeatureComponentModel component) {
   final CategoryModel category = component.getCategory();
   if (category != null) {
     final String url = categoryUrlConverter.convert(category).getUrl();
     model.addAttribute("url", url);
   }
 }
Пример #2
0
  public static String getUrlForCMSLinkComponent(
      final CMSLinkComponentModel component,
      final Converter<ProductModel, ProductData> productUrlConverter,
      final Converter<CategoryModel, CategoryData> categoryUrlConverter) {
    // Try to get the URL from the component
    {
      final String url = component.getUrl();
      if (url != null && !url.isEmpty()) {
        return url;
      }
    }

    // Try to get the label for the content page
    {
      final ContentPageModel contentPage = component.getContentPage();
      if (contentPage != null) {
        return contentPage.getLabel();
      }
    }

    // Try to get the category and build a URL to the category
    final CategoryModel category = component.getCategory();
    if (category != null) {
      if (categoryUrlConverter != null) {
        return categoryUrlConverter.convert(category).getUrl();
      } else {
        return getCategoryUrlConverter(getCurrentRequest()).convert(category).getUrl();
      }
    }

    // Try to get the product and build a URL to the product
    final ProductModel product = component.getProduct();
    if (product != null) {
      if (productUrlConverter != null) {
        productUrlConverter.convert(product).getUrl();
      } else {
        return getProductUrlConverter(getCurrentRequest()).convert(product).getUrl();
      }
    }
    return null;
  }