1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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  }