Coverage Report - org.apache.myfaces.shared.renderkit.html.HtmlBodyRendererBase
 
Classes in this File Line Coverage Branch Coverage Complexity
HtmlBodyRendererBase
0%
0/48
0%
0/22
4.667
 
 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.shared.renderkit.html;
 20  
 
 21  
 import java.io.IOException;
 22  
 import java.util.List;
 23  
 import java.util.Map;
 24  
 
 25  
 import javax.faces.application.ProjectStage;
 26  
 import javax.faces.component.UIComponent;
 27  
 import javax.faces.component.UIViewRoot;
 28  
 import javax.faces.component.behavior.ClientBehavior;
 29  
 import javax.faces.component.behavior.ClientBehaviorHolder;
 30  
 import javax.faces.context.FacesContext;
 31  
 import javax.faces.context.ResponseWriter;
 32  
 
 33  
 import org.apache.myfaces.shared.renderkit.ClientBehaviorEvents;
 34  
 import org.apache.myfaces.shared.renderkit.html.util.ResourceUtils;
 35  
 
 36  
 /**
 37  
  * Renderer used by h:body component
 38  
  * 
 39  
  * @since 2.0
 40  
  */
 41  0
 public class HtmlBodyRendererBase extends HtmlRenderer
 42  
 {
 43  
 
 44  
     @Override
 45  
     public void decode(FacesContext context, UIComponent component)
 46  
     {
 47  
         // check for npe
 48  0
         super.decode(context, component);
 49  
         
 50  0
         HtmlRendererUtils.decodeClientBehaviors(context, component);
 51  0
     }
 52  
 
 53  
     @Override
 54  
     public void encodeBegin(FacesContext facesContext, UIComponent component)
 55  
             throws IOException
 56  
     {
 57  0
         super.encodeBegin(facesContext, component); //check for NP
 58  
 
 59  0
         ResponseWriter writer = facesContext.getResponseWriter();
 60  0
         Map<String, List<ClientBehavior>> behaviors = null;
 61  0
         if (component instanceof ClientBehaviorHolder)
 62  
         {
 63  0
             behaviors = ((ClientBehaviorHolder) component).getClientBehaviors();
 64  0
             if (!behaviors.isEmpty())
 65  
             {
 66  0
                 ResourceUtils.renderDefaultJsfJsInlineIfNecessary(facesContext, writer);
 67  
             }
 68  
 
 69  0
             writer.startElement(HTML.BODY_ELEM, component);
 70  0
             if (!behaviors.isEmpty())
 71  
             {
 72  
                 // Note "name" does not exists as attribute in <body> tag.
 73  0
                 writer.writeAttribute(HTML.ID_ATTR, component.getClientId(facesContext),null);
 74  
             }
 75  
             else
 76  
             {
 77  0
                 HtmlRendererUtils.writeIdIfNecessary(writer, component, facesContext);
 78  
             }
 79  0
             if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext))
 80  
             {
 81  0
                 CommonPropertyUtils.renderEventProperties(writer, 
 82  
                         CommonPropertyUtils.getCommonPropertiesMarked(component), component);
 83  
             }
 84  
             else
 85  
             {
 86  0
                 if (isCommonEventsOptimizationEnabled(facesContext))
 87  
                 {
 88  0
                     CommonEventUtils.renderBehaviorizedEventHandlers(facesContext, writer, 
 89  
                            CommonPropertyUtils.getCommonPropertiesMarked(component),
 90  
                            CommonEventUtils.getCommonEventsMarked(component), component, behaviors);
 91  
                 }
 92  
                 else
 93  
                 {
 94  0
                     HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, component, behaviors);
 95  
                 }
 96  
             }
 97  0
             HtmlRendererUtils.renderBehaviorizedAttribute(facesContext, writer, HTML.ONLOAD_ATTR, component,
 98  
                     ClientBehaviorEvents.LOAD, behaviors, HTML.ONLOAD_ATTR);
 99  0
             HtmlRendererUtils.renderBehaviorizedAttribute(facesContext, writer, HTML.ONUNLOAD_ATTR, component,
 100  
                     ClientBehaviorEvents.UNLOAD, behaviors, HTML.ONUNLOAD_ATTR);
 101  0
             if (isCommonPropertiesOptimizationEnabled(facesContext))
 102  
             {
 103  0
                 HtmlRendererUtils.renderHTMLAttributes(writer, component,
 104  
                         HTML.BODY_ATTRIBUTES_WITHOUT_EVENTS);
 105  0
                 CommonPropertyUtils.renderCommonPassthroughPropertiesWithoutEvents(writer, 
 106  
                         CommonPropertyUtils.getCommonPropertiesMarked(component), component);
 107  
             }
 108  
             else
 109  
             {
 110  0
                 HtmlRendererUtils.renderHTMLAttributes(writer, component,
 111  
                         HTML.BODY_PASSTHROUGH_ATTRIBUTES_WITHOUT_EVENTS);
 112  
             }
 113  0
             HtmlRendererUtils.renderHTMLStringAttribute(writer, component, HTML.XMLNS_ATTR , HTML.XMLNS_ATTR);
 114  
             
 115  
         }
 116  
         else
 117  
         {
 118  0
             writer.startElement(HTML.BODY_ELEM, component);
 119  0
             HtmlRendererUtils.writeIdIfNecessary(writer, component, facesContext);
 120  0
             if (isCommonPropertiesOptimizationEnabled(facesContext))
 121  
             {
 122  0
                 HtmlRendererUtils.renderHTMLAttributes(writer, component,
 123  
                         HTML.BODY_ATTRIBUTES);
 124  0
                 CommonPropertyUtils.renderCommonPassthroughProperties(writer, 
 125  
                         CommonPropertyUtils.getCommonPropertiesMarked(component), component);
 126  
             }
 127  
             else
 128  
             {
 129  0
                 HtmlRendererUtils.renderHTMLAttributes(writer, component,
 130  
                         HTML.BODY_PASSTHROUGH_ATTRIBUTES);
 131  
             }
 132  0
             HtmlRendererUtils.renderHTMLStringAttribute(writer, component, HTML.XMLNS_ATTR , HTML.XMLNS_ATTR);
 133  
         }
 134  0
     }
 135  
 
 136  
     @Override
 137  
     public void encodeEnd(FacesContext facesContext, UIComponent component)
 138  
             throws IOException
 139  
     {
 140  0
         super.encodeEnd(facesContext, component); //check for NP
 141  
 
 142  0
         ResponseWriter writer = facesContext.getResponseWriter();
 143  0
         UIViewRoot root = facesContext.getViewRoot();
 144  
         // Perf: use indexes for iteration over children,
 145  
         // componentResources are javax.faces.component._ComponentChildrenList._ComponentChildrenList(UIComponent)  
 146  0
         List<UIComponent> componentResources = root.getComponentResources(facesContext,
 147  
                 HTML.BODY_TARGET);
 148  0
         int childrenCount = componentResources.size();
 149  0
         if (childrenCount > 0)
 150  
         {
 151  0
             for (int i = 0; i < childrenCount; i++)
 152  
             {
 153  0
                 UIComponent child = componentResources.get(i);
 154  0
                 child.encodeAll(facesContext);
 155  
             }
 156  
         }
 157  
         
 158  
         // render all unhandled FacesMessages when ProjectStage is Development
 159  0
         if (facesContext.isProjectStage(ProjectStage.Development))
 160  
         {
 161  0
             HtmlRendererUtils.renderUnhandledFacesMessages(facesContext);
 162  
         }
 163  
         
 164  0
         writer.endElement(HTML.BODY_ELEM);
 165  0
     }
 166  
 }