Coverage report

  %line %branch
org.apache.jetspeed.aggregator.impl.PortletRendererImpl
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.util.Collection;
 20  
 import java.util.HashMap;
 21  
 import java.util.Iterator;
 22  
 import java.util.Map;
 23  
 import java.util.List;
 24  
 
 25  
 import javax.servlet.http.HttpServletRequest;
 26  
 import javax.servlet.http.HttpServletResponse;
 27  
 
 28  
 import org.apache.commons.lang.StringEscapeUtils;
 29  
 import org.apache.commons.logging.Log;
 30  
 import org.apache.commons.logging.LogFactory;
 31  
 import org.apache.jetspeed.JetspeedActions;
 32  
 import org.apache.jetspeed.PortalReservedParameters;
 33  
 import org.apache.jetspeed.aggregator.ContentDispatcher;
 34  
 import org.apache.jetspeed.aggregator.ContentDispatcherCtrl;
 35  
 import org.apache.jetspeed.aggregator.FailedToRenderFragmentException;
 36  
 import org.apache.jetspeed.aggregator.PortletAccessDeniedException;
 37  
 import org.apache.jetspeed.aggregator.PortletContent;
 38  
 import org.apache.jetspeed.aggregator.PortletRenderer;
 39  
 import org.apache.jetspeed.aggregator.PortletTrackingManager;
 40  
 import org.apache.jetspeed.aggregator.RenderingJob;
 41  
 import org.apache.jetspeed.aggregator.UnknownPortletDefinitionException;
 42  
 import org.apache.jetspeed.aggregator.WorkerMonitor;
 43  
 import org.apache.jetspeed.cache.CacheElement;
 44  
 import org.apache.jetspeed.cache.ContentCacheKey;
 45  
 import org.apache.jetspeed.cache.JetspeedCache;
 46  
 import org.apache.jetspeed.components.portletentity.PortletEntityNotStoredException;
 47  
 import org.apache.jetspeed.container.window.FailedToRetrievePortletWindow;
 48  
 import org.apache.jetspeed.container.window.PortletWindowAccessor;
 49  
 import org.apache.jetspeed.om.common.LocalizedField;
 50  
 import org.apache.jetspeed.om.common.portlet.MutablePortletEntity;
 51  
 import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
 52  
 import org.apache.jetspeed.om.page.ContentFragment;
 53  
 import org.apache.jetspeed.om.window.impl.PortletWindowImpl;
 54  
 import org.apache.jetspeed.request.RequestContext;
 55  
 import org.apache.jetspeed.security.SecurityAccessController;
 56  
 import org.apache.jetspeed.services.title.DynamicTitleService;
 57  
 import org.apache.jetspeed.statistics.PortalStatistics;
 58  
 import org.apache.pluto.PortletContainer;
 59  
 import org.apache.pluto.om.entity.PortletEntity;
 60  
 import org.apache.pluto.om.window.PortletWindow;
 61  
 
 62  
 /**
 63  
  * <h4>PortletRendererService <br />
 64  
  * Jetspeed-2 Rendering service.</h4>
 65  
  * <p>
 66  
  * This service process all portlet rendering requests and interfaces with the
 67  
  * portlet container to generate the resulting markup
 68  
  * </p>
 69  
  * 
 70  
  * @author <a href="mailto:raphael@apache.org">Rapha�l Luta </a>
 71  
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
 72  
  * @author <a>Woonsan Ko</a>
 73  
  * @version $Id: PortletRendererImpl.java,v 1.30 2005/05/20 14:54:22 ate Exp $
 74  
  */
 75  
 public class PortletRendererImpl implements PortletRenderer
 76  
 {
 77  0
     protected final static Log log = LogFactory.getLog(PortletRendererImpl.class);
 78  
 
 79  
     protected WorkerMonitor workMonitor;
 80  
     protected PortletContainer container;
 81  
     protected PortletWindowAccessor windowAccessor;
 82  
     protected PortalStatistics statistics;
 83  
     protected DynamicTitleService addTitleService;
 84  
 
 85  
     protected PortletTrackingManager portletTracking;
 86  
     
 87  
     /**
 88  
      *  flag indicating whether to check jetspeed-portlet.xml security constraints 
 89  
      *  before rendering a portlet. If security check fails, do not display portlet content
 90  
      */
 91  
     protected boolean checkSecurityConstraints;   
 92  
     /**
 93  
      * For security constraint checks
 94  
      */
 95  
     protected SecurityAccessController accessController;
 96  
     
 97  
     /**
 98  
      * JSR 168 Portlet Content Cache
 99  
      */
 100  
     protected JetspeedCache portletContentCache;
 101  
     
 102  
     /**
 103  
      * OutOfService Cache
 104  
      */
 105  0
     protected boolean overrideTitles = false;
 106  
     public static final String OUT_OF_SERVICE_MESSAGE = "Portlet is not responding and has been taken out of service.";
 107  
     
 108  
     public PortletRendererImpl(PortletContainer container, 
 109  
                                PortletWindowAccessor windowAccessor,
 110  
                                WorkerMonitor workMonitor,
 111  
                                PortalStatistics statistics,
 112  
                                DynamicTitleService addTitleService,
 113  
                                PortletTrackingManager portletTracking,
 114  
                                boolean checkSecurityConstraints,
 115  
                                SecurityAccessController accessController,
 116  
                                JetspeedCache portletContentCache,
 117  
                                boolean overrideTitles)
 118  0
     {
 119  0
         this.container = container;
 120  0
         this.windowAccessor = windowAccessor;
 121  0
         this.workMonitor = workMonitor;
 122  0
         this.statistics = statistics;
 123  0
         this.addTitleService = addTitleService;
 124  0
         this.portletTracking = portletTracking;
 125  0
         this.checkSecurityConstraints = checkSecurityConstraints;
 126  0
         this.accessController = accessController;
 127  0
         this.portletContentCache = portletContentCache;
 128  0
         this.overrideTitles = overrideTitles;
 129  0
     }
 130  
 
 131  
     public PortletRendererImpl(PortletContainer container, 
 132  
             PortletWindowAccessor windowAccessor,
 133  
             WorkerMonitor workMonitor,
 134  
             PortalStatistics statistics,
 135  
             DynamicTitleService addTitleService,
 136  
             PortletTrackingManager portletTracking,
 137  
             boolean checkSecurityConstraints,
 138  
             SecurityAccessController accessController,
 139  
             JetspeedCache portletContentCache)
 140  
     {
 141  0
         this(container, windowAccessor, workMonitor, statistics, 
 142  
              addTitleService, portletTracking, checkSecurityConstraints,
 143  
              accessController, portletContentCache, false);
 144  0
     }
 145  
     
 146  
     public PortletRendererImpl(PortletContainer container, 
 147  
                                PortletWindowAccessor windowAccessor,
 148  
                                WorkerMonitor workMonitor,
 149  
                                PortalStatistics statistics,
 150  
                                DynamicTitleService addTitleService)
 151  
     {
 152  0
         this(container, windowAccessor, workMonitor, statistics, null, class="keyword">null, false, class="keyword">null, class="keyword">null, true);
 153  0
     }
 154  
 
 155  
     public PortletRendererImpl(PortletContainer container, 
 156  
                                PortletWindowAccessor windowAccessor,
 157  
                                WorkerMonitor workMonitor,
 158  
                                PortalStatistics statistics)
 159  
     {
 160  0
         this( container, windowAccessor, workMonitor, statistics, null );
 161  0
     }
 162  
     
 163  
     public PortletRendererImpl(PortletContainer container, 
 164  
                                PortletWindowAccessor windowAccessor,
 165  
                                WorkerMonitor workMonitor)
 166  
     {
 167  0
         this( container, windowAccessor, workMonitor, null );
 168  0
     }
 169  
     
 170  
     public void start()
 171  
     {
 172  
         // workMonitor.start();
 173  0
     }
 174  
 
 175  
     public void stop()
 176  
     {
 177  
         // this.monitor.shutdown ?
 178  0
     }
 179  
 
 180  
     /**
 181  
      * Render the specified Page fragment. Result is returned in the
 182  
      * PortletResponse.
 183  
      * 
 184  
      * @throws FailedToRenderFragmentException
 185  
      * @throws FailedToRetrievePortletWindow
 186  
      * @throws UnknownPortletDefinitionException
 187  
      */
 188  
     public void renderNow( ContentFragment fragment, RequestContext requestContext )
 189  
     {
 190  0
         HttpServletRequest servletRequest =null;
 191  0
         HttpServletResponse servletResponse = null;
 192  0
         ContentDispatcherCtrl dispatcher = null;    
 193  0
         boolean contentIsCached = false;
 194  
         try
 195  
         {
 196  0
             PortletWindow portletWindow = getPortletWindow(fragment);
 197  0
             PortletDefinitionComposite portletDefinition = 
 198  
                 (PortletDefinitionComposite) portletWindow.getPortletEntity().getPortletDefinition();           
 199  0
             if (checkSecurityConstraints && !checkSecurityConstraint(portletDefinition, fragment))
 200  
             {
 201  0
                 throw new PortletAccessDeniedException("Access Denied.");
 202  
             }
 203  0
             if (portletTracking.isOutOfService(portletWindow))
 204  
             {
 205  0
                 log.info("Taking portlet out of service: " + portletDefinition.getUniqueName() + " for window " + fragment.getId());
 206  0
                 fragment.overrideRenderedContent(OUT_OF_SERVICE_MESSAGE);
 207  0
                 return;
 208  
             }
 209  0
             long timeoutMetadata = this.getTimeoutOnJob(portletDefinition);
 210  0
             portletTracking.setExpiration(portletWindow, timeoutMetadata);            
 211  0
             int expirationCache = getExpirationCache(portletDefinition);
 212  0
             if (expirationCache != 0)
 213  
             {
 214  0
                 if (retrieveCachedContent(requestContext, fragment, portletWindow, expirationCache, portletDefinition))
 215  0
                     return;
 216  0
                 contentIsCached = true;
 217  
             }
 218  0
             if (dispatcher == null)
 219  
             {
 220  0
                 dispatcher = createDispatcher(requestContext, fragment, expirationCache);
 221  
             }
 222  0
             servletRequest = requestContext.getRequestForWindow(portletWindow);
 223  0
             servletResponse = dispatcher.getResponseForWindow(portletWindow, requestContext);
 224  0
             RenderingJob rJob = 
 225  
                 buildRenderingJob(portletWindow, fragment, servletRequest, servletResponse,
 226  
                                   requestContext, false, portletDefinition, dispatcher, null, 
 227  
                                   expirationCache, contentIsCached, timeoutMetadata);
 228  0
             rJob.execute();
 229  0
             addTitleToHeader( portletWindow, fragment, servletRequest, servletResponse, dispatcher, contentIsCached);
 230  
         }
 231  0
         catch (PortletAccessDeniedException e)
 232  
         {
 233  0
             fragment.overrideRenderedContent(e.getLocalizedMessage());                        
 234  
         }        
 235  0
         catch (Exception e)
 236  
         {
 237  0
             fragment.overrideRenderedContent(e.getLocalizedMessage());
 238  0
             log.error(e.toString(), e);
 239  0
         }
 240  0
     }
 241  
 
 242  
     /**
 243  
      * Render the specified Page fragment. Result is returned in the
 244  
      * PortletResponse.
 245  
      * 
 246  
      * @throws FailedToRenderFragmentException
 247  
      * @throws FailedToRetrievePortletWindow
 248  
      * @throws UnknownPortletDefinitionException
 249  
      * @throws PortletAccessDeniedException
 250  
      */
 251  
     public void renderNow( ContentFragment fragment, HttpServletRequest request, HttpServletResponse response )          
 252  
     {
 253  0
         RequestContext requestContext = (RequestContext) request
 254  
                 .getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
 255  0
         renderNow(fragment, requestContext);
 256  0
     }
 257  
     
 258  
     protected int getExpirationCache(PortletDefinitionComposite portletDefinition)
 259  
     {
 260  0
         if (portletDefinition == null)
 261  0
             return 0;
 262  0
         String expiration = portletDefinition.getExpirationCache();
 263  0
         if (expiration == null)
 264  0
             return 0;
 265  0
         return Integer.parseInt(expiration);
 266  
     }
 267  
     
 268  
     /**
 269  
      * Render the specified Page fragment. The method returns before rendering
 270  
      * is complete, rendered content can be accessed through the Content Dispatcher
 271  
      * 
 272  
      * @return the asynchronous portlet rendering job to synchronize
 273  
      */
 274  
     public RenderingJob render( ContentFragment fragment, RequestContext requestContext )
 275  
     {
 276  0
         RenderingJob job = null;
 277  
 
 278  
         try
 279  
         {
 280  0
             job = createRenderingJob(fragment, requestContext);
 281  
         }
 282  0
         catch (Exception e)
 283  
         {
 284  0
             log.error("render() failed: " + e.toString(), e);
 285  0
             fragment.overrideRenderedContent(e.getLocalizedMessage());            
 286  0
         }
 287  
 
 288  0
         if (job != null)
 289  
         {
 290  0
             processRenderingJob(job, true);
 291  
         }
 292  
 
 293  0
         return job;
 294  
     }       
 295  
     
 296  
     /** 
 297  
      * 
 298  
      * Create a rendering job for the specified Page fragment.
 299  
      * The method returns a rendering job which should be passed to 'processRenderingJob(RenderingJob job)' method.
 300  
      * @return portlet rendering job to pass to render(RenderingJob job) method
 301  
      * @throws FailedToRetrievePortletWindow
 302  
      * @throws UnknownPortletDefinitionException
 303  
      * @throws PortletAccessDeniedException
 304  
      */
 305  
     public RenderingJob createRenderingJob(ContentFragment fragment, RequestContext requestContext)
 306  
     {
 307  0
         RenderingJob job = null;
 308  0
         boolean contentIsCached = false;       
 309  
         try
 310  
         {
 311  0
             PortletWindow portletWindow = getPortletWindow(fragment);
 312  0
             PortletDefinitionComposite portletDefinition = 
 313  
                 (PortletDefinitionComposite) portletWindow.getPortletEntity().getPortletDefinition();     
 314  
 
 315  0
             long timeoutMetadata = this.getTimeoutOnJob(portletDefinition);
 316  0
             portletTracking.setExpiration(portletWindow, timeoutMetadata);            
 317  
             
 318  0
             if (checkSecurityConstraints && !checkSecurityConstraint(portletDefinition, fragment))
 319  
             {
 320  0
                 throw new PortletAccessDeniedException("Access Denied.");
 321  
             }
 322  0
             if (portletTracking.isOutOfService(portletWindow))
 323  
             {
 324  0
                 fragment.overrideRenderedContent(OUT_OF_SERVICE_MESSAGE);
 325  0
                 return null;
 326  
             }
 327  0
             int expirationCache = getExpirationCache(portletDefinition);
 328  0
             if (expirationCache != 0)
 329  
             {
 330  0
                 portletTracking.setExpiration(portletWindow, expirationCache);
 331  0
                 contentIsCached = retrieveCachedContent(requestContext, fragment, portletWindow, 
 332  
                                                         expirationCache, portletDefinition);
 333  0
                 if (contentIsCached)
 334  
                 {
 335  0
                     return null;
 336  
                 }
 337  
             }
 338  0
             job = buildRenderingJob( portletWindow, fragment, requestContext, true, 
 339  
                                      portletDefinition, null, contentIsCached, timeoutMetadata );
 340  
         }
 341  0
         catch (Exception e)
 342  
         {
 343  0
             throw new RuntimeException("Failed to create rendering job", e);
 344  0
         }
 345  
 
 346  0
         return job;
 347  
     }
 348  
            
 349  
     /** 
 350  
      * 
 351  
      * Render the specified rendering job.
 352  
      * The method returns before rendering is complete when the job is processed in parallel mode.
 353  
      * When it is not parallel mode, it returns after rendering is complete.
 354  
      * @throws FailedToRenderFragmentException
 355  
      */
 356  
     public void processRenderingJob(RenderingJob job)
 357  
     {
 358  0
         processRenderingJob(job, false);
 359  0
     }
 360  
 
 361  
     protected void processRenderingJob(RenderingJob job, boolean parallelOnly)
 362  
     {
 363  0
         ContentFragment fragment = null;
 364  
 
 365  
         try
 366  
         {
 367  0
             if (parallelOnly || job.getTimeout() > 0)
 368  
             {
 369  0
                 workMonitor.process(job);
 370  
             }
 371  
             else
 372  
             {
 373  0
                 job.execute();
 374  0
                 addTitleToHeader(job.getWindow(), job.getFragment(), 
 375  
                                  job.getRequest(), job.getResponse(), job.getDispatcher(), 
 376  
                                  job.isContentCached());                
 377  
             }
 378  
         }
 379  0
         catch (Exception e1)
 380  
         {
 381  0
             log.error("render() failed: " + e1.toString(), e1);
 382  0
             fragment.overrideRenderedContent(e1.getLocalizedMessage());            
 383  0
         }
 384  0
     }
 385  
     
 386  
     /**
 387  
      * Wait for all rendering jobs in the collection to finish successfully or otherwise. 
 388  
      * @param renderingJobs the Collection of rendering job objects to wait for.
 389  
      */
 390  
     public void waitForRenderingJobs(List renderingJobs)
 391  
     {
 392  0
         this.workMonitor.waitForRenderingJobs(renderingJobs);
 393  0
     }
 394  
 
 395  
     /**
 396  
      * Retrieve cached content, if content retrieved successfully return true, if no content found return false
 397  
      * @param requestContext
 398  
      * @param fragment
 399  
      * @param portletWindow
 400  
      * @return true when content found, otherwise false
 401  
      */
 402  
     protected boolean retrieveCachedContent(RequestContext requestContext, ContentFragment fragment, 
 403  
                                             PortletWindow portletWindow, int expiration, 
 404  
                                             PortletDefinitionComposite portletDefinition)
 405  
         throws Exception
 406  
     {
 407  0
         ContentCacheKey cacheKey = portletContentCache.createCacheKey(requestContext, fragment.getId());        
 408  0
         CacheElement cachedElement = portletContentCache.get(cacheKey);
 409  0
         if (cachedElement != null)
 410  
         {
 411  0
             PortletContent portletContent = (PortletContent)cachedElement.getContent();            
 412  0
             fragment.setPortletContent(portletContent);
 413  0
             ContentDispatcherCtrl dispatcher = new ContentDispatcherImpl(portletContent);
 414  0
             HttpServletRequest servletRequest = requestContext.getRequestForWindow(portletWindow);
 415  
 
 416  0
             this.addTitleService.setDynamicTitle(portletWindow, servletRequest, dispatcher.getPortletContent(fragment).getTitle());
 417  0
             return true;
 418  
         }        
 419  0
         return false;
 420  
     }
 421  
     
 422  
     public ContentDispatcherCtrl createDispatcher(RequestContext request, ContentFragment fragment, int expirationCache)
 423  
     {
 424  0
         ContentCacheKey cacheKey = portletContentCache.createCacheKey(request, fragment.getId());                
 425  0
         PortletContent content = new PortletContentImpl(this, cacheKey, expirationCache);
 426  0
         ContentDispatcherCtrl dispatcher = new ContentDispatcherImpl(content); 
 427  0
         return dispatcher;
 428  
     }
 429  
     
 430  
     /**
 431  
      * Retrieve the ContentDispatcher for the specified request
 432  
      */
 433  
     public ContentDispatcher getDispatcher( RequestContext request, boolean isParallel )
 434  
     {
 435  0
         return request.getContentDispatcher();
 436  
     }
 437  
 
 438  
 
 439  
     protected PortletWindow getPortletWindow( ContentFragment fragment ) throws FailedToRetrievePortletWindow, PortletEntityNotStoredException
 440  
     {
 441  
         // ObjectID oid = JetspeedObjectID.createFromString(fragment.getId());
 442  0
         PortletWindow portletWindow = windowAccessor.getPortletWindow(fragment);
 443  
 
 444  0
         if (portletWindow == null)
 445  
         {
 446  0
             throw new FailedToRetrievePortletWindow("Portlet Window creation failed for fragment: "
 447  
                                                     + fragment.getId() + ", " + fragment.getName());
 448  
         }
 449  
 
 450  0
         PortletEntity portletEntity = portletWindow.getPortletEntity();
 451  0
         ((MutablePortletEntity)portletEntity).setFragment(fragment);
 452  
         
 453  0
         ((PortletWindowImpl) portletWindow).setInstantlyRendered(fragment.isInstantlyRendered());
 454  
 
 455  0
         return portletWindow;
 456  
     }
 457  
     
 458  
     protected RenderingJob buildRenderingJob( PortletWindow portletWindow, ContentFragment fragment, 
 459  
                                               RequestContext requestContext, boolean isParallel,
 460  
                                               PortletDefinitionComposite portletDefinition, 
 461  
                                               PortletContent portletContent, boolean contentIsCached, long timeoutMetadata)
 462  
         throws PortletAccessDeniedException, FailedToRetrievePortletWindow, PortletEntityNotStoredException        
 463  
     {
 464  0
         int expirationCache = getExpirationCache(portletDefinition);
 465  0
         ContentDispatcherCtrl dispatcher = createDispatcher(requestContext, fragment, expirationCache);
 466  0
         HttpServletRequest request = requestContext.getRequestForWindow(portletWindow);
 467  0
         HttpServletResponse response = dispatcher.getResponseForWindow(portletWindow, requestContext);
 468  
 
 469  0
         return buildRenderingJob( portletWindow, fragment, request, response,
 470  
                                   requestContext, isParallel,
 471  
                                   portletDefinition, dispatcher,
 472  
                                   portletContent, expirationCache, contentIsCached, timeoutMetadata );        
 473  
     }
 474  
 
 475  
     protected RenderingJob buildRenderingJob( PortletWindow portletWindow, ContentFragment fragment, 
 476  
                                               HttpServletRequest request, HttpServletResponse response, 
 477  
                                               RequestContext requestContext, boolean isParallel,
 478  
                                               PortletDefinitionComposite portletDefinition, 
 479  
                                               ContentDispatcherCtrl dispatcher, 
 480  
                                               PortletContent portletContent, 
 481  
                                               int expirationCache, boolean contentIsCached, long timeoutMetadata)
 482  
              throws PortletAccessDeniedException, FailedToRetrievePortletWindow, PortletEntityNotStoredException
 483  
    {    
 484  0
         RenderingJob rJob = null;
 485  
                
 486  0
         request.setAttribute(PortalReservedParameters.PAGE_ATTRIBUTE, requestContext.getPage());
 487  0
         request.setAttribute(PortalReservedParameters.FRAGMENT_ATTRIBUTE, fragment);
 488  0
         request.setAttribute(PortalReservedParameters.CONTENT_DISPATCHER_ATTRIBUTE, dispatcher);
 489  0
         request.setAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE, requestContext);
 490  0
         request.setAttribute(PortalReservedParameters.REQUEST_CONTEXT_OBJECTS, requestContext.getObjects());                        
 491  0
         request.setAttribute(PortalReservedParameters.PATH_ATTRIBUTE, requestContext.getAttribute(PortalReservedParameters.PATH_ATTRIBUTE));
 492  0
         request.setAttribute(PortalReservedParameters.PORTLET_WINDOW_ATTRIBUTE, portletWindow);
 493  
         
 494  0
         if (portletContent == null)
 495  
         {
 496  0
             portletContent = dispatcher.getPortletContent(fragment);
 497  0
             fragment.setPortletContent(portletContent);
 498  
         }
 499  
         // In case of parallel mode, store attributes in a map to be refered by worker.
 500  0
         if (isParallel)
 501  
         {
 502  0
             Map workerAttrs = new HashMap();
 503  0
             workerAttrs.put(PortalReservedParameters.PAGE_ATTRIBUTE, requestContext.getPage());
 504  0
             workerAttrs.put(PortalReservedParameters.FRAGMENT_ATTRIBUTE, fragment);
 505  0
             workerAttrs.put(PortalReservedParameters.CONTENT_DISPATCHER_ATTRIBUTE, dispatcher);
 506  0
             workerAttrs.put(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE, requestContext);
 507  0
             workerAttrs.put(PortalReservedParameters.REQUEST_CONTEXT_OBJECTS, requestContext.getObjects());                                    
 508  0
             workerAttrs.put(PortalReservedParameters.PATH_ATTRIBUTE, requestContext.getAttribute(PortalReservedParameters.PATH_ATTRIBUTE));
 509  0
             workerAttrs.put(PortalReservedParameters.PORTLET_WINDOW_ATTRIBUTE, portletWindow);
 510  
 
 511  
             // the portlet invoker is not thread safe; it stores current portlet definition as a member variable.
 512  
             // so, store portlet definition as an attribute of worker
 513  0
             workerAttrs.put(PortalReservedParameters.PORTLET_DEFINITION_ATTRIBUTE, portletDefinition);
 514  
 
 515  0
             rJob = new RenderingJobImpl(container, this, portletDefinition, portletContent, fragment, dispatcher,
 516  
                                                     request, response, requestContext, portletWindow, 
 517  
                                                     statistics, expirationCache, contentIsCached, workerAttrs);
 518  
             
 519  0
         }
 520  
         else
 521  
         {
 522  0
             rJob = new RenderingJobImpl(container, this, portletDefinition, portletContent, fragment, dispatcher,
 523  
                                                          request, response, requestContext, portletWindow, 
 524  
                                                          statistics, expirationCache, contentIsCached );
 525  
             
 526  
         }
 527  
         
 528  0
         if (isParallel)
 529  
         {
 530  0
             setTimeoutOnJob(timeoutMetadata, rJob);
 531  
         }
 532  
         
 533  0
         return rJob;
 534  
     }
 535  
  
 536  
     protected long getTimeoutOnJob(PortletDefinitionComposite portletDefinition)
 537  
     {
 538  0
         long timeoutMetadata = 0;
 539  0
         Collection timeoutFields = null;
 540  
 
 541  0
         if (portletDefinition != null)
 542  
         {
 543  0
             timeoutFields = portletDefinition.getMetadata().getFields(PortalReservedParameters.PORTLET_EXTENDED_DESCRIPTOR_RENDER_TIMEOUT);
 544  
         }
 545  
 
 546  0
         if (timeoutFields != null) 
 547  
         {
 548  0
             Iterator it = timeoutFields.iterator();
 549  
 
 550  0
             if (it.hasNext()) 
 551  
             {
 552  0
                 LocalizedField timeoutField = (LocalizedField) timeoutFields.iterator().next();
 553  
 
 554  
                 try 
 555  
                 {
 556  0
                     timeoutMetadata = Long.parseLong(timeoutField.getValue());
 557  
                 }
 558  0
                 catch (NumberFormatException nfe) 
 559  
                 {
 560  0
                     log.warn("Invalid timeout metadata: " + nfe.getMessage());
 561  0
                 }
 562  
             }
 563  
         }       
 564  0
         return timeoutMetadata;
 565  
     }
 566  
     
 567  
     protected void setTimeoutOnJob(long timeoutMetadata, RenderingJob rJob)
 568  
     {
 569  
         
 570  0
         if (timeoutMetadata > 0) 
 571  
         {
 572  0
             rJob.setTimeout(timeoutMetadata);
 573  
         }
 574  0
         else if (this.portletTracking.getDefaultPortletTimeout() > 0) 
 575  
         {
 576  0
             rJob.setTimeout(this.portletTracking.getDefaultPortletTimeout());
 577  
         }        
 578  0
     }
 579  
     
 580  
     public void addTitleToHeader( PortletWindow portletWindow, ContentFragment fragment, 
 581  
                                   HttpServletRequest request, HttpServletResponse response, 
 582  
                                   ContentDispatcherCtrl dispatcher, boolean isCacheTitle )
 583  
     {
 584  0
         if (overrideTitles)
 585  
         {
 586  
             try
 587  
             {
 588  0
                 String title = fragment.getTitle();
 589  
 
 590  0
                 if ( title == null )
 591  
                 {
 592  0
                     title = addTitleService.getDynamicTitle( portletWindow, request );
 593  
                 }
 594  
 
 595  0
                 response.setHeader( "JS_PORTLET_TITLE", StringEscapeUtils.escapeHtml( title ) );
 596  0
                 dispatcher.getPortletContent(fragment).setTitle(title);          
 597  
             }
 598  0
             catch (Exception e)
 599  
             {
 600  0
                 log.error("Unable to reteive portlet title: " + e.getMessage(), e);
 601  0
             }
 602  
         }
 603  
         else
 604  
         {
 605  0
             String title = null;
 606  
 
 607  0
             if (isCacheTitle)
 608  
             {
 609  0
                 title = fragment.getTitle();
 610  
 
 611  0
                 if ( title == null )
 612  
                 {
 613  0
                     title = addTitleService.getDynamicTitle(portletWindow, request);
 614  
                 }
 615  
 
 616  0
                 dispatcher.getPortletContent(fragment).setTitle(title);
 617  
             }
 618  
 
 619  0
             if (title == null)
 620  
             {
 621  0
                 title = addTitleService.getDynamicTitle(portletWindow, request);
 622  0
                 dispatcher.getPortletContent(fragment).setTitle(title);                
 623  
             }
 624  
         }
 625  0
     }
 626  
     
 627  
     protected boolean checkSecurityConstraint(PortletDefinitionComposite portlet, ContentFragment fragment)
 628  
     {
 629  0
         if (fragment.getType().equals(ContentFragment.PORTLET))
 630  
         {
 631  0
             if (accessController != null)
 632  
             {
 633  0
                 return accessController.checkPortletAccess(portlet, JetspeedActions.MASK_VIEW);
 634  
             }
 635  
         }
 636  0
         return true;
 637  
     }
 638  
  
 639  
     protected void addToCache(PortletContent content)
 640  
     {
 641  0
         CacheElement cachedElement = portletContentCache.createElement(content.getCacheKey(), content);
 642  0
         if (content.getExpiration() == -1)
 643  
         {
 644  0
             cachedElement.setTimeToIdleSeconds(portletContentCache.getTimeToIdleSeconds());
 645  0
             cachedElement.setTimeToLiveSeconds(portletContentCache.getTimeToLiveSeconds());
 646  
         }
 647  
         else
 648  
         {       
 649  0
             cachedElement.setTimeToIdleSeconds(content.getExpiration());
 650  0
             cachedElement.setTimeToLiveSeconds(content.getExpiration());
 651  
         }
 652  0
         portletContentCache.put(cachedElement);        
 653  0
     }    
 654  
     
 655  
     public void notifyContentComplete(PortletContent content)
 656  
     {
 657  0
         if (content.getExpiration() != 0)
 658  0
             addToCache(content);
 659  0
     }
 660  
     
 661  
     public PortletTrackingManager getPortletTrackingManager()
 662  
     {
 663  0
         return this.portletTracking;
 664  
     }
 665  
 }

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