1 24 package org.ofbiz.webapp.website; 25 26 import javax.servlet.ServletContext ; 27 import javax.servlet.ServletRequest ; 28 29 import org.ofbiz.base.util.Debug; 30 import org.ofbiz.base.util.UtilMisc; 31 import org.ofbiz.entity.GenericDelegator; 32 import org.ofbiz.entity.GenericEntityException; 33 import org.ofbiz.entity.GenericValue; 34 35 43 public class WebSiteWorker { 44 45 public static final String module = WebSiteWorker.class.getName(); 46 47 public static String getWebSiteId(ServletRequest request) { 48 ServletContext application = ((ServletContext ) request.getAttribute("servletContext")); 49 50 if (application == null) return null; 51 return application.getInitParameter("webSiteId"); 52 } 53 54 public static GenericValue getWebSite(ServletRequest request) { 55 String webSiteId = getWebSiteId(request); 56 if (webSiteId == null) { 57 return null; 58 } 59 GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); 60 61 try { 62 return delegator.findByPrimaryKeyCache("WebSite", UtilMisc.toMap("webSiteId", webSiteId)); 63 } catch (GenericEntityException e) { 64 Debug.logError(e, "Error looking up website with id " + webSiteId, module); 65 } 66 return null; 67 } 68 } 69 | Popular Tags |