1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.util.bridges.struts;
16  
17  import com.liferay.portal.kernel.servlet.ServletContextProvider;
18  
19  import javax.portlet.GenericPortlet;
20  import javax.portlet.PortletContext;
21  import javax.portlet.PortletRequest;
22  import javax.portlet.PortletResponse;
23  
24  import javax.servlet.ServletContext;
25  import javax.servlet.http.HttpServletRequest;
26  import javax.servlet.http.HttpServletResponse;
27  
28  /**
29   * <a href="LiferayServletContextProviderWrapper.java.html"><b><i>View Source
30   * </i></b></a>
31   *
32   * @author Michael Young
33   */
34  public class LiferayServletContextProviderWrapper
35      implements org.apache.portals.bridges.common.ServletContextProvider {
36  
37      public ServletContext getServletContext(GenericPortlet portlet) {
38          ServletContextProvider provider = _getProvider(portlet);
39  
40          return provider.getServletContext(portlet);
41      }
42  
43      public HttpServletRequest getHttpServletRequest(
44          GenericPortlet portlet, PortletRequest portletRequest) {
45  
46          ServletContextProvider provider = _getProvider(portlet);
47  
48          return provider.getHttpServletRequest(portlet, portletRequest);
49      }
50  
51      public HttpServletResponse getHttpServletResponse(
52          GenericPortlet portlet, PortletResponse portletResponse) {
53  
54          ServletContextProvider provider = _getProvider(portlet);
55  
56          return provider.getHttpServletResponse(portlet, portletResponse);
57      }
58  
59      private ServletContextProvider _getProvider(GenericPortlet portlet) {
60          PortletContext portletContext = portlet.getPortletContext();
61  
62          if (_provider == null) {
63              _provider = (ServletContextProvider)portletContext.getAttribute(
64                  ServletContextProvider.STRUTS_BRIDGES_CONTEXT_PROVIDER);
65          }
66  
67          return _provider;
68      }
69  
70      private ServletContextProvider _provider;
71  
72  }