Coverage Report - org.seasar.teeda.core.render.html.HtmlGraphicImageRenderer
 
Classes in this File Line Coverage Branch Coverage Complexity
HtmlGraphicImageRenderer
93%
25/27
100%
4/4
1.75
 
 1  
 /*
 2  
  * Copyright 2004-2011 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.teeda.core.render.html;
 17  
 
 18  
 import java.io.IOException;
 19  
 
 20  
 import javax.faces.component.UIComponent;
 21  
 import javax.faces.component.UIGraphic;
 22  
 import javax.faces.context.FacesContext;
 23  
 import javax.faces.context.ResponseWriter;
 24  
 import javax.faces.internal.IgnoreAttribute;
 25  
 
 26  
 import org.seasar.teeda.core.JsfConstants;
 27  
 import org.seasar.teeda.core.render.AbstractRenderer;
 28  
 import org.seasar.teeda.core.util.FacesContextUtil;
 29  
 import org.seasar.teeda.core.util.RendererUtil;
 30  
 
 31  
 /**
 32  
  * @author manhole
 33  
  */
 34  34
 public class HtmlGraphicImageRenderer extends AbstractRenderer {
 35  
 
 36  
     public static final String COMPONENT_FAMILY = "javax.faces.Graphic";
 37  
 
 38  
     public static final String RENDERER_TYPE = "javax.faces.Image";
 39  
 
 40  34
     private final IgnoreAttribute ignoreComponent = new IgnoreAttribute();
 41  
     {
 42  34
         ignoreComponent.addAttributeName(JsfConstants.ID_ATTR);
 43  34
         ignoreComponent.addAttributeName(JsfConstants.VALUE_ATTR);
 44  34
         ignoreComponent.addAttributeName(JsfConstants.URL_ATTR);
 45  34
     }
 46  
 
 47  
     public void encodeEnd(FacesContext context, UIComponent component)
 48  
             throws IOException {
 49  11
         assertNotNull(context, component);
 50  9
         if (!component.isRendered()) {
 51  1
             return;
 52  
         }
 53  8
         encodeHtmlGraphicImageEnd(context, (UIGraphic) component);
 54  8
     }
 55  
 
 56  
     protected void encodeHtmlGraphicImageEnd(FacesContext context,
 57  
             UIGraphic graphic) throws IOException {
 58  8
         ResponseWriter writer = context.getResponseWriter();
 59  8
         writer.startElement(JsfConstants.IMG_ELEM, graphic);
 60  8
         RendererUtil.renderIdAttributeIfNecessary(writer, graphic,
 61  
                 getIdForRender(context, graphic));
 62  8
         final String url = getUrl(context, graphic);
 63  8
         writer.writeURIAttribute(JsfConstants.SRC_ATTR, url, null);
 64  8
         renderRemainAttributes(graphic, writer, ignoreComponent);
 65  8
         writer.endElement(JsfConstants.IMG_ELEM);
 66  8
     }
 67  
 
 68  
     protected String getUrl(FacesContext context, UIGraphic htmlGraphicImage) {
 69  8
         String url = htmlGraphicImage.getUrl();
 70  8
         if (url == null) {
 71  4
             url = "";
 72  
         }
 73  8
         url = FacesContextUtil.getViewHandler(context).getResourceURL(context,
 74  
                 url);
 75  8
         url = context.getExternalContext().encodeResourceURL(url);
 76  8
         return url;
 77  
     }
 78  
 
 79  
     protected void addIgnoreAttributeName(final String attr) {
 80  0
         ignoreComponent.addAttributeName(attr);
 81  0
     }
 82  
 
 83  
 }