Coverage Report - org.apache.myfaces.shared.renderkit.html.HtmlGroupRendererBase
 
Classes in this File Line Coverage Branch Coverage Complexity
HtmlGroupRendererBase
0%
0/45
0%
0/28
3.8
 
 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 org.apache.myfaces.shared.renderkit.RendererUtils;
 22  
 
 23  
 import javax.faces.component.UIComponent;
 24  
 import javax.faces.component.UIViewRoot;
 25  
 import javax.faces.component.html.HtmlPanelGroup;
 26  
 import javax.faces.context.FacesContext;
 27  
 import javax.faces.context.ResponseWriter;
 28  
 import java.io.IOException;
 29  
 import java.util.List;
 30  
 import java.util.Map;
 31  
 import javax.faces.component.behavior.ClientBehavior;
 32  
 import org.apache.myfaces.shared.renderkit.html.util.ResourceUtils;
 33  
 
 34  0
 public class HtmlGroupRendererBase
 35  
         extends HtmlRenderer 
 36  
 {
 37  
     private static final String LAYOUT_BLOCK_VALUE = "block";
 38  
 
 39  
     public boolean getRendersChildren()
 40  
     {
 41  0
         return true;
 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  
     public void encodeBegin(FacesContext context, UIComponent component)
 54  
             throws IOException
 55  
     {
 56  0
     }
 57  
 
 58  
     public void encodeChildren(FacesContext context, UIComponent component)
 59  
         throws IOException
 60  
     {
 61  0
     }
 62  
 
 63  
     public void encodeEnd(FacesContext context, UIComponent component)
 64  
             throws IOException
 65  
     {
 66  0
         ResponseWriter writer = context.getResponseWriter();
 67  0
         boolean span = false;
 68  
 
 69  
         // will be SPAN or DIV, depending on the layout attribute value
 70  0
         String layoutElement = HTML.SPAN_ELEM;
 71  
 
 72  0
         HtmlPanelGroup panelGroup = (HtmlPanelGroup) component;
 73  
 
 74  
         // if layout is 'block', render DIV instead SPAN
 75  0
         String layout = panelGroup.getLayout();
 76  0
         if (layout != null && layout.equals(LAYOUT_BLOCK_VALUE))
 77  
         {
 78  0
             layoutElement = HTML.DIV_ELEM;
 79  
         }
 80  
         
 81  0
         Map<String, List<ClientBehavior>> behaviors = panelGroup.getClientBehaviors();
 82  0
         if (behaviors != null && !behaviors.isEmpty())
 83  
         {
 84  0
             ResourceUtils.renderDefaultJsfJsInlineIfNecessary(context, writer);
 85  
         }
 86  
 
 87  0
         if( (!behaviors.isEmpty()) || 
 88  
                 (component.getId()!=null && !component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX)))
 89  
         {
 90  0
             span = true;
 91  
 
 92  0
             writer.startElement(layoutElement, component);
 93  
 
 94  
             //HtmlRendererUtils.writeIdIfNecessary(writer, component, context);
 95  0
             writer.writeAttribute(HTML.ID_ATTR, component.getClientId(context), null);
 96  
 
 97  0
             long commonPropertiesMarked = 0L;
 98  0
             if (isCommonPropertiesOptimizationEnabled(context))
 99  
             {
 100  0
                 commonPropertiesMarked = CommonPropertyUtils.getCommonPropertiesMarked(component);
 101  0
                 CommonPropertyUtils.renderCommonPassthroughPropertiesWithoutEvents(writer, 
 102  
                         commonPropertiesMarked, component);
 103  
             }
 104  
             else
 105  
             {
 106  0
                 HtmlRendererUtils.renderHTMLAttributes(writer, component, HTML.UNIVERSAL_ATTRIBUTES);
 107  
             }
 108  0
             if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(context))
 109  
             {
 110  0
                 CommonPropertyUtils.renderEventProperties(writer, 
 111  
                         commonPropertiesMarked, component);
 112  
             }
 113  
             else
 114  
             {
 115  0
                 if (isCommonEventsOptimizationEnabled(context))
 116  
                 {
 117  0
                     CommonEventUtils.renderBehaviorizedEventHandlers(context, writer, 
 118  
                            commonPropertiesMarked,
 119  
                            CommonEventUtils.getCommonEventsMarked(component), component, behaviors);
 120  
                 }
 121  
                 else
 122  
                 {
 123  0
                     HtmlRendererUtils.renderBehaviorizedEventHandlers(context, writer, component, behaviors);
 124  
                 }
 125  
             }
 126  0
         }
 127  
         else
 128  
         {
 129  0
             if (isCommonPropertiesOptimizationEnabled(context))
 130  
             {
 131  0
                 long commonPropertiesMarked = CommonPropertyUtils.getCommonPropertiesMarked(component);
 132  0
                 if (commonPropertiesMarked > 0)
 133  
                 {
 134  0
                     span = true;
 135  0
                     writer.startElement(layoutElement, component);
 136  0
                     HtmlRendererUtils.writeIdIfNecessary(writer, component, context);
 137  
 
 138  0
                     CommonPropertyUtils.renderCommonPassthroughProperties(writer, commonPropertiesMarked, component);
 139  
                 }
 140  0
             }
 141  
             else
 142  
             {
 143  0
                 span=HtmlRendererUtils.renderHTMLAttributesWithOptionalStartElement(writer,
 144  
                                                                                  component,
 145  
                                                                                  layoutElement,
 146  
                                                                                  HTML.COMMON_PASSTROUGH_ATTRIBUTES);
 147  
             }
 148  
         }
 149  
 
 150  0
         RendererUtils.renderChildren(context, component);
 151  0
         if (span)
 152  
         {
 153  0
             writer.endElement(layoutElement);
 154  
         }
 155  0
     }
 156  
 
 157  
 }