Coverage Report - org.apache.myfaces.shared.renderkit.html.HtmlImageRendererBase
 
Classes in this File Line Coverage Branch Coverage Complexity
HtmlImageRendererBase
0%
0/40
0%
0/32
9
 
 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  
 import java.util.logging.Level;
 25  
 import java.util.logging.Logger;
 26  
 
 27  
 import javax.faces.application.ProjectStage;
 28  
 import javax.faces.component.UIComponent;
 29  
 import javax.faces.component.UIGraphic;
 30  
 import javax.faces.component.behavior.ClientBehavior;
 31  
 import javax.faces.component.behavior.ClientBehaviorHolder;
 32  
 import javax.faces.context.FacesContext;
 33  
 import javax.faces.context.ResponseWriter;
 34  
 
 35  
 import org.apache.myfaces.shared.renderkit.JSFAttr;
 36  
 import org.apache.myfaces.shared.renderkit.RendererUtils;
 37  
 import org.apache.myfaces.shared.renderkit.html.util.ResourceUtils;
 38  
 
 39  
 
 40  0
 public class HtmlImageRendererBase
 41  
         extends HtmlRenderer
 42  
 {
 43  
     //private static final Log log = LogFactory.getLog(HtmlImageRendererBase.class);
 44  0
     private static final Logger log = Logger.getLogger(HtmlImageRendererBase.class.getName());
 45  
     
 46  
     public void decode(FacesContext context, UIComponent component)
 47  
     {
 48  
         //check for npe
 49  0
         super.decode(context, component);
 50  
         
 51  0
         HtmlRendererUtils.decodeClientBehaviors(context, component);
 52  0
     }
 53  
 
 54  
     public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
 55  
             throws IOException
 56  
     {
 57  0
         org.apache.myfaces.shared.renderkit.RendererUtils.checkParamValidity(
 58  
                 facesContext, uiComponent, UIGraphic.class);
 59  
 
 60  0
         ResponseWriter writer = facesContext.getResponseWriter();
 61  
         
 62  0
         Map<String, List<ClientBehavior>> behaviors = null;
 63  0
         if (uiComponent instanceof ClientBehaviorHolder)
 64  
         {
 65  0
             behaviors = ((ClientBehaviorHolder) uiComponent).getClientBehaviors();
 66  0
             if (!behaviors.isEmpty())
 67  
             {
 68  0
                 ResourceUtils.renderDefaultJsfJsInlineIfNecessary(facesContext, writer);
 69  
             }
 70  
         }
 71  
         
 72  0
         writer.startElement(HTML.IMG_ELEM, uiComponent);
 73  
 
 74  0
         if (uiComponent instanceof ClientBehaviorHolder
 75  
                 && !behaviors.isEmpty())
 76  
         {
 77  0
             HtmlRendererUtils.writeIdAndName(writer, uiComponent, facesContext);
 78  
         }
 79  
         else
 80  
         {
 81  0
             HtmlRendererUtils.writeIdIfNecessary(writer, uiComponent, facesContext);
 82  
         }
 83  
 
 84  0
         final String url = RendererUtils.getIconSrc(facesContext, uiComponent, JSFAttr.URL_ATTR);
 85  0
         if (url != null)
 86  
         {
 87  0
             writer.writeURIAttribute(HTML.SRC_ATTR, url,JSFAttr.VALUE_ATTR);
 88  
         }
 89  
         else
 90  
         {
 91  0
           if (facesContext.isProjectStage(ProjectStage.Development) && log.isLoggable(Level.WARNING))
 92  
           {
 93  0
               log.warning("Component UIGraphic " + uiComponent.getClientId(facesContext) 
 94  
                       + " has no attribute url, value, name or attribute resolves to null. Path to component " 
 95  
                       + RendererUtils.getPathToComponent(uiComponent));
 96  
           }
 97  
         }
 98  
 
 99  
         /* 
 100  
          * Warn the user if the ALT attribute is missing.
 101  
          */                
 102  0
         if (uiComponent.getAttributes().get(HTML.ALT_ATTR) == null) 
 103  
         {
 104  0
             if(facesContext.isProjectStage(ProjectStage.Development) && log.isLoggable(Level.WARNING))
 105  
             {
 106  0
                 log.warning("Component UIGraphic " + uiComponent.getClientId(facesContext) 
 107  
                         + " has no attribute alt or attribute resolves to null. Path to component " 
 108  
                         + RendererUtils.getPathToComponent(uiComponent));
 109  
             }
 110  
         }
 111  
 
 112  0
         if (uiComponent instanceof ClientBehaviorHolder)
 113  
         {
 114  0
             if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext))
 115  
             {
 116  0
                 CommonPropertyUtils.renderEventProperties(writer, 
 117  
                         CommonPropertyUtils.getCommonPropertiesMarked(uiComponent), uiComponent);
 118  
             }
 119  
             else
 120  
             {
 121  0
                 if (isCommonEventsOptimizationEnabled(facesContext))
 122  
                 {
 123  0
                     CommonEventUtils.renderBehaviorizedEventHandlers(facesContext, writer, 
 124  
                            CommonPropertyUtils.getCommonPropertiesMarked(uiComponent),
 125  
                            CommonEventUtils.getCommonEventsMarked(uiComponent), uiComponent, behaviors);
 126  
                 }
 127  
                 else
 128  
                 {
 129  0
                     HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, uiComponent, behaviors);
 130  
                 }
 131  
             }
 132  0
             if (isCommonPropertiesOptimizationEnabled(facesContext))
 133  
             {
 134  0
                 HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.IMG_ATTRIBUTES);
 135  0
                 CommonPropertyUtils.renderCommonPassthroughPropertiesWithoutEvents(writer, 
 136  
                         CommonPropertyUtils.getCommonPropertiesMarked(uiComponent), uiComponent);
 137  
             }
 138  
             else
 139  
             {
 140  0
                 HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, 
 141  
                         HTML.IMG_PASSTHROUGH_ATTRIBUTES_WITHOUT_EVENTS);
 142  
             }
 143  
         }
 144  
         else
 145  
         {
 146  0
             if (isCommonPropertiesOptimizationEnabled(facesContext))
 147  
             {
 148  0
                 HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.IMG_ATTRIBUTES);
 149  0
                 CommonPropertyUtils.renderCommonPassthroughProperties(writer, 
 150  
                         CommonPropertyUtils.getCommonPropertiesMarked(uiComponent), uiComponent);
 151  
             }
 152  
             else
 153  
             {
 154  0
                 HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, 
 155  
                         HTML.IMG_PASSTHROUGH_ATTRIBUTES);
 156  
             }
 157  
         }
 158  
 
 159  0
         writer.endElement(org.apache.myfaces.shared.renderkit.html.HTML.IMG_ELEM);
 160  
 
 161  0
     }
 162  
 
 163  
 }