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: 158   Methods: 6
NCLOC: 94   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
PortletRendererImpl.java 0% 65.8% 83.3% 65.2%
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    import java.io.PrintWriter;
 19    import java.util.ArrayList;
 20    import java.util.Date;
 21    import java.util.List;
 22   
 23    import org.apache.hivemind.ApplicationRuntimeException;
 24    import org.apache.tapestry.IMarkupWriter;
 25    import org.apache.tapestry.IPage;
 26    import org.apache.tapestry.IRequestCycle;
 27    import org.apache.tapestry.PageRedirectException;
 28    import org.apache.tapestry.Tapestry;
 29    import org.apache.tapestry.TapestryUtils;
 30    import org.apache.tapestry.asset.AssetFactory;
 31    import org.apache.tapestry.engine.EngineMessages;
 32    import org.apache.tapestry.markup.MarkupWriterSource;
 33    import org.apache.tapestry.util.ContentType;
 34    import org.apache.tapestry.util.PageRenderSupportImpl;
 35    import org.apache.tapestry.web.WebResponse;
 36   
 37    /**
 38    * The guts of rendering a page as a portlet response; used by
 39    * {@link org.apache.tapestry.portlet.RenderService} and
 40    * {@link org.apache.tapestry.portlet.PortletHomeService}.
 41    *
 42    * @author Howard M. Lewis Ship
 43    * @since 4.0
 44    */
 45    public class PortletRendererImpl implements PortletRenderer
 46    {
 47    private WebResponse _response;
 48   
 49    private MarkupWriterSource _markupWriterSource;
 50   
 51    private AssetFactory _assetFactory;
 52   
 53    private String _applicationId;
 54   
 55  1 public void renderPage(IRequestCycle cycle, String pageName) throws IOException
 56    {
 57  1 try {
 58  1 cycle.activate(pageName);
 59   
 60  1 IPage page = cycle.getPage();
 61   
 62  1 ContentType contentType = page.getResponseContentType();
 63   
 64  1 PrintWriter printWriter = _response.getPrintWriter(contentType);
 65   
 66  1 IMarkupWriter writer = _markupWriterSource.newMarkupWriter(printWriter, contentType);
 67   
 68  1 String namespace = _response.getNamespace();
 69   
 70  1 PageRenderSupportImpl support = new PageRenderSupportImpl(_assetFactory, namespace, null);
 71   
 72  1 TapestryUtils.storePageRenderSupport(cycle, support);
 73   
 74  1 IMarkupWriter nested = writer.getNestedWriter();
 75   
 76  1 cycle.renderPage(nested);
 77   
 78  1 String id = "Tapestry Portlet " + _applicationId + " " + namespace;
 79   
 80  1 writer.comment("BEGIN " + id);
 81  1 writer.comment("Page: " + page.getPageName());
 82  1 writer.comment("Generated: " + new Date());
 83  1 writer.comment("Framework version: " + Tapestry.VERSION);
 84   
 85  1 support.writeBodyScript(writer, cycle);
 86   
 87  1 nested.close();
 88   
 89  1 support.writeInitializationScript(writer);
 90   
 91  1 writer.comment("END " + id);
 92   
 93  1 writer.close();
 94   
 95    // TODO: Trap errors and do some error reporting here?
 96    }
 97    catch (PageRedirectException e) {
 98  0 handlePageRedirectException(cycle, e);
 99    }
 100    }
 101   
 102  0 protected void handlePageRedirectException(IRequestCycle cycle, PageRedirectException exception)
 103    throws IOException
 104    {
 105  0 List pageNames = new ArrayList();
 106   
 107  0 String pageName = exception.getTargetPageName();
 108   
 109  0 while (true)
 110    {
 111  0 if (pageNames.contains(pageName))
 112    {
 113  0 pageNames.add(pageName);
 114   
 115  0 throw new ApplicationRuntimeException(EngineMessages.validateCycle(pageNames));
 116    }
 117   
 118    // Record that this page has been a target.
 119   
 120  0 pageNames.add(pageName);
 121   
 122  0 try
 123    {
 124    // Attempt to activate the new page.
 125   
 126  0 cycle.activate(pageName);
 127   
 128  0 break;
 129    }
 130    catch (PageRedirectException secondRedirectException)
 131    {
 132  0 pageName = secondRedirectException.getTargetPageName();
 133    }
 134    }
 135   
 136  0 renderPage(cycle, pageName);
 137    }
 138   
 139  1 public void setMarkupWriterSource(MarkupWriterSource markupWriterSource)
 140    {
 141  1 _markupWriterSource = markupWriterSource;
 142    }
 143   
 144  1 public void setResponse(WebResponse response)
 145    {
 146  1 _response = response;
 147    }
 148   
 149  1 public void setAssetFactory(AssetFactory assetFactory)
 150    {
 151  1 _assetFactory = assetFactory;
 152    }
 153   
 154  1 public void setApplicationId(String applicationId)
 155    {
 156  1 _applicationId = applicationId;
 157    }
 158    }