Author: jonesde
Date: Thu Jan 18 23:54:53 2007 New Revision: 497728 URL: http://svn.apache.org/viewvc?view=rev&rev=497728 Log: Some cleanups for the CategoryWorker.getCategoryContentWrappers method, which was implemented with a really weird pattern; also fixed problem in that method with infinite recursion Modified: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/breadcrumbs.bsh ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/sidedeepcategory.bsh ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryWorker.java ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/find/sidedeepcategory.bsh ofbiz/trunk/applications/product/webapp/catalog/find/sidedeepcategory.ftl Modified: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/breadcrumbs.bsh URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/breadcrumbs.bsh?view=diff&rev=497728&r1=497727&r2=497728 ============================================================================== --- ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/breadcrumbs.bsh (original) +++ ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/breadcrumbs.bsh Thu Jan 18 23:54:53 2007 @@ -1,7 +1,4 @@ /* - * - * Copyright 2001-2006 The Apache Software Foundation - * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at @@ -21,13 +18,12 @@ */ import org.ofbiz.base.util.*; -import org.ofbiz.product.catalog.*; import org.ofbiz.product.category.*; +import javolution.util.FastMap; -requestParameters = UtilHttp.getParameterMap(request); -catIterator = UtilMisc.toIterator(request.getAttribute("topLevelList")); -if(catIterator != null) { - catContentWrappers = new HashMap(); - catContentWrappers = CategoryWorker.getCategoryContentWrappers(catContentWrappers, catIterator, request); +categoryList = request.getAttribute("topLevelList"); +if(categoryList != null) { + catContentWrappers = FastMap.newInstance(); + CategoryWorker.getCategoryContentWrappers(catContentWrappers, categoryList, request); context.put("catContentWrappers", catContentWrappers); } Modified: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/sidedeepcategory.bsh URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/sidedeepcategory.bsh?view=diff&rev=497728&r1=497727&r2=497728 ============================================================================== --- ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/sidedeepcategory.bsh (original) +++ ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/sidedeepcategory.bsh Thu Jan 18 23:54:53 2007 @@ -1,7 +1,4 @@ /* - * - * Copyright 2001-2006 The Apache Software Foundation - * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at @@ -23,6 +20,7 @@ import org.ofbiz.base.util.*; import org.ofbiz.product.catalog.*; import org.ofbiz.product.category.*; +import javolution.util.FastMap; requestParameters = UtilHttp.getParameterMap(request); @@ -31,9 +29,9 @@ request.setAttribute("curCategoryId", curCategoryId); CategoryWorker.setTrail(request, curCategoryId); -catIterator = UtilMisc.toIterator(request.getAttribute("topLevelList")); -if(catIterator != null) { - catContentWrappers = new HashMap(); - catContentWrappers = CategoryWorker.getCategoryContentWrappers(catContentWrappers, catIterator, request); +categoryList = request.getAttribute("topLevelList"); +if(categoryList != null) { + catContentWrappers = FastMap.newInstance(); + CategoryWorker.getCategoryContentWrappers(catContentWrappers, categoryList, request); context.put("catContentWrappers", catContentWrappers); } Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryWorker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryWorker.java?view=diff&rev=497728&r1=497727&r2=497728 ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryWorker.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryWorker.java Thu Jan 18 23:54:53 2007 @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -31,14 +30,18 @@ import javax.servlet.http.HttpSession; import javax.servlet.jsp.PageContext; -import org.ofbiz.base.util.*; +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilDateTime; +import org.ofbiz.base.util.UtilFormatOut; +import org.ofbiz.base.util.UtilHttp; +import org.ofbiz.base.util.UtilMisc; import org.ofbiz.entity.GenericDelegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.condition.EntityCondition; +import org.ofbiz.entity.condition.EntityConditionList; import org.ofbiz.entity.condition.EntityExpr; import org.ofbiz.entity.condition.EntityOperator; -import org.ofbiz.entity.condition.EntityConditionList; -import org.ofbiz.entity.condition.EntityCondition; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.product.product.ProductWorker; @@ -421,21 +424,27 @@ return newList; } - public static HashMap getCategoryContentWrappers(HashMap catContentWrappers, Iterator catIterator, HttpServletRequest request) throws GenericEntityException { + public static void getCategoryContentWrappers(Map catContentWrappers, List categoryList, HttpServletRequest request) throws GenericEntityException { + if (catContentWrappers == null || categoryList == null) { + return; + } + Iterator catIterator = categoryList.iterator(); while(catIterator.hasNext()) { GenericValue cat = (GenericValue) catIterator.next(); + String productCategoryId = (String) cat.get("productCategoryId"); + + if (catContentWrappers.containsKey(productCategoryId)) { + // if this ID is already in the Map, skip it (avoids inefficiency, infinite recursion, etc.) + continue; + } + CategoryContentWrapper catContentWrapper = new CategoryContentWrapper(cat, request); - String id = (String) cat.get("productCategoryId"); - catContentWrappers.put(id, catContentWrapper); + catContentWrappers.put(productCategoryId, catContentWrapper); ArrayList subCat = new ArrayList(); - subCat = getRelatedCategoriesRet(request, "subCatList", id, true); + subCat = getRelatedCategoriesRet(request, "subCatList", productCategoryId, true); if(subCat != null) { - Iterator subCatIterator = UtilMisc.toIterator(subCat); - if(subCatIterator != null) { - getCategoryContentWrappers(catContentWrappers, subCatIterator, request ); - } + getCategoryContentWrappers(catContentWrappers, subCat, request ); } } - return catContentWrappers; } } Modified: ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/find/sidedeepcategory.bsh URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/find/sidedeepcategory.bsh?view=diff&rev=497728&r1=497727&r2=497728 ============================================================================== --- ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/find/sidedeepcategory.bsh (original) +++ ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/actions/find/sidedeepcategory.bsh Thu Jan 18 23:54:53 2007 @@ -1,7 +1,4 @@ /* - * - * Copyright 2001-2006 The Apache Software Foundation - * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at @@ -18,6 +15,7 @@ import org.ofbiz.base.util.*; import org.ofbiz.entity.*; import org.ofbiz.product.category.*; +import javolution.util.FastMap; delegator = request.getAttribute("delegator"); @@ -49,9 +47,9 @@ context.put("curCategoryId", curCategoryId); context.put("currentTopCategory", currentTopCategory); -catIterator = UtilMisc.toIterator(request.getAttribute("topLevelList")); -if(catIterator != null) { - catContentWrappers = new HashMap(); - catContentWrappers = CategoryWorker.getCategoryContentWrappers(catContentWrappers, catIterator, request); +categoryList = request.getAttribute("topLevelList"); +if(categoryList != null) { + catContentWrappers = FastMap.newInstance(); + CategoryWorker.getCategoryContentWrappers(catContentWrappers, categoryList, request); context.put("catContentWrappers", catContentWrappers); } Modified: ofbiz/trunk/applications/product/webapp/catalog/find/sidedeepcategory.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/find/sidedeepcategory.ftl?view=diff&rev=497728&r1=497727&r2=497728 ============================================================================== --- ofbiz/trunk/applications/product/webapp/catalog/find/sidedeepcategory.ftl (original) +++ ofbiz/trunk/applications/product/webapp/catalog/find/sidedeepcategory.ftl Thu Jan 18 23:54:53 2007 @@ -1,7 +1,4 @@ <#-- - -Copyright 2001-2006 The Apache Software Foundation - Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at |
Free forum by Nabble | Edit this page |