Coverage Report - org.apache.myfaces.portlet.PortletViewHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
PortletViewHandler
0%
0/32
0%
0/12
0
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package org.apache.myfaces.portlet;
 20  
 
 21  
 import java.io.IOException;
 22  
 
 23  
 import javax.faces.FacesException;
 24  
 import javax.faces.application.Application;
 25  
 import javax.faces.application.ViewHandler;
 26  
 import javax.faces.application.ViewHandlerWrapper;
 27  
 import javax.faces.component.UIViewRoot;
 28  
 import javax.faces.context.FacesContext;
 29  
 import javax.portlet.PortletRequest;
 30  
 import javax.portlet.PortletURL;
 31  
 import javax.portlet.RenderResponse;
 32  
 
 33  
 import org.apache.commons.logging.Log;
 34  
 import org.apache.commons.logging.LogFactory;
 35  
 
 36  
 /**
 37  
  * TODO: test this portlet view handler in portlet environment
 38  
  * 
 39  
  * @author Mathias Broekelmann (latest modification by $Author: mbr $)
 40  
  * @version $Revision: 517404 $ $Date: 2007-03-12 16:17:24 -0500 (Mon, 12 Mar 2007) $
 41  
  */
 42  
 public class PortletViewHandler extends ViewHandlerWrapper
 43  
 {
 44  
     private final ViewHandler _viewHandler;
 45  
 
 46  0
     private static final Log log = LogFactory.getLog(PortletViewHandler.class);
 47  
 
 48  
     public PortletViewHandler(ViewHandler viewHandler)
 49  0
     {
 50  0
         _viewHandler = viewHandler;
 51  0
     }
 52  
 
 53  
     @Override
 54  
     protected ViewHandler getWrapped()
 55  
     {
 56  0
         return _viewHandler;
 57  
     }
 58  
 
 59  
     @Override
 60  
     public UIViewRoot restoreView(FacesContext context, String viewId)
 61  
     {
 62  0
         if (PortletUtil.isPortletRequest(context))
 63  
         {
 64  0
             PortletRequest request = (PortletRequest) context.getExternalContext().getRequest();
 65  0
             String portletViewId = request.getParameter(MyFacesGenericPortlet.VIEW_ID);
 66  0
             Application application = context.getApplication();
 67  0
             ViewHandler applicationViewHandler = application.getViewHandler();
 68  0
             String renderKitId = applicationViewHandler.calculateRenderKitId(context);
 69  0
             UIViewRoot viewRoot = application.getStateManager().restoreView(context, portletViewId, renderKitId);
 70  0
             return viewRoot;
 71  
         }
 72  0
         return super.restoreView(context, viewId);
 73  
     }
 74  
 
 75  
     @Override
 76  
     public UIViewRoot createView(FacesContext context, String viewId)
 77  
     {
 78  0
         UIViewRoot viewRoot = super.createView(context, viewId);
 79  0
         if (PortletUtil.isPortletRequest(context))
 80  
         {
 81  0
             PortletRequest request = (PortletRequest) context.getExternalContext().getRequest();
 82  0
             viewRoot.setViewId(request.getParameter(MyFacesGenericPortlet.VIEW_ID));
 83  
         }
 84  0
         return viewRoot;
 85  
     }
 86  
 
 87  
     @Override
 88  
     public String getActionURL(FacesContext context, String viewId)
 89  
     {
 90  0
         if (PortletUtil.isRenderResponse(context))
 91  
         {
 92  0
             RenderResponse response = (RenderResponse) context.getExternalContext().getResponse();
 93  0
             PortletURL url = response.createActionURL();
 94  0
             url.setParameter(MyFacesGenericPortlet.VIEW_ID, viewId);
 95  0
             return url.toString();
 96  
         }
 97  0
         return super.getActionURL(context, viewId);
 98  
     }
 99  
 
 100  
     @Override
 101  
     public void renderView(FacesContext context, UIViewRoot viewToRender) throws IOException, FacesException
 102  
     {
 103  0
         if (PortletUtil.isPortletRequest(context))
 104  
         {
 105  0
             if (viewToRender.isRendered())
 106  
             {
 107  0
                 if (log.isTraceEnabled())
 108  0
                     log.trace("It is a portlet request. Dispatching to view");
 109  0
                 context.getExternalContext().dispatch(viewToRender.getViewId());
 110  
             }
 111  
         }
 112  
         else
 113  
         {
 114  0
             super.renderView(context, viewToRender);
 115  
         }
 116  0
     }
 117  
 }