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

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