001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sam/tags/sakai_2-4-1/samigo-app/src/java/org/sakaiproject/tool/assessment/jsf/renderer/TimerBarRenderer.java $
003: * $Id: TimerBarRenderer.java 9268 2006-05-10 21:27:24Z daisyf@stanford.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2004, 2005, 2006 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.tool.assessment.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: import javax.faces.component.UIViewRoot;
029: import java.util.Map;
030:
031: /**
032: * <p>Description: </p>
033: * <p>Description:<br />
034: * This class is the class that renders the <code>timerBar</code>
035: * custom tag.</p>
036: * <p>Copyright: Copyright (c) 2004</p>
037: * <p>Organization: Sakai Project</p>
038: * @author Ed Smiley
039: * @author (JavaScript) Brian Gosselin of http://scriptasylum.com
040: * @version $Id: TimerBarRenderer.java 9268 2006-05-10 21:27:24Z daisyf@stanford.edu $
041: */
042:
043: public class TimerBarRenderer extends Renderer {
044: private static final String SCRIPT_PATH = "/jsf/widget/timerBar/";
045:
046: public boolean supportsComponentType(UIComponent component) {
047: return (component instanceof UIOutput);
048: }
049:
050: public void decode(FacesContext context, UIComponent component) {
051: }
052:
053: public void encodeChildren(FacesContext context,
054: UIComponent component) throws IOException {
055: ;
056: }
057:
058: /**
059: * <p>Faces render output method .</p>
060: * <p>Method Generator: org.sakaiproject.tool.assessment.devtools.RenderMaker</p>
061: *
062: * @param context <code>FacesContext</code> for the current request
063: * @param component <code>UIComponent</code> being rendered
064: *
065: * @throws IOException if an input/output error occurs
066: */
067: public void encodeEnd(FacesContext context, UIComponent component)
068: throws IOException {
069:
070: if (!component.isRendered()) {
071: return;
072: }
073:
074: ResponseWriter writer = context.getResponseWriter();
075:
076: String clientId = null;
077:
078: if (component.getId() != null
079: && !component.getId().startsWith(
080: UIViewRoot.UNIQUE_ID_PREFIX)) {
081: clientId = component.getClientId(context);
082: }
083:
084: if (clientId != null) {
085: writer.startElement("span", component);
086: writer.writeAttribute("id", clientId, "id");
087: }
088:
089: Map attrMap = component.getAttributes();
090:
091: writer.write("\n");
092: writer.write("\n<script language=\"javascript\">");
093: writer.write("\n// Timer Bar - Version 1.0");
094: writer
095: .write("\n// Based on Script by Brian Gosselin of http://scriptasylum.com");
096: writer
097: .write("\n var loadedcolor='gray' ; // PROGRESS BAR COLOR");
098:
099: writer
100: .write("\n var unloadedcolor='green'; // COLOR OF UNLOADED AREA");
101:
102: writer
103: .write("\n var bordercolor='navy'; // COLOR OF THE BORDER");
104: writer.write("\n var barheight = " + attrMap.get("height")
105: + "; // HEIGHT OF PROGRESS BAR IN PIXELS");
106: writer.write("\n var barwidth = " + attrMap.get("width")
107: + "; // WIDTH OF THE BAR IN PIXELS");
108: writer.write("\n var waitTime = " + attrMap.get("wait")
109: + "; // NUMBER OF SECONDS FOR PROGRESSBAR");
110: writer.write("\n var loaded = " + attrMap.get("elapsed")
111: + "*10; // TENTHS OF A SECOND ELAPSED");
112: writer
113: .write("\n// THE FUNCTION BELOW CONTAINS THE ACTION(S) TAKEN ONCE BAR REACHES 100.");
114: writer.write("\n");
115: writer.write("\n var action = function()");
116: writer.write("\n {");
117: writer.write("\n " + attrMap.get("expireScript") + ";");
118: writer.write("\n alert(\"" + attrMap.get("expireMessage")
119: + "\");");
120: writer.write("\n }");
121: writer.write("\n");
122: writer.write("\n</script>");
123: String contextPath = context.getExternalContext()
124: .getRequestContextPath();
125: writer
126: .write("\n<script language=\"javascript\" src=\""
127: + contextPath + SCRIPT_PATH
128: + "timerbar.js\"></script>");
129: writer.write("\n");
130:
131: if (clientId != null) {
132: writer.endElement("span");
133: }
134: }
135:
136: }
|