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.kernel.portlet;
016    
017    import com.liferay.portal.kernel.util.ParamUtil;
018    
019    import java.io.IOException;
020    
021    import javax.portlet.ActionRequest;
022    import javax.portlet.ActionResponse;
023    import javax.portlet.EventRequest;
024    import javax.portlet.EventResponse;
025    import javax.portlet.PortletException;
026    import javax.portlet.PortletRequest;
027    import javax.portlet.PortletResponse;
028    import javax.portlet.RenderRequest;
029    import javax.portlet.RenderResponse;
030    import javax.portlet.ResourceRequest;
031    import javax.portlet.ResourceResponse;
032    import javax.portlet.filter.FilterChain;
033    
034    /**
035     * @author Michael Young
036     */
037    public class PortletFilterUtil {
038    
039            public static void doFilter(
040                            PortletRequest portletRequest, PortletResponse portletResponse,
041                            String lifecycle, FilterChain filterChain)
042                    throws IOException, PortletException {
043    
044                    if (lifecycle.equals(PortletRequest.ACTION_PHASE)) {
045                            ActionRequest actionRequest = (ActionRequest)portletRequest;
046                            ActionResponse actionResponse = (ActionResponse)portletResponse;
047    
048                            filterChain.doFilter(actionRequest, actionResponse);
049    
050                            if (ParamUtil.getBoolean(actionRequest, "wsrp")) {
051                                    actionResponse.setRenderParameter("wsrp", "1");
052                            }
053                    }
054                    else if (lifecycle.equals(PortletRequest.EVENT_PHASE)) {
055                            EventRequest eventRequest = (EventRequest)portletRequest;
056                            EventResponse eventResponse = (EventResponse)portletResponse;
057    
058                            filterChain.doFilter(eventRequest, eventResponse);
059                    }
060                    else if (lifecycle.equals(PortletRequest.RENDER_PHASE)) {
061                            RenderRequest renderRequest = (RenderRequest)portletRequest;
062                            RenderResponse renderResponse = (RenderResponse)portletResponse;
063    
064                            filterChain.doFilter(renderRequest, renderResponse);
065                    }
066                    else if (lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {
067                            ResourceRequest resourceRequest = (ResourceRequest)portletRequest;
068                            ResourceResponse resourceResponse =
069                                    (ResourceResponse)portletResponse;
070    
071                            filterChain.doFilter(resourceRequest, resourceResponse);
072                    }
073            }
074    
075    }