Coverage report

  %line %branch
org.apache.jetspeed.resource.ResourceValveImpl
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.resource;
 18  
 
 19  
 import java.io.IOException;
 20  
 import java.util.HashMap;
 21  
 
 22  
 import javax.portlet.PortletException;
 23  
 import javax.servlet.http.HttpServletRequest;
 24  
 import javax.servlet.http.HttpServletResponse;
 25  
 
 26  
 import org.apache.commons.logging.Log;
 27  
 import org.apache.commons.logging.LogFactory;
 28  
 import org.apache.jetspeed.PortalReservedParameters;
 29  
 import org.apache.jetspeed.container.window.PortletWindowAccessor;
 30  
 import org.apache.jetspeed.om.common.portlet.MutablePortletEntity;
 31  
 import org.apache.jetspeed.om.page.ContentFragment;
 32  
 import org.apache.jetspeed.om.page.ContentFragmentImpl;
 33  
 import org.apache.jetspeed.om.page.Fragment;
 34  
 import org.apache.jetspeed.om.page.Page;
 35  
 import org.apache.jetspeed.pipeline.PipelineException;
 36  
 import org.apache.jetspeed.pipeline.valve.AbstractValve;
 37  
 import org.apache.jetspeed.pipeline.valve.ValveContext;
 38  
 import org.apache.jetspeed.request.RequestContext;
 39  
 import org.apache.pluto.PortletContainer;
 40  
 import org.apache.pluto.PortletContainerException;
 41  
 import org.apache.pluto.om.window.PortletWindow;
 42  
 
 43  
 /**
 44  
  * <p>
 45  
  * ResourceValveImpl
 46  
  * </p>
 47  
  * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
 48  
  * @version $Id: ResourceValveImpl.java 544024 2007-06-04 00:59:09Z ate $
 49  
  *
 50  
  */
 51  
 public class ResourceValveImpl extends AbstractValve
 52  
 {
 53  
 
 54  0
     private static final Log log = LogFactory.getLog(ResourceValveImpl.class);
 55  
     private PortletContainer container;
 56  
     private PortletWindowAccessor windowAccessor;
 57  
 
 58  
     public ResourceValveImpl(PortletContainer container, PortletWindowAccessor windowAccessor)
 59  0
     {
 60  0
         this.container = container;
 61  0
         this.windowAccessor = windowAccessor;
 62  0
     }
 63  
     
 64  
     /**
 65  
      * @see org.apache.jetspeed.pipeline.valve.Valve#invoke(org.apache.jetspeed.request.RequestContext, org.apache.jetspeed.pipeline.valve.ValveContext)
 66  
      */
 67  
     public void invoke(RequestContext request, ValveContext context) throws PipelineException
 68  
     {     
 69  0
         PortletWindow resourceWindow = request.getPortalURL().getNavigationalState().getPortletWindowOfResource();
 70  
         
 71  0
         if ( resourceWindow != null )
 72  
         {
 73  
             try
 74  
             {            
 75  0
                 Page page = request.getPage();
 76  0
                 Fragment fragment = page.getFragmentById(resourceWindow.getId().toString());
 77  
                 // If portlet entity is null, try to refresh the resourceWindow.
 78  
                 // Under some clustered environments, a cached portlet window could have null entity.
 79  0
                 if (null == resourceWindow.getPortletEntity())
 80  
                 {
 81  
                     try 
 82  
                     {
 83  0
                         ContentFragment contentFragment = new ContentFragmentImpl(fragment, class="keyword">new HashMap());
 84  0
                         resourceWindow = this.windowAccessor.getPortletWindow(contentFragment);
 85  
                     } 
 86  0
                     catch (Exception e)
 87  
                     {
 88  0
                         log.error("Failed to refresh resource window.", e);
 89  0
                     }
 90  
                 }
 91  0
                 ((MutablePortletEntity)resourceWindow.getPortletEntity()).setFragment(fragment);
 92  0
                 HttpServletResponse response = request.getResponse();
 93  0
                 HttpServletRequest requestForWindow = request.getRequestForWindow(resourceWindow);
 94  0
                 requestForWindow.setAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE, request);
 95  0
                 requestForWindow.setAttribute(PortalReservedParameters.PAGE_ATTRIBUTE, request.getPage());
 96  0
                 requestForWindow.setAttribute(PortalReservedParameters.FRAGMENT_ATTRIBUTE, fragment);
 97  0
                 request.setAttribute(PortalReservedParameters.REQUEST_CONTEXT_OBJECTS, request.getObjects());                        
 98  0
                 request.setAttribute(PortalReservedParameters.PATH_ATTRIBUTE, request.getAttribute(PortalReservedParameters.PATH_ATTRIBUTE));
 99  0
                 request.setAttribute(PortalReservedParameters.PORTLET_WINDOW_ATTRIBUTE, resourceWindow);
 100  0
                 BufferedHttpServletResponse bufferedResponse = new BufferedHttpServletResponse(response);
 101  0
                 container.renderPortlet(resourceWindow, requestForWindow, bufferedResponse);
 102  0
                 bufferedResponse.flush(response);
 103  
             }
 104  0
             catch (PortletContainerException e)
 105  
             {
 106  0
                 log.fatal("Unable to retrieve portlet container!", e);
 107  0
                 throw new PipelineException("Unable to retrieve portlet container!", e);
 108  
             }
 109  0
             catch (PortletException e)
 110  
             {
 111  0
                 log.warn("Unexpected PortletException", e);
 112  
 
 113  
             }
 114  0
             catch (IOException e)
 115  
             {
 116  0
                 log.error("Unexpected IOException", e);
 117  
             }
 118  0
             catch (IllegalStateException e)
 119  
             {
 120  0
                 log.error("Unexpected IllegalStateException.", e);
 121  
             }
 122  0
             catch (Exception t)
 123  
             {
 124  0
                 log.error("Unexpected Exception", t);
 125  0
             }
 126  
         }
 127  
         else
 128  
         {
 129  
             // Pass control to the next Valve in the Pipeline
 130  0
             context.invokeNext(request);
 131  
         }
 132  0
     }
 133  
 
 134  
     public String toString()
 135  
     {
 136  0
         return "ResourceValveImpl";
 137  
     }
 138  
 }

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