001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/jsf/tags/sakai_2-4-1/widgets/src/java/org/sakaiproject/jsf/renderer/ScriptRenderer.java $
003: * $Id: ScriptRenderer.java 9278 2006-05-10 23:29:21Z ray@media.berkeley.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.jsf.renderer;
021:
022: import java.io.IOException;
023: import javax.faces.component.UIComponent;
024: import javax.faces.component.UIOutput;
025: import javax.faces.context.FacesContext;
026: import javax.faces.context.ResponseWriter;
027: import javax.faces.render.Renderer;
028:
029: import org.sakaiproject.jsf.util.RendererUtil;
030:
031: /**
032: * <p>Description: </p>
033: * <p>Render a stylesheet link for the value of our component's
034: * <code>path</code> attribute, prefixed by the context path of this
035: * web application.</p>
036: * <p> Based on example code by Sun Microsystems. </p>
037: * <p>Copyright: Copyright (c) 2004</p>
038: * <p>Organization: Sakai Project</p>
039: * @author Ed Smiley
040: * @version $Id: ScriptRenderer.java 9278 2006-05-10 23:29:21Z ray@media.berkeley.edu $
041: */
042:
043: public class ScriptRenderer extends Renderer {
044:
045: public boolean supportsComponentType(UIComponent component) {
046: return (component instanceof UIOutput);
047: }
048:
049: public void decode(FacesContext context, UIComponent component) {
050: }
051:
052: public void encodeChildren(FacesContext context,
053: UIComponent component) throws IOException {
054: ;
055: }
056:
057: public void encodeBegin(FacesContext context, UIComponent component)
058: throws IOException {
059: ;
060: }
061:
062: /**
063: * <p>Render a relative HTML <code><script></code> element for a
064: * <code>text/css</code> stylesheet at the specified context-relative
065: * path.</p>
066: *
067: * @param context FacesContext for the request we are processing
068: * @param component UIComponent to be rendered
069: *
070: * @throws IOException if an input/output error occurs while rendering
071: * @throws NullPointerException if <code>context</code>
072: * or <code>component</code> is null
073: */
074: /**
075: * <p>Faces render output method to output script tag.</p>
076: * <p>Method Generator: org.sakaiproject.tool.assessment.devtoolsRenderMaker</p>
077: *
078: * @param context <code>FacesContext</code> for the current request
079: * @param component <code>UIComponent</code> being rendered
080: *
081: * @throws IOException if an input/output error occurs
082: */
083: public void encodeEnd(FacesContext context, UIComponent component)
084: throws IOException {
085:
086: if (!component.isRendered()) {
087: return;
088: }
089:
090: String path = (String) RendererUtil.getAttribute(context,
091: component, "path");
092: String type = (String) RendererUtil.getAttribute(context,
093: component, "type");
094:
095: if ("".equals(type) || type == null) {
096: type = "text/javascript";
097: }
098: ResponseWriter writer = context.getResponseWriter();
099: String contextPath = (String) RendererUtil.getAttribute(
100: context, component, "contextBase");
101: if (contextPath == null || contextPath == "") {
102: contextPath = context.getExternalContext()
103: .getRequestContextPath();
104: }
105:
106: writer.write("<script src=\"" + contextPath + path
107: + "\" type=\"" + type + "\">");
108: // ie requires
109: writer.write("</script>");
110: }
111:
112: }
|