Coverage Report - org.apache.myfaces.shared_impl.renderkit.html.HtmlImageRendererBase
 
Classes in this File Line Coverage Branch Coverage Complexity
HtmlImageRendererBase
0%
0/19
0%
0/10
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.shared_impl.renderkit.html;
 20  
 
 21  
 import org.apache.commons.logging.Log;
 22  
 import org.apache.commons.logging.LogFactory;
 23  
 import org.apache.myfaces.shared_impl.renderkit.JSFAttr;
 24  
 
 25  
 import javax.faces.component.UIComponent;
 26  
 import javax.faces.component.UIGraphic;
 27  
 import javax.faces.component.html.HtmlGraphicImage;
 28  
 import javax.faces.context.FacesContext;
 29  
 import javax.faces.context.ResponseWriter;
 30  
 import java.io.IOException;
 31  
 
 32  
 
 33  
 /**
 34  
  * @author Manfred Geiler (latest modification by $Author: grantsmith $)
 35  
  * @author Thomas Spiegl
 36  
  * @author Anton Koinov
 37  
  * @version $Revision$ $Date: 2005-05-11 18:45:06 +0200 (Wed, 11 May 2005) $
 38  
  */
 39  0
 public class HtmlImageRendererBase
 40  
         extends HtmlRenderer
 41  
 {
 42  0
     private static final Log log = LogFactory.getLog(HtmlImageRendererBase.class);
 43  
 
 44  
     public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
 45  
             throws IOException
 46  
     {
 47  0
         org.apache.myfaces.shared_impl.renderkit.RendererUtils.checkParamValidity(facesContext, uiComponent, UIGraphic.class);
 48  
 
 49  0
         ResponseWriter writer = facesContext.getResponseWriter();
 50  
 
 51  
         String url;
 52  0
         if (uiComponent instanceof HtmlGraphicImage)
 53  
         {
 54  0
             url = ((HtmlGraphicImage) uiComponent).getUrl();
 55  
         }
 56  
         else
 57  
         {
 58  0
             url = (String) uiComponent.getAttributes().get(JSFAttr.URL_ATTR);
 59  
         }
 60  
 
 61  0
         writer.startElement(HTML.IMG_ELEM, uiComponent);
 62  
 
 63  0
         HtmlRendererUtils.writeIdIfNecessary(writer, uiComponent, facesContext);
 64  
 
 65  0
         if (url != null && url.length() > 0)
 66  
         {
 67  0
             String src = facesContext.getApplication()
 68  
                     .getViewHandler().getResourceURL(facesContext, url);
 69  0
             writer.writeURIAttribute(HTML.SRC_ATTR,
 70  
                     facesContext.getExternalContext().encodeResourceURL(src),
 71  
                     JSFAttr.VALUE_ATTR);
 72  0
         }
 73  
         else
 74  
         {
 75  0
             if (log.isWarnEnabled()) log.warn("Graphic with id " + uiComponent.getClientId(facesContext) + " has no value (url).");
 76  
         }
 77  
 
 78  
         /* 
 79  
          * Warn the user if the ALT attribute is missing.
 80  
          */                
 81  0
         if (uiComponent.getAttributes().get(HTML.ALT_ATTR) == null) 
 82  
         {
 83  0
             log.warn("ALT attribute is missing for : " + uiComponent.getId());
 84  
         }
 85  
 
 86  0
         HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.IMG_PASSTHROUGH_ATTRIBUTES);
 87  
 
 88  0
         writer.endElement(org.apache.myfaces.shared_impl.renderkit.html.HTML.IMG_ELEM);
 89  
 
 90  0
     }
 91  
 
 92  
 }