001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }