001    // Copyright 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry.portlet;
016    
017    import org.apache.tapestry.IRequestCycle;
018    import org.apache.tapestry.services.ResponseRenderer;
019    import org.apache.tapestry.services.ServiceConstants;
020    
021    import javax.portlet.ActionResponse;
022    import javax.portlet.PortletRequest;
023    
024    /**
025     * Sets render parameters on the current {@link javax.portlet.ActionResponse}
026     * that will invoke the {@link org.apache.tapestry.portlet.RenderService} to
027     * render the (currently) active page. This reflects the Portlet API's very
028     * clear division between processing an action and rendering a response; we need
029     * to record into the implicit render URL the render service and the name of the
030     * active page.
031     * 
032     * @author Howard M. Lewis Ship
033     * @since 4.0
034     */
035    public class PortletResponseRenderer implements ResponseRenderer
036    {
037        private PortletRequest _request;
038    
039        private ActionResponse _response;
040    
041        public void renderResponse(IRequestCycle cycle)
042        {
043            String pageName = cycle.getPage().getPageName();
044            
045            _response.setRenderParameter(ServiceConstants.SERVICE, PortletConstants.RENDER_SERVICE);
046            _response.setRenderParameter(ServiceConstants.PAGE, pageName);
047            _response.setRenderParameter(PortletConstants.PORTLET_MODE, _request.getPortletMode().toString());
048            _response.setRenderParameter(PortletConstants.WINDOW_STATE, _request.getWindowState().toString());
049        }
050    
051        public void setResponse(ActionResponse response)
052        {
053            _response = response;
054        }
055    
056        public void setRequest(PortletRequest request)
057        {
058            _request = request;
059        }
060    }