Delegator delegator = FreeMarkerWorker.getWrappedObject("delegator", env);
LocalDispatcher dispatcher = FreeMarkerWorker.getWrappedObject("dispatcher", env);
Locale locale = (Locale) args.get("locale");
if (UtilValidate.isNotEmpty(productId)) {
GenericValue product = delegator.findOne("Product", UtilMisc.toMap("productId", productId), false);
ProductContentWrapper wrapper = new ProductContentWrapper(dispatcher, product, locale, "text/html");
url = CatalogUrlFilter.makeProductUrl(delegator, wrapper, null, ((StringModel) prefix).getAsString(), previousCategoryId, productCategoryId, productId);
} else {
GenericValue productCategory = delegator.findOne("ProductCategory", UtilMisc.toMap("productCategoryId", productCategoryId), false);
CategoryContentWrapper wrapper = new CategoryContentWrapper(dispatcher, productCategory, locale, "text/html");
url = CatalogUrlFilter.makeCategoryUrl(delegator, wrapper, null, ((StringModel) prefix).getAsString(), previousCategoryId, productCategoryId, productId, viewSize, viewIndex, viewSort, searchString);