01: /*
02: * $Id: WebSiteWorker.java,v 1.3 2003/12/14 10:14:19 jonesde Exp $
03: *
04: * Copyright (c) 2001-2003 The Open For Business Project - www.ofbiz.org
05: *
06: * Permission is hereby granted, free of charge, to any person obtaining a
07: * copy of this software and associated documentation files (the "Software"),
08: * to deal in the Software without restriction, including without limitation
09: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10: * and/or sell copies of the Software, and to permit persons to whom the
11: * Software is furnished to do so, subject to the following conditions:
12: *
13: * The above copyright notice and this permission notice shall be included
14: * in all copies or substantial portions of the Software.
15: *
16: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23: */
24: package org.ofbiz.content.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: /**
36: * WebSiteWorker - Worker class for web site related functionality
37: *
38: * @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
39: * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
40: * @version $Revision: 1.3 $
41: * @since 2.0
42: */
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
49: .getAttribute("servletContext"));
50:
51: if (application == null)
52: return null;
53: return application.getInitParameter("webSiteId");
54: }
55:
56: public static GenericValue getWebSite(ServletRequest request) {
57: String webSiteId = getWebSiteId(request);
58: if (webSiteId == null) {
59: return null;
60: }
61: GenericDelegator delegator = (GenericDelegator) request
62: .getAttribute("delegator");
63:
64: try {
65: return delegator.findByPrimaryKeyCache("WebSite", UtilMisc
66: .toMap("webSiteId", webSiteId));
67: } catch (GenericEntityException e) {
68: Debug.logError(e, "Error looking up website with id "
69: + webSiteId, module);
70: }
71: return null;
72: }
73: }
|