1 24 package org.ofbiz.product.config; 25 26 import javax.servlet.http.HttpServletRequest ; 27 28 import org.ofbiz.base.util.Debug; 29 import org.ofbiz.base.util.UtilHttp; 30 import org.ofbiz.entity.GenericDelegator; 31 import org.ofbiz.entity.GenericValue; 32 import org.ofbiz.product.catalog.CatalogWorker; 33 import org.ofbiz.product.store.ProductStoreWorker; 34 import org.ofbiz.service.LocalDispatcher; 35 import org.ofbiz.base.util.cache.UtilCache; 36 37 45 public class ProductConfigWorker { 46 47 public static final String module = ProductConfigWorker.class.getName(); 48 public static final String resource = "ProductUiLabels"; 49 public static final String SEPARATOR = "::"; 51 public static UtilCache productConfigCache = new UtilCache("product.config", true); 53 public static ProductConfigWrapper getProductConfigWrapper(String productId, String currencyUomId, HttpServletRequest request) { 54 ProductConfigWrapper configWrapper = null; 55 String catalogId = CatalogWorker.getCurrentCatalogId(request); 56 String webSiteId = CatalogWorker.getWebSiteId(request); 57 String productStoreId = ProductStoreWorker.getProductStoreId(request); 58 GenericValue autoUserLogin = (GenericValue)request.getSession().getAttribute("autoUserLogin"); 59 try { 60 63 String cacheKey = productId + SEPARATOR + productStoreId + SEPARATOR + catalogId + SEPARATOR + webSiteId + SEPARATOR + currencyUomId; 64 if (!productConfigCache.containsKey(cacheKey)) { 65 configWrapper = new ProductConfigWrapper((GenericDelegator)request.getAttribute("delegator"), 66 (LocalDispatcher)request.getAttribute("dispatcher"), 67 productId, productStoreId, catalogId, webSiteId, 68 currencyUomId, UtilHttp.getLocale(request), 69 autoUserLogin); 70 productConfigCache.put(cacheKey, new ProductConfigWrapper(configWrapper)); 71 } else { 72 configWrapper = new ProductConfigWrapper((ProductConfigWrapper)productConfigCache.get(cacheKey)); 73 } 74 } catch(ProductConfigWrapperException we) { 75 configWrapper = null; 76 } catch(Exception e) { 77 Debug.logWarning(e.getMessage(), module); 78 } 79 return configWrapper; 80 } 81 82 public static void fillProductConfigWrapper(ProductConfigWrapper configWrapper, HttpServletRequest request) { 83 int numOfQuestions = configWrapper.getQuestions().size(); 84 for (int k = 0; k < numOfQuestions; k++) { 85 String [] opts = request.getParameterValues("" + k); 86 if (opts == null) { 87 continue; 88 } 89 for (int h = 0; h < opts.length; h++) { 90 int cnt = -1; 91 try { 92 cnt = Integer.parseInt(opts[h]); 93 configWrapper.setSelected(k, cnt); 94 } catch(Exception e) { 95 Debug.logWarning(e.getMessage(), module); 96 } 97 } 98 } 99 } 100 } 101 102 | Popular Tags |