Coverage report

  %line %branch
org.apache.jetspeed.aggregator.impl.PageAggregatorImpl
0% 
0% 

 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  * 
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.jetspeed.aggregator.impl;
 18  
 
 19  
 import java.io.IOException;
 20  
 import java.util.Iterator;
 21  
 
 22  
 import org.apache.commons.logging.Log;
 23  
 import org.apache.commons.logging.LogFactory;
 24  
 import org.apache.jetspeed.PortalReservedParameters;
 25  
 import org.apache.jetspeed.aggregator.FailedToRenderFragmentException;
 26  
 import org.apache.jetspeed.aggregator.PageAggregator;
 27  
 import org.apache.jetspeed.aggregator.PortletRenderer;
 28  
 import org.apache.jetspeed.container.state.NavigationalState;
 29  
 import org.apache.jetspeed.exception.JetspeedException;
 30  
 import org.apache.jetspeed.om.page.ContentFragment;
 31  
 import org.apache.jetspeed.om.page.ContentPage;
 32  
 import org.apache.jetspeed.request.RequestContext;
 33  
 import org.apache.pluto.om.window.PortletWindow;
 34  
 
 35  
 /**
 36  
  * ContentPageAggregator builds the content required to render a page of portlets.
 37  
  * 
 38  
  * @author <a href="mailto:raphael@apache.org">Rapha�l Luta </a>
 39  
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
 40  
  * @version $Id: PageAggregatorImpl.java 516448 2007-03-09 16:25:47Z ate $
 41  
  */
 42  
 public class PageAggregatorImpl implements PageAggregator
 43  
 {
 44  0
     private final static Log log = LogFactory.getLog(PageAggregatorImpl.class);
 45  
     private PortletRenderer renderer;
 46  
 
 47  
     public PageAggregatorImpl( PortletRenderer renderer)
 48  0
     {
 49  0
         this.renderer = renderer;
 50  0
     }
 51  
 
 52  
     /**
 53  
      * Builds the portlet set defined in the context into a portlet tree.
 54  
      * 
 55  
      * @return Unique Portlet Entity ID
 56  
      */
 57  
     public void build( RequestContext context ) throws JetspeedException, IOException
 58  
     {
 59  0
         ContentPage page = context.getPage();
 60  0
         if (null == page)
 61  
         {
 62  0
             throw new JetspeedException("Failed to find PSML Pin ContentPageAggregator.build");
 63  
         }
 64  0
         ContentFragment root = page.getRootContentFragment();
 65  0
         if (root == null)
 66  
         {
 67  0
             throw new JetspeedException("No root ContentFragment found in ContentPage");
 68  
         }
 69  
         // handle maximized state
 70  0
         NavigationalState nav = context.getPortalURL().getNavigationalState();
 71  0
         PortletWindow window = nav.getMaximizedWindow();
 72  0
         if (null != window)
 73  
         {
 74  0
             renderMaximizedWindow(context, page, root, window);
 75  
         }
 76  
         else
 77  
         {
 78  0
             aggregateAndRender(root, context, page);
 79  
         }        
 80  0
         context.getResponse().getWriter().write(root.getRenderedContent());
 81  0
         if (null != window)
 82  
         {
 83  0
             context.getRequest().removeAttribute(PortalReservedParameters.MAXIMIZED_FRAGMENT_ATTRIBUTE);
 84  0
             context.getRequest().removeAttribute(PortalReservedParameters.MAXIMIZED_LAYOUT_ATTRIBUTE);
 85  
         }
 86  0
     }
 87  
 
 88  
     /**
 89  
      * <p>
 90  
      * renderMaximizedWindow
 91  
      * </p>
 92  
      * 
 93  
      * @param context
 94  
      * @param page
 95  
      * @param layoutContentFragment
 96  
      * @param defaultPortletDecorator
 97  
      * @param dispatcher
 98  
      * @param window
 99  
      * @throws FailedToRenderContentFragmentException
 100  
      */
 101  
     protected void renderMaximizedWindow( RequestContext context, ContentPage page, ContentFragment layoutContentFragment,
 102  
             PortletWindow window ) throws FailedToRenderFragmentException
 103  
     {
 104  0
         ContentFragment maxedContentFragment = page.getContentFragmentById(window.getId().toString());
 105  0
         if (maxedContentFragment != null)
 106  
         {
 107  0
             context.getRequest().setAttribute(PortalReservedParameters.MAXIMIZED_FRAGMENT_ATTRIBUTE, maxedContentFragment);
 108  0
             context.getRequest().setAttribute(PortalReservedParameters.FRAGMENT_ATTRIBUTE, maxedContentFragment);
 109  0
             context.getRequest().setAttribute(PortalReservedParameters.MAXIMIZED_LAYOUT_ATTRIBUTE, page.getRootContentFragment());
 110  
 
 111  
             try
 112  
             {
 113  0
                 renderer.renderNow(maxedContentFragment, context);
 114  0
                 renderer.renderNow(layoutContentFragment, context);              
 115  
                 
 116  
             }
 117  0
             catch (Exception e)
 118  
             {
 119  0
                 log.error(e.getMessage(), e);
 120  0
                 maxedContentFragment.overrideRenderedContent("Sorry, but we were unable access the requested portlet.  Send the following message to your portal admin:  "+  e.getMessage());
 121  0
             }
 122  
         }
 123  
         else
 124  
         {
 125  0
             String message = "Maximized fragment not found."; 
 126  0
             log.error(message);
 127  0
             if (maxedContentFragment != null)
 128  0
                 maxedContentFragment.overrideRenderedContent("Sorry, but we were unable access the requested portlet.  Send the following message to your portal admin:  "+  message);            
 129  
         }
 130  0
     }
 131  
 
 132  
     protected void aggregateAndRender( ContentFragment f, RequestContext context, ContentPage page )
 133  
             throws FailedToRenderFragmentException
 134  
     {
 135  0
         if (f.getContentFragments() != null && f.getContentFragments().size() > 0)
 136  
         {
 137  0
             Iterator children = f.getContentFragments().iterator();
 138  0
             while (children.hasNext())
 139  
             {
 140  0
                 ContentFragment child = (ContentFragment) children.next();
 141  0
                 if (!"hidden".equals(f.getState()))
 142  
                 {
 143  0
                     aggregateAndRender(child, context, page);
 144  
                 }
 145  0
             }
 146  
         }
 147  0
         renderer.renderNow(f, context);
 148  0
     }
 149  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.