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.util.bridges.struts;
016    
017    import com.liferay.portal.kernel.servlet.ServletContextProvider;
018    
019    import javax.portlet.GenericPortlet;
020    import javax.portlet.PortletContext;
021    import javax.portlet.PortletRequest;
022    import javax.portlet.PortletResponse;
023    
024    import javax.servlet.ServletContext;
025    import javax.servlet.http.HttpServletRequest;
026    import javax.servlet.http.HttpServletResponse;
027    
028    /**
029     * @author Michael Young
030     */
031    public class LiferayServletContextProviderWrapper
032            implements org.apache.portals.bridges.common.ServletContextProvider {
033    
034            public ServletContext getServletContext(GenericPortlet portlet) {
035                    ServletContextProvider provider = _getProvider(portlet);
036    
037                    return provider.getServletContext(portlet);
038            }
039    
040            public HttpServletRequest getHttpServletRequest(
041                    GenericPortlet portlet, PortletRequest portletRequest) {
042    
043                    ServletContextProvider provider = _getProvider(portlet);
044    
045                    return provider.getHttpServletRequest(portlet, portletRequest);
046            }
047    
048            public HttpServletResponse getHttpServletResponse(
049                    GenericPortlet portlet, PortletResponse portletResponse) {
050    
051                    ServletContextProvider provider = _getProvider(portlet);
052    
053                    return provider.getHttpServletResponse(portlet, portletResponse);
054            }
055    
056            private ServletContextProvider _getProvider(GenericPortlet portlet) {
057                    PortletContext portletContext = portlet.getPortletContext();
058    
059                    if (_provider == null) {
060                            _provider = (ServletContextProvider)portletContext.getAttribute(
061                                    ServletContextProvider.STRUTS_BRIDGES_CONTEXT_PROVIDER);
062                    }
063    
064                    return _provider;
065            }
066    
067            private ServletContextProvider _provider;
068    
069    }