01: /*******************************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: *******************************************************************************/package org.ofbiz.webapp.website;
19:
20: import javax.servlet.ServletContext;
21: import javax.servlet.ServletRequest;
22:
23: import org.ofbiz.base.util.Debug;
24: import org.ofbiz.base.util.UtilMisc;
25: import org.ofbiz.entity.GenericDelegator;
26: import org.ofbiz.entity.GenericEntityException;
27: import org.ofbiz.entity.GenericValue;
28:
29: /**
30: * WebSiteWorker - Worker class for web site related functionality
31: */
32: public class WebSiteWorker {
33:
34: public static final String module = WebSiteWorker.class.getName();
35:
36: public static String getWebSiteId(ServletRequest request) {
37: ServletContext application = ((ServletContext) request
38: .getAttribute("servletContext"));
39:
40: if (application == null)
41: return null;
42: return application.getInitParameter("webSiteId");
43: }
44:
45: public static GenericValue getWebSite(ServletRequest request) {
46: String webSiteId = getWebSiteId(request);
47: if (webSiteId == null) {
48: return null;
49: }
50: GenericDelegator delegator = (GenericDelegator) request
51: .getAttribute("delegator");
52:
53: try {
54: return delegator.findByPrimaryKeyCache("WebSite", UtilMisc
55: .toMap("webSiteId", webSiteId));
56: } catch (GenericEntityException e) {
57: Debug.logError(e, "Error looking up website with id "
58: + webSiteId, module);
59: }
60: return null;
61: }
62: }
|