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
015package org.apache.tapestry.portlet;
016
017import javax.portlet.ActionResponse;
018import javax.portlet.PortletRequest;
019
020import org.apache.tapestry.IRequestCycle;
021import org.apache.tapestry.services.ResponseRenderer;
022import org.apache.tapestry.services.ServiceConstants;
023
024/**
025 * Sets render parameters on the current {@link javax.portlet.ActionResponse} that will invoke the
026 * {@link org.apache.tapestry.portlet.RenderService} to render the (currently) active page. This
027 * reflects the Portlet API's very clear division between processing an action and rendering a
028 * response; we need to record into the implicit render URL the render service and the name of the
029 * active page.
030 * 
031 * @author Howard M. Lewis Ship
032 * @since 4.0
033 */
034public class PortletResponseRenderer implements ResponseRenderer
035{
036    private PortletRequest _request;
037
038    private ActionResponse _response;
039
040    public void renderResponse(IRequestCycle cycle)
041    {
042        String pageName = cycle.getPage().getPageName();
043
044        _response.setRenderParameter(ServiceConstants.SERVICE, PortletConstants.RENDER_SERVICE);
045        _response.setRenderParameter(ServiceConstants.PAGE, pageName);
046        _response.setRenderParameter(PortletConstants.PORTLET_MODE, _request.getPortletMode()
047                .toString());
048        _response.setRenderParameter(PortletConstants.WINDOW_STATE, _request.getWindowState()
049                .toString());
050    }
051
052    public void setResponse(ActionResponse response)
053    {
054        _response = response;
055    }
056
057    public void setRequest(PortletRequest request)
058    {
059        _request = request;
060    }
061}