001    /**
002     * Copyright (c) 2000-2010 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.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    }