001    /**
002     * Copyright (c) 2000-2013 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.portlet.LiferayPortletContext;
018    import com.liferay.portal.kernel.servlet.ServletContextProvider;
019    import com.liferay.portal.kernel.util.JavaConstants;
020    import com.liferay.portal.util.PortalUtil;
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     * @author Raymond Augé
036     */
037    public class LiferayServletContextProvider implements ServletContextProvider {
038    
039            @Override
040            public HttpServletRequest getHttpServletRequest(
041                    GenericPortlet portlet, PortletRequest portletRequest) {
042    
043                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
044                            portletRequest);
045    
046                    return new LiferayStrutsRequestImpl(request);
047            }
048    
049            @Override
050            public HttpServletResponse getHttpServletResponse(
051                    GenericPortlet portlet, PortletResponse portletResponse) {
052    
053                    return PortalUtil.getHttpServletResponse(portletResponse);
054            }
055    
056            @Override
057            public ServletContext getServletContext(GenericPortlet portlet) {
058                    PortletContext portletContext = portlet.getPortletContext();
059    
060                    ServletContext servletContext =
061                            (ServletContext)portletContext.getAttribute(
062                                    JavaConstants.JAVAX_PORTLET_SERVLET_CONTEXT);
063    
064                    if (servletContext == null) {
065                            LiferayPortletContext liferayPortletContext =
066                                    (LiferayPortletContext)portlet.getPortletContext();
067    
068                            servletContext = liferayPortletContext.getServletContext();
069                    }
070    
071                    return getServletContext(servletContext);
072            }
073    
074            @Override
075            public ServletContext getServletContext(ServletContext servletContext) {
076                    return new LiferayServletContext(servletContext);
077            }
078    
079    }