01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/sam/tags/sakai_2-4-1/samigo-app/src/java/org/sakaiproject/tool/assessment/jsf/renderer/ScriptRenderer.java $
03: * $Id: ScriptRenderer.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: ScriptRenderer.java 9268 2006-05-10 21:27:24Z daisyf@stanford.edu $
39: */
40:
41: public class ScriptRenderer 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 encodeChildren(FacesContext context,
51: UIComponent component) throws IOException {
52: ;
53: }
54:
55: public void encodeBegin(FacesContext context, UIComponent component)
56: throws IOException {
57: ;
58: }
59:
60: /**
61: * <p>Render a relative HTML <code><script></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: /**
73: * <p>Faces render output method to output script tag.</p>
74: * <p>Method Generator: org.sakaiproject.tool.assessment.devtoolsRenderMaker</p>
75: *
76: * @param context <code>FacesContext</code> for the current request
77: * @param component <code>UIComponent</code> being rendered
78: *
79: * @throws IOException if an input/output error occurs
80: */
81: public void encodeEnd(FacesContext context, UIComponent component)
82: throws IOException {
83: String path = (String) component.getAttributes().get("path");
84: String type = (String) component.getAttributes().get("type");
85:
86: if ("".equals(type) || type == null) {
87: type = "text/javascript";
88: }
89: ResponseWriter writer = context.getResponseWriter();
90: String contextPath = context.getExternalContext()
91: .getRequestContextPath();
92: writer.write("<script src=\"" + contextPath + path
93: + "\" type=\"" + type + "\">");
94: // ie requires
95: writer.write("</script>");
96: }
97:
98: }
|