|
Author: jleroux
Date: Thu May 27 10:23:30 2010 New Revision: 948761 URL: http://svn.apache.org/viewvc?rev=948761&view=rev Log: A patch from Sascha Rodekamp "Identifying the website id" (https://issues.apache.org/jira/browse/OFBIZ-3784) - OFBIZ-3784 Sascha : here is a little patch to improve the identification of the websites. The original method seems a little bit bare. Jacques: I can't see any problems with this improvement, though I did not test all cases Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/website/WebSiteWorker.java Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/website/WebSiteWorker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/website/WebSiteWorker.java?rev=948761&r1=948760&r2=948761&view=diff ============================================================================== --- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/website/WebSiteWorker.java (original) +++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/website/WebSiteWorker.java Thu May 27 10:23:30 2010 @@ -18,11 +18,17 @@ *******************************************************************************/ package org.ofbiz.webapp.website; +import java.util.Map; + import javax.servlet.ServletContext; import javax.servlet.ServletRequest; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilHttp; import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; @@ -35,10 +41,29 @@ public class WebSiteWorker { public static final String module = WebSiteWorker.class.getName(); public static String getWebSiteId(ServletRequest request) { - ServletContext application = ((ServletContext) request.getAttribute("servletContext")); + HttpSession session = ((HttpServletRequest) request).getSession(); + Map<String, Object> requestParameters = UtilHttp.getParameterMap((HttpServletRequest) request); + String webSiteId = null; + boolean fromSession = false; + + // first see if a new webSiteId was specified as a parameter + webSiteId = (String) requestParameters.get("webSiteId"); + // if no parameter, try from session + if (UtilValidate.isEmpty(webSiteId)) { + webSiteId = (String) session.getAttribute("webSiteId"); + if (webSiteId != null) fromSession = true; + } + // get it from the servlet context + if (UtilValidate.isEmpty(webSiteId)) { + ServletContext application = ((ServletContext) request.getAttribute("servletContext")); + if (application != null) webSiteId = application.getInitParameter("webSiteId"); + } + + if (UtilValidate.isNotEmpty(webSiteId) && !fromSession) { + session.setAttribute("webSiteId", webSiteId); + } - if (application == null) return null; - return application.getInitParameter("webSiteId"); + return webSiteId; } public static GenericValue getWebSite(ServletRequest request) { |
| Free forum by Nabble | Edit this page |
