KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > renderkit > html > HtmlImageRenderer


1 /*
2  * Copyright 2004 The Apache Software Foundation.
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, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.myfaces.renderkit.html;
17
18 import org.apache.myfaces.renderkit.JSFAttr;
19 import org.apache.myfaces.renderkit.RendererUtils;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 import javax.faces.component.UIComponent;
25 import javax.faces.component.UIGraphic;
26 import javax.faces.component.html.HtmlGraphicImage;
27 import javax.faces.context.FacesContext;
28 import javax.faces.context.ResponseWriter;
29 import java.io.IOException JavaDoc;
30
31
32 /**
33  * @author Thomas Spiegl (latest modification by $Author: matze $)
34  * @author Anton Koinov
35  * @version $Revision: 1.11 $ $Date: 2004/10/13 11:51:00 $
36  * $Log: HtmlImageRenderer.java,v $
37  * Revision 1.11 2004/10/13 11:51:00 matze
38  * renamed packages to org.apache
39  *
40  * Revision 1.10 2004/07/01 22:05:07 mwessendorf
41  * ASF switch
42  *
43  * Revision 1.9 2004/05/18 11:59:13 manolito
44  * id attribute is rendered now
45  *
46  */

47 public class HtmlImageRenderer
48 extends HtmlRenderer
49 {
50     private static final Log log = LogFactory.getLog(HtmlImageRenderer.class);
51
52     public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
53             throws IOException JavaDoc
54     {
55         RendererUtils.checkParamValidity(facesContext, uiComponent, UIGraphic.class);
56
57         ResponseWriter writer = facesContext.getResponseWriter();
58
59         String JavaDoc url;
60         if (uiComponent instanceof HtmlGraphicImage)
61         {
62             url = ((HtmlGraphicImage)uiComponent).getUrl();
63         }
64         else
65         {
66             url = (String JavaDoc)uiComponent.getAttributes().get(JSFAttr.URL_ATTR);
67         }
68
69         if ((url != null) && (url.length() > 0))
70         {
71             writer.startElement(HTML.IMG_ELEM, uiComponent);
72
73             writer.writeAttribute(HTML.ID_ATTR, uiComponent.getClientId(facesContext), null);
74
75             String JavaDoc src = facesContext.getApplication()
76                             .getViewHandler().getResourceURL(facesContext, url);
77             writer.writeURIAttribute(HTML.SRC_ATTR,
78                                      facesContext.getExternalContext().encodeResourceURL(src),
79                                      null);
80
81             HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.IMG_PASSTHROUGH_ATTRIBUTES);
82
83             writer.endElement(HTML.IMG_ELEM);
84         }
85         else
86         {
87             if (log.isWarnEnabled()) log.warn("Graphic with id " + uiComponent.getClientId(facesContext) + " has no value (url).");
88         }
89     }
90 }
91
Popular Tags