01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/sam/tags/sakai_2-4-1/samigo-app/src/java/org/sakaiproject/tool/assessment/jsf/renderer/StylesheetRenderer.java $
03: * $Id: StylesheetRenderer.java 9268 2006-05-10 21:27:24Z daisyf@stanford.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2004, 2005, 2006 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.tool.assessment.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: /**
30: * <p>Description: </p>
31: * <p>Render a stylesheet link for the value of our component's
32: * <code>path</code> attribute, prefixed by the context path of this
33: * web application.</p>
34: * <p> Based on example code by Sun Microsystems. </p>
35: * <p>Copyright: Copyright (c) 2004</p>
36: * <p>Organization: Sakai Project</p>
37: * @author Ed Smiley
38: * @version $Id: StylesheetRenderer.java 9268 2006-05-10 21:27:24Z daisyf@stanford.edu $
39: */
40:
41: public class StylesheetRenderer extends Renderer {
42:
43: public boolean supportsComponentType(UIComponent component) {
44: return (component instanceof UIOutput);
45: }
46:
47: public void decode(FacesContext context, UIComponent component) {
48: }
49:
50: public void encodeBegin(FacesContext context, UIComponent component)
51: throws IOException {
52: ;
53: }
54:
55: public void encodeChildren(FacesContext context,
56: UIComponent component) throws IOException {
57: ;
58: }
59:
60: /**
61: * <p>Render a relative HTML <code><link></code> element for a
62: * <code>text/css</code> stylesheet at the specified context-relative
63: * path.</p>
64: *
65: * @param context FacesContext for the request we are processing
66: * @param component UIComponent to be rendered
67: *
68: * @throws IOException if an input/output error occurs while rendering
69: * @throws NullPointerException if <code>context</code>
70: * or <code>component</code> is null
71: */
72: public void encodeEnd(FacesContext context, UIComponent component)
73: throws IOException {
74:
75: if ((context == null) || (component == null)) {
76: throw new NullPointerException();
77: }
78:
79: ResponseWriter writer = context.getResponseWriter();
80: String contextPath = context.getExternalContext()
81: .getRequestContextPath();
82: writer
83: .write("<link rel=\"stylesheet\" type=\"text/css\" href=\"");
84:
85: writer.write(contextPath);
86: writer.write((String) component.getAttributes().get("path"));
87: writer.write("\"/>");
88: }
89:
90: }
|