Clover coverage report - Code Coverage for tapestry-portlet release 4.0.2
Coverage timestamp: Thu Apr 13 2006 10:54:39 EDT
file stats: LOC: 108   Methods: 8
NCLOC: 50   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
RenderService.java 100% 92.3% 87.5% 91.3%
coverage coverage
 1    // Copyright 2005 The Apache Software Foundation
 2    //
 3    // Licensed under the Apache License, Version 2.0 (the "License");
 4    // you may not use this file except in compliance with the License.
 5    // You may obtain a copy of the License at
 6    //
 7    // http://www.apache.org/licenses/LICENSE-2.0
 8    //
 9    // Unless required by applicable law or agreed to in writing, software
 10    // distributed under the License is distributed on an "AS IS" BASIS,
 11    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12    // See the License for the specific language governing permissions and
 13    // limitations under the License.
 14   
 15    package org.apache.tapestry.portlet;
 16   
 17    import java.io.IOException;
 18   
 19    import javax.portlet.PortletRequest;
 20   
 21    import org.apache.tapestry.IRequestCycle;
 22    import org.apache.tapestry.engine.IEngineService;
 23    import org.apache.tapestry.engine.ILink;
 24    import org.apache.tapestry.services.ServiceConstants;
 25   
 26    /**
 27    * Responsible for rendering out a page; a Portlet render URL is built during action processing that
 28    * stores the active page; this is the page that will be rendered. The render service is (typically)
 29    * the only service that operates during a portlet RenderRequest. All other services will be an
 30    * ActionRequest that (via {@link org.apache.tapestry.portlet.PortletResponseRenderer}, writes
 31    * query parameters to activate this service during the render request.
 32    * <p>
 33    * Problematic is is anything related to the portlet mode or window state. As per the Portlet spec,
 34    * when the user clicks the "help" or "edit" buttons (or the minimize, maximize, etc.), this causes
 35    * a new RenderRequest, but explicitly keeps the render parameters set by the most recent
 36    * ActionRequest. But what Tapestry needs is to detect that the mode or state has changed and select
 37    * a different page to render the response. So we store the mode and state in effect when the
 38    * ActionRequest executed as two more query parameters, and detect changes to mode and state that
 39    * way. If there is a change, then we ignore the page query parameter and use the
 40    * {@link PortletPageResolver} to figure out the correct page to display instead.
 41    *
 42    * @author Howard M. Lewis Ship
 43    * @since 4.0
 44    * @see org.apache.tapestry.services.impl.ResponseRendererImpl
 45    */
 46    public class RenderService implements IEngineService
 47    {
 48    private PortletRequest _request;
 49   
 50    private PortletRenderer _portletRenderer;
 51   
 52    private PortletPageResolver _pageResolver;
 53   
 54  1 public ILink getLink(boolean post, Object parameter)
 55    {
 56  1 throw new UnsupportedOperationException(PortletMessages.unsupportedMethod("getLink"));
 57    }
 58   
 59  3 public void service(IRequestCycle cycle) throws IOException
 60    {
 61  3 String pageName = getPageNameToRender(cycle);
 62   
 63  3 _portletRenderer.renderPage(cycle, pageName);
 64    }
 65   
 66  3 private String getPageNameToRender(IRequestCycle cycle)
 67    {
 68  3 if (isStateChange(cycle))
 69  2 return _pageResolver.getPageNameForRequest(cycle);
 70   
 71  1 return cycle.getParameter(ServiceConstants.PAGE);
 72    }
 73   
 74    /**
 75    * Returns true if the portlet mode or the window state has changed since. The values stored
 76    * previously (during an action request) are compared to the current values.
 77    */
 78   
 79  3 boolean isStateChange(IRequestCycle cycle)
 80    {
 81  3 String expectedPortletMode = cycle.getParameter(PortletConstants.PORTLET_MODE);
 82  3 String expectedWindowState = cycle.getParameter(PortletConstants.WINDOW_STATE);
 83   
 84  3 return !(_request.getPortletMode().toString().equals(expectedPortletMode) && _request
 85    .getWindowState().toString().equals(expectedWindowState));
 86   
 87    }
 88   
 89  0 public String getName()
 90    {
 91  0 return PortletConstants.RENDER_SERVICE;
 92    }
 93   
 94  3 public void setPortletRenderer(PortletRenderer portletRenderer)
 95    {
 96  3 _portletRenderer = portletRenderer;
 97    }
 98   
 99  3 public void setRequest(PortletRequest request)
 100    {
 101  3 _request = request;
 102    }
 103   
 104  2 public void setPageResolver(PortletPageResolver pageResolver)
 105    {
 106  2 _pageResolver = pageResolver;
 107    }
 108    }