01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/jsf/tags/sakai_2-4-1/widgets/src/java/org/sakaiproject/jsf/renderer/StylesheetRenderer.java $
03: * $Id: StylesheetRenderer.java 9278 2006-05-10 23:29:21Z ray@media.berkeley.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2003, 2004 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.jsf.renderer;
21:
22: import java.io.IOException;
23: import javax.faces.component.UIComponent;
24: import javax.faces.component.UIOutput;
25: import javax.faces.context.FacesContext;
26: import javax.faces.context.ResponseWriter;
27: import javax.faces.render.Renderer;
28:
29: import org.sakaiproject.jsf.util.RendererUtil;
30:
31: /**
32: * <p>Description: </p>
33: * <p>Render a stylesheet link for the value of our component's
34: * <code>path</code> attribute, prefixed by the context path of this
35: * web application.</p>
36: * <p> Based on example code by Sun Microsystems. </p>
37: * <p>Copyright: Copyright (c) 2004</p>
38: * <p>Organization: Sakai Project</p>
39: * @author Ed Smiley
40: * @version $Id: StylesheetRenderer.java 9278 2006-05-10 23:29:21Z ray@media.berkeley.edu $
41: */
42:
43: public class StylesheetRenderer extends Renderer {
44:
45: public boolean supportsComponentType(UIComponent component) {
46: return (component instanceof UIOutput);
47: }
48:
49: public void decode(FacesContext context, UIComponent component) {
50: }
51:
52: public void encodeBegin(FacesContext context, UIComponent component)
53: throws IOException {
54: ;
55: }
56:
57: public void encodeChildren(FacesContext context,
58: UIComponent component) throws IOException {
59: ;
60: }
61:
62: /**
63: * <p>Render a relative HTML <code><link></code> element for a
64: * <code>text/css</code> stylesheet at the specified context-relative
65: * path.</p>
66: *
67: * @param context FacesContext for the request we are processing
68: * @param component UIComponent to be rendered
69: *
70: * @throws IOException if an input/output error occurs while rendering
71: * @throws NullPointerException if <code>context</code>
72: * or <code>component</code> is null
73: */
74: public void encodeEnd(FacesContext context, UIComponent component)
75: throws IOException {
76:
77: if (!component.isRendered()) {
78: return;
79: }
80:
81: ResponseWriter writer = context.getResponseWriter();
82:
83: String contextPath = (String) RendererUtil.getAttribute(
84: context, component, "contextBase");
85: if (contextPath == null || contextPath == "") {
86: contextPath = context.getExternalContext()
87: .getRequestContextPath();
88: }
89:
90: writer
91: .write("<link rel=\"stylesheet\" type=\"text/css\" href=\"");
92:
93: writer.write(contextPath);
94: writer.write((String) RendererUtil.getAttribute(context,
95: component, "path"));
96: writer.write("\"/>");
97: }
98:
99: }
|