001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.apache.bridges.struts;
016    
017    import com.liferay.portal.kernel.servlet.ServletContextProvider;
018    import com.liferay.portal.kernel.util.JavaConstants;
019    import com.liferay.portal.util.PortalUtil;
020    import com.liferay.portlet.PortletContextImpl;
021    
022    import javax.portlet.GenericPortlet;
023    import javax.portlet.PortletContext;
024    import javax.portlet.PortletRequest;
025    import javax.portlet.PortletResponse;
026    
027    import javax.servlet.ServletContext;
028    import javax.servlet.http.HttpServletRequest;
029    import javax.servlet.http.HttpServletResponse;
030    
031    /**
032     * @author James Schopp
033     * @author Michael Young
034     * @author Deepak Gothe
035     */
036    public class LiferayServletContextProvider implements ServletContextProvider {
037    
038            public ServletContext getServletContext(GenericPortlet portlet) {
039                    PortletContext portletContext = portlet.getPortletContext();
040    
041                    ServletContext servletContext =
042                            (ServletContext)portletContext.getAttribute(
043                                    JavaConstants.JAVAX_PORTLET_SERVLET_CONTEXT);
044    
045                    if (servletContext == null) {
046                            PortletContextImpl portletContextImpl =
047                                    (PortletContextImpl)portlet.getPortletContext();
048    
049                            servletContext = portletContextImpl.getServletContext();
050                    }
051    
052                    return getServletContext(servletContext);
053            }
054    
055            public ServletContext getServletContext(ServletContext servletContext) {
056                    return new LiferayServletContext(servletContext);
057            }
058    
059            public HttpServletRequest getHttpServletRequest(
060                    GenericPortlet portlet, PortletRequest portletRequest) {
061    
062                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
063                            portletRequest);
064    
065                    return new LiferayStrutsRequestImpl(request);
066            }
067    
068            public HttpServletResponse getHttpServletResponse(
069                    GenericPortlet portlet, PortletResponse portletResponse) {
070    
071                    return PortalUtil.getHttpServletResponse(portletResponse);
072            }
073    
074    }