01: /*
02: * Copyright 2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.shared_impl.renderkit.html;
17:
18: import org.apache.commons.logging.Log;
19: import org.apache.commons.logging.LogFactory;
20: import org.apache.myfaces.shared_impl.renderkit.JSFAttr;
21:
22: import javax.faces.component.UIComponent;
23: import javax.faces.component.UIGraphic;
24: import javax.faces.component.html.HtmlGraphicImage;
25: import javax.faces.context.FacesContext;
26: import javax.faces.context.ResponseWriter;
27: import java.io.IOException;
28:
29: /**
30: * @author Manfred Geiler (latest modification by $Author: grantsmith $)
31: * @author Thomas Spiegl
32: * @author Anton Koinov
33: * @version $Revision$ $Date: 2005-05-11 18:45:06 +0200 (Wed, 11 May 2005) $
34: */
35: public class HtmlImageRendererBase extends HtmlRenderer {
36: private static final Log log = LogFactory
37: .getLog(HtmlImageRendererBase.class);
38:
39: public void encodeEnd(FacesContext facesContext,
40: UIComponent uiComponent) throws IOException {
41: org.apache.myfaces.shared_impl.renderkit.RendererUtils
42: .checkParamValidity(facesContext, uiComponent,
43: UIGraphic.class);
44:
45: ResponseWriter writer = facesContext.getResponseWriter();
46:
47: String url;
48: if (uiComponent instanceof HtmlGraphicImage) {
49: url = ((HtmlGraphicImage) uiComponent).getUrl();
50: } else {
51: url = (String) uiComponent.getAttributes().get(
52: JSFAttr.URL_ATTR);
53: }
54:
55: writer.startElement(HTML.IMG_ELEM, uiComponent);
56:
57: HtmlRendererUtils.writeIdIfNecessary(writer, uiComponent,
58: facesContext);
59:
60: if (url != null && url.length() > 0) {
61: String src = facesContext.getApplication().getViewHandler()
62: .getResourceURL(facesContext, url);
63: writer.writeURIAttribute(HTML.SRC_ATTR, facesContext
64: .getExternalContext().encodeResourceURL(src),
65: JSFAttr.VALUE_ATTR);
66: } else {
67: if (log.isWarnEnabled())
68: log.warn("Graphic with id "
69: + uiComponent.getClientId(facesContext)
70: + " has no value (url).");
71: }
72:
73: HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent,
74: HTML.IMG_PASSTHROUGH_ATTRIBUTES);
75:
76: writer
77: .endElement(org.apache.myfaces.shared_impl.renderkit.html.HTML.IMG_ELEM);
78:
79: }
80:
81: }
|