Coverage Report - org.apache.myfaces.renderkit.html.HtmlHeadRenderer
 
Classes in this File Line Coverage Branch Coverage Complexity
HtmlHeadRenderer
0%
0/20
0%
0/6
2.5
 
 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.renderkit.html;
 20  
 
 21  
 import java.io.IOException;
 22  
 import java.util.List;
 23  
 
 24  
 import javax.faces.application.ProjectStage;
 25  
 import javax.faces.component.UIComponent;
 26  
 import javax.faces.component.UIViewRoot;
 27  
 import javax.faces.context.FacesContext;
 28  
 import javax.faces.context.ResponseWriter;
 29  
 import javax.faces.render.Renderer;
 30  
 
 31  
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFRenderer;
 32  
 import org.apache.myfaces.shared.config.MyfacesConfig;
 33  
 import org.apache.myfaces.shared.renderkit.html.HTML;
 34  
 import org.apache.myfaces.shared.renderkit.html.HtmlRendererUtils;
 35  
 
 36  
 /**
 37  
  * Renderer used by h:head component
 38  
  * 
 39  
  * @since 2.0
 40  
  * @author Leonardo Uribe (latest modification by $Author$)
 41  
  * @version $Revision$ $Date$
 42  
  */
 43  
 @JSFRenderer(renderKitId = "HTML_BASIC", family = "javax.faces.Output", type = "javax.faces.Head")
 44  0
 public class HtmlHeadRenderer extends Renderer
 45  
 {
 46  
     //TODO: Move constants to shared HTML class
 47  
     private final static String HEAD_ELEM = "head";
 48  
     private final static String HEAD_TARGET = HEAD_ELEM;
 49  
 
 50  
     private final static String PROFILE_ATTR = "profile";
 51  
 
 52  0
     private final static String[] HEAD_PASSTHROUGH_ATTRIBUTES = { HTML.DIR_ATTR,
 53  
             HTML.LANG_ATTR, PROFILE_ATTR};
 54  
 
 55  
     @Override
 56  
     public void encodeBegin(FacesContext facesContext, UIComponent component)
 57  
             throws IOException
 58  
     {
 59  0
         super.encodeBegin(facesContext, component); //check for NP
 60  
 
 61  0
         ResponseWriter writer = facesContext.getResponseWriter();
 62  0
         writer.startElement(HEAD_ELEM, component);
 63  0
         HtmlRendererUtils.writeIdIfNecessary(writer, component, facesContext);
 64  0
         HtmlRendererUtils.renderHTMLAttributes(writer, component,
 65  
                 HEAD_PASSTHROUGH_ATTRIBUTES);
 66  0
         HtmlRendererUtils.renderHTMLAttribute(writer, component, HTML.XMLNS_ATTR , HTML.XMLNS_ATTR);
 67  0
     }
 68  
 
 69  
     @Override
 70  
     public void encodeEnd(FacesContext facesContext, UIComponent component)
 71  
             throws IOException
 72  
     {
 73  0
         super.encodeEnd(facesContext, component); //check for NP
 74  
 
 75  0
         ResponseWriter writer = facesContext.getResponseWriter();
 76  0
         UIViewRoot root = facesContext.getViewRoot();
 77  0
         List<UIComponent> componentResources = root.getComponentResources(facesContext,
 78  
                 HEAD_TARGET);
 79  
         
 80  0
         for (int i = 0, childCount = componentResources.size(); i < childCount; i++)
 81  
         {
 82  0
             UIComponent child = componentResources.get(i);
 83  0
             child.encodeAll(facesContext);
 84  
         }
 85  0
         writer.endElement(HEAD_ELEM);
 86  
 
 87  0
         if (MyfacesConfig.getCurrentInstance(facesContext.getExternalContext()).isEarlyFlushEnabled() &&
 88  
                 facesContext.isProjectStage(ProjectStage.Production))
 89  
         {
 90  0
             writer.flush();
 91  
         }
 92  0
     }
 93  
 }