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.portal.apache.bridges.struts;
16  
17  import com.liferay.portal.kernel.servlet.ServletContextProvider;
18  import com.liferay.portal.kernel.util.JavaConstants;
19  import com.liferay.portal.util.PortalUtil;
20  import com.liferay.portlet.PortletContextImpl;
21  
22  import javax.portlet.GenericPortlet;
23  import javax.portlet.PortletContext;
24  import javax.portlet.PortletRequest;
25  import javax.portlet.PortletResponse;
26  
27  import javax.servlet.ServletContext;
28  import javax.servlet.http.HttpServletRequest;
29  import javax.servlet.http.HttpServletResponse;
30  
31  /**
32   * <a href="LiferayServletContextProvider.java.html"><b><i>View Source</i></b>
33   * </a>
34   *
35   * @author James Schopp
36   * @author Michael Young
37   * @author Deepak Gothe
38   */
39  public class LiferayServletContextProvider implements ServletContextProvider {
40  
41      public ServletContext getServletContext(GenericPortlet portlet) {
42          PortletContext portletContext = portlet.getPortletContext();
43  
44          ServletContext servletContext =
45              (ServletContext)portletContext.getAttribute(
46                  JavaConstants.JAVAX_PORTLET_SERVLET_CONTEXT);
47  
48          if (servletContext == null) {
49              PortletContextImpl portletContextImpl =
50                  (PortletContextImpl)portlet.getPortletContext();
51  
52              servletContext = portletContextImpl.getServletContext();
53          }
54  
55          return getServletContext(servletContext);
56      }
57  
58      public ServletContext getServletContext(ServletContext servletContext) {
59          return new LiferayServletContext(servletContext);
60      }
61  
62      public HttpServletRequest getHttpServletRequest(
63          GenericPortlet portlet, PortletRequest portletRequest) {
64  
65          HttpServletRequest request = PortalUtil.getHttpServletRequest(
66              portletRequest);
67  
68          return new LiferayStrutsRequestImpl(request);
69      }
70  
71      public HttpServletResponse getHttpServletResponse(
72          GenericPortlet portlet, PortletResponse portletResponse) {
73  
74          return PortalUtil.getHttpServletResponse(portletResponse);
75      }
76  
77  }