Author: jleroux Date: Thu Oct 24 15:35:14 2013 New Revision: 1535416 URL: http://svn.apache.org/r1535416 Log: No functional changes, just formatting
Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/CatalogUrlFilter.java Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/CatalogUrlFilter.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/CatalogUrlFilter.java?rev=1535416&r1=1535415&r2=1535416&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/CatalogUrlFilter.java (original) +++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/CatalogUrlFilter.java Thu Oct 24 15:35:14 2013 @@ -50,37 +50,37 @@ import org.ofbiz.webapp.control.ContextF public class CatalogUrlFilter extends ContextFilter { public final static String module = CatalogUrlFilter.class.getName(); - + public static final String CONTROL_MOUNT_POINT = "control"; public static final String PRODUCT_REQUEST = "product"; public static final String CATEGORY_REQUEST = "category"; - + protected static String defaultLocaleString = null; protected static String redirectUrl = null; - + @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; Delegator delegator = (Delegator) httpRequest.getSession().getServletContext().getAttribute("delegator"); - - //Get ServletContext + + // Get ServletContext ServletContext servletContext = config.getServletContext(); - - //Set request attribute and session + + // Set request attribute and session UrlServletHelper.setRequestAttributes(request, delegator, servletContext); - + // set initial parameters String initDefaultLocalesString = config.getInitParameter("defaultLocaleString"); String initRedirectUrl = config.getInitParameter("redirectUrl"); defaultLocaleString = UtilValidate.isNotEmpty(initDefaultLocalesString) ? initDefaultLocalesString : ""; redirectUrl = UtilValidate.isNotEmpty(initRedirectUrl) ? initRedirectUrl : ""; - + String pathInfo = httpRequest.getServletPath(); if (UtilValidate.isNotEmpty(pathInfo)) { List<String> pathElements = StringUtil.split(pathInfo, "/"); String alternativeUrl = pathElements.get(0); - + String productId = null; String productCategoryId = null; String urlContentId = null; @@ -90,12 +90,14 @@ public class CatalogUrlFilter extends Co List<EntityCondition> productContentConds = FastList.newInstance(); productContentConds.add(EntityCondition.makeCondition("productContentTypeId", "ALTERNATIVE_URL")); productContentConds.add(EntityUtil.getFilterByDateExpr()); - List<GenericValue> productContentInfos = delegator.findList("ProductContentAndInfo", EntityCondition.makeCondition(productContentConds), null, UtilMisc.toList("-fromDate"), null, true); + List<GenericValue> productContentInfos = delegator.findList("ProductContentAndInfo", EntityCondition.makeCondition(productContentConds), null, + UtilMisc.toList("-fromDate"), null, true); if (UtilValidate.isNotEmpty(productContentInfos)) { - for (GenericValue productContentInfo : productContentInfos){ + for (GenericValue productContentInfo : productContentInfos) { String contentId = (String) productContentInfo.get("contentId"); - List<GenericValue> ContentAssocDataResourceViewTos = delegator.findByAnd("ContentAssocDataResourceViewTo", UtilMisc.toMap("contentIdStart", contentId, "caContentAssocTypeId", "ALTERNATE_LOCALE", "drDataResourceTypeId", "ELECTRONIC_TEXT"), null, true); - if (UtilValidate.isNotEmpty(ContentAssocDataResourceViewTos)){ + List<GenericValue> ContentAssocDataResourceViewTos = delegator.findByAnd("ContentAssocDataResourceViewTo", + UtilMisc.toMap("contentIdStart", contentId, "caContentAssocTypeId", "ALTERNATE_LOCALE", "drDataResourceTypeId", "ELECTRONIC_TEXT"), null, true); + if (UtilValidate.isNotEmpty(ContentAssocDataResourceViewTos)) { for (GenericValue ContentAssocDataResourceViewTo : ContentAssocDataResourceViewTos) { GenericValue ElectronicText = ContentAssocDataResourceViewTo.getRelatedOne("ElectronicText", true); if (UtilValidate.isNotEmpty(ElectronicText)) { @@ -113,9 +115,10 @@ public class CatalogUrlFilter extends Co } } } - } + } if (UtilValidate.isEmpty(productId)) { - List<GenericValue> contentDataResourceViews = delegator.findByAnd("ContentDataResourceView", UtilMisc.toMap("contentId", contentId, "drDataResourceTypeId", "ELECTRONIC_TEXT"), null, true); + List<GenericValue> contentDataResourceViews = delegator.findByAnd("ContentDataResourceView", + UtilMisc.toMap("contentId", contentId, "drDataResourceTypeId", "ELECTRONIC_TEXT"), null, true); for (GenericValue contentDataResourceView : contentDataResourceViews) { GenericValue ElectronicText = contentDataResourceView.getRelatedOne("ElectronicText", true); if (UtilValidate.isNotEmpty(ElectronicText)) { @@ -139,21 +142,23 @@ public class CatalogUrlFilter extends Co } } } - + // look for productCategoryId if (alternativeUrl.endsWith("-c")) { List<EntityCondition> productCategoryContentConds = FastList.newInstance(); productCategoryContentConds.add(EntityCondition.makeCondition("prodCatContentTypeId", "ALTERNATIVE_URL")); productCategoryContentConds.add(EntityUtil.getFilterByDateExpr()); - List<GenericValue> productCategoryContentInfos = delegator.findList("ProductCategoryContentAndInfo", EntityCondition.makeCondition(productCategoryContentConds), null, UtilMisc.toList("-fromDate"), null, true); + List<GenericValue> productCategoryContentInfos = delegator.findList("ProductCategoryContentAndInfo", + EntityCondition.makeCondition(productCategoryContentConds), null, UtilMisc.toList("-fromDate"), null, true); if (UtilValidate.isNotEmpty(productCategoryContentInfos)) { - for (GenericValue productCategoryContentInfo : productCategoryContentInfos){ + for (GenericValue productCategoryContentInfo : productCategoryContentInfos) { String contentId = (String) productCategoryContentInfo.get("contentId"); - List<GenericValue> ContentAssocDataResourceViewTos = delegator.findByAnd("ContentAssocDataResourceViewTo", UtilMisc.toMap("contentIdStart", contentId, "caContentAssocTypeId", "ALTERNATE_LOCALE", "drDataResourceTypeId", "ELECTRONIC_TEXT"), null, true); - if (UtilValidate.isNotEmpty(ContentAssocDataResourceViewTos)){ + List<GenericValue> ContentAssocDataResourceViewTos = delegator.findByAnd("ContentAssocDataResourceViewTo", + UtilMisc.toMap("contentIdStart", contentId, "caContentAssocTypeId", "ALTERNATE_LOCALE", "drDataResourceTypeId", "ELECTRONIC_TEXT"), null, true); + if (UtilValidate.isNotEmpty(ContentAssocDataResourceViewTos)) { for (GenericValue ContentAssocDataResourceViewTo : ContentAssocDataResourceViewTos) { GenericValue ElectronicText = ContentAssocDataResourceViewTo.getRelatedOne("ElectronicText", true); - if (UtilValidate.isNotEmpty(ElectronicText)){ + if (UtilValidate.isNotEmpty(ElectronicText)) { String textData = (String) ElectronicText.get("textData"); if (UtilValidate.isNotEmpty(textData)) { textData = UrlServletHelper.invalidCharacter(textData); @@ -170,9 +175,10 @@ public class CatalogUrlFilter extends Co } } } - } + } if (UtilValidate.isEmpty(productCategoryId)) { - List<GenericValue> contentDataResourceViews = delegator.findByAnd("ContentDataResourceView", UtilMisc.toMap("contentId", contentId, "drDataResourceTypeId", "ELECTRONIC_TEXT"), null, true); + List<GenericValue> contentDataResourceViews = delegator.findByAnd("ContentDataResourceView", + UtilMisc.toMap("contentId", contentId, "drDataResourceTypeId", "ELECTRONIC_TEXT"), null, true); for (GenericValue contentDataResourceView : contentDataResourceViews) { GenericValue ElectronicText = contentDataResourceView.getRelatedOne("ElectronicText", true); if (UtilValidate.isNotEmpty(ElectronicText)) { @@ -200,17 +206,18 @@ public class CatalogUrlFilter extends Co } catch (GenericEntityException e) { Debug.logWarning("Cannot look for product and product category", module); } - + // generate forward URL StringBuilder urlBuilder = new StringBuilder(); urlBuilder.append("/" + CONTROL_MOUNT_POINT); - + if (UtilValidate.isNotEmpty(productId)) { try { List<EntityCondition> conds = FastList.newInstance(); conds.add(EntityCondition.makeCondition("productId", productId)); conds.add(EntityUtil.getFilterByDateExpr()); - List<GenericValue> productCategoryMembers = delegator.findList("ProductCategoryMember", EntityCondition.makeCondition(conds), UtilMisc.toSet("productCategoryId"), UtilMisc.toList("-fromDate"), null, true); + List<GenericValue> productCategoryMembers = delegator.findList("ProductCategoryMember", EntityCondition.makeCondition(conds), + UtilMisc.toSet("productCategoryId"), UtilMisc.toList("-fromDate"), null, true); if (UtilValidate.isNotEmpty(productCategoryMembers)) { GenericValue productCategoryMember = EntityUtil.getFirst(productCategoryMembers); productCategoryId = productCategoryMember.getString("productCategoryId"); @@ -219,7 +226,7 @@ public class CatalogUrlFilter extends Co Debug.logError(e, "Cannot find product category for product: " + productId, module); } urlBuilder.append("/" + PRODUCT_REQUEST); - + } else { urlBuilder.append("/" + CATEGORY_REQUEST); } @@ -228,14 +235,15 @@ public class CatalogUrlFilter extends Co String topCategoryId = CategoryWorker.getCatalogTopCategory(httpRequest, null); List<GenericValue> trailCategories = CategoryWorker.getRelatedCategoriesRet(httpRequest, "trailCategories", topCategoryId, false, false, true); List<String> trailCategoryIds = EntityUtil.getFieldListFromEntityList(trailCategories, "productCategoryId", true); - + // look for productCategoryId from productId if (UtilValidate.isNotEmpty(productId)) { try { List<EntityCondition> rolllupConds = FastList.newInstance(); rolllupConds.add(EntityCondition.makeCondition("productId", productId)); rolllupConds.add(EntityUtil.getFilterByDateExpr()); - List<GenericValue> productCategoryMembers = delegator.findList("ProductCategoryMember", EntityCondition.makeCondition(rolllupConds), null, UtilMisc.toList("-fromDate"), null, true); + List<GenericValue> productCategoryMembers = delegator.findList("ProductCategoryMember", EntityCondition.makeCondition(rolllupConds), null, + UtilMisc.toList("-fromDate"), null, true); for (GenericValue productCategoryMember : productCategoryMembers) { String trailCategoryId = productCategoryMember.getString("productCategoryId"); if (trailCategoryIds.contains(trailCategoryId)) { @@ -259,7 +267,8 @@ public class CatalogUrlFilter extends Co List<EntityCondition> rolllupConds = FastList.newInstance(); rolllupConds.add(EntityCondition.makeCondition("productCategoryId", parentProductCategoryId)); rolllupConds.add(EntityUtil.getFilterByDateExpr()); - List<GenericValue> productCategoryRollups = delegator.findList("ProductCategoryRollup", EntityCondition.makeCondition(rolllupConds), null, UtilMisc.toList("-fromDate"), null, true); + List<GenericValue> productCategoryRollups = delegator.findList("ProductCategoryRollup", EntityCondition.makeCondition(rolllupConds), null, + UtilMisc.toList("-fromDate"), null, true); if (UtilValidate.isNotEmpty(productCategoryRollups)) { // add only categories that belong to the top category to trail for (GenericValue productCategoryRollup : productCategoryRollups) { @@ -278,7 +287,7 @@ public class CatalogUrlFilter extends Co } } Collections.reverse(trailElements); - + List<String> trail = CategoryWorker.getTrail(httpRequest); if (trail == null) { trail = FastList.newInstance(); @@ -290,7 +299,7 @@ public class CatalogUrlFilter extends Co previousCategoryId = trail.get(trail.size() - 1); } trail = CategoryWorker.adjustTrail(trail, productCategoryId, previousCategoryId); - + if (trailElements.size() == 1) { CategoryWorker.setTrail(request, trailElements.get(0), null); } else if (trailElements.size() == 2) { @@ -312,14 +321,14 @@ public class CatalogUrlFilter extends Co } request.setAttribute("productCategoryId", productCategoryId); - + if (productId != null) { request.setAttribute("product_id", productId); request.setAttribute("productId", productId); } } - - //Set view query parameters + + // Set view query parameters UrlServletHelper.setViewQueryParameters(request, urlBuilder); if (UtilValidate.isNotEmpty(productId) || UtilValidate.isNotEmpty(productCategoryId) || UtilValidate.isNotEmpty(urlContentId)) { Debug.logInfo("[Filtered request]: " + pathInfo + " (" + urlBuilder + ")", module); @@ -327,32 +336,35 @@ public class CatalogUrlFilter extends Co dispatch.forward(request, response); return; } - - //Check path alias + + // Check path alias UrlServletHelper.checkPathAlias(request, httpResponse, delegator, pathInfo); } - + // we're done checking; continue on chain.doFilter(request, response); } - - public static String makeCategoryUrl(HttpServletRequest request, String previousCategoryId, String productCategoryId, String productId, String viewSize, String viewIndex, String viewSort, String searchString) { + + public static String makeCategoryUrl(HttpServletRequest request, String previousCategoryId, String productCategoryId, String productId, String viewSize, String viewIndex, + String viewSort, String searchString) { Delegator delegator = (Delegator) request.getAttribute("delegator"); try { GenericValue productCategory = delegator.findOne("ProductCategory", UtilMisc.toMap("productCategoryId", productCategoryId), true); CategoryContentWrapper wrapper = new CategoryContentWrapper(productCategory, request); List<String> trail = CategoryWorker.getTrail(request); - return makeCategoryUrl(delegator, wrapper, trail, request.getContextPath(), previousCategoryId, productCategoryId, productId, viewSize, viewIndex, viewSort, searchString); + return makeCategoryUrl(delegator, wrapper, trail, request.getContextPath(), previousCategoryId, productCategoryId, productId, viewSize, viewIndex, viewSort, + searchString); } catch (GenericEntityException e) { Debug.logWarning(e, "Cannot create category's URL for: " + productCategoryId, module); return redirectUrl; } } - public static String makeCategoryUrl(Delegator delegator, CategoryContentWrapper wrapper, List<String> trail, String contextPath, String previousCategoryId, String productCategoryId, String productId, String viewSize, String viewIndex, String viewSort, String searchString) { + public static String makeCategoryUrl(Delegator delegator, CategoryContentWrapper wrapper, List<String> trail, String contextPath, String previousCategoryId, + String productCategoryId, String productId, String viewSize, String viewIndex, String viewSort, String searchString) { String url = ""; StringWrapper alternativeUrl = wrapper.get("ALTERNATIVE_URL"); - + if (UtilValidate.isNotEmpty(alternativeUrl) && UtilValidate.isNotEmpty(alternativeUrl.toString())) { StringBuilder urlBuilder = new StringBuilder(); urlBuilder.append(contextPath); @@ -396,20 +408,20 @@ public class CatalogUrlFilter extends Co urlBuilder.append("searchString=" + searchString + "&"); } if (urlBuilder.toString().endsWith("&")) { - return urlBuilder.toString().substring(0, urlBuilder.toString().length()-1); + return urlBuilder.toString().substring(0, urlBuilder.toString().length() - 1); } - + url = urlBuilder.toString(); } else { - if(UtilValidate.isEmpty(trail)){ + if (UtilValidate.isEmpty(trail)) { trail = FastList.newInstance(); } url = CatalogUrlServlet.makeCatalogUrl(contextPath, trail, productId, productCategoryId, previousCategoryId); } - + return url; } - + public static String makeProductUrl(HttpServletRequest request, String previousCategoryId, String productCategoryId, String productId) { Delegator delegator = (Delegator) request.getAttribute("delegator"); String url = null; @@ -425,7 +437,8 @@ public class CatalogUrlFilter extends Co return url; } - public static String makeProductUrl(Delegator delegator, ProductContentWrapper wrapper,List<String> trail, String contextPath, String previousCategoryId, String productCategoryId, String productId) { + public static String makeProductUrl(Delegator delegator, ProductContentWrapper wrapper, List<String> trail, String contextPath, String previousCategoryId, + String productCategoryId, String productId) { String url = ""; StringWrapper alternativeUrl = wrapper.get("ALTERNATIVE_URL"); if (UtilValidate.isNotEmpty(alternativeUrl) && UtilValidate.isNotEmpty(alternativeUrl.toString())) { @@ -444,7 +457,7 @@ public class CatalogUrlFilter extends Co } url = urlBuilder.toString(); } else { - if(UtilValidate.isEmpty(trail)){ + if (UtilValidate.isEmpty(trail)) { trail = FastList.newInstance(); } url = CatalogUrlServlet.makeCatalogUrl(contextPath, trail, productId, productCategoryId, previousCategoryId);