01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/jsf/tags/sakai_2-4-1/widgets/src/java/org/sakaiproject/jsf/renderer/CourierRenderer.java $
03: * $Id: CourierRenderer.java 9278 2006-05-10 23:29:21Z ray@media.berkeley.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005 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:
24: import javax.faces.component.UIComponent;
25: import javax.faces.component.UIOutput;
26: import javax.faces.context.FacesContext;
27: import javax.faces.context.ResponseWriter;
28: import javax.faces.render.Renderer;
29: import javax.servlet.http.HttpServletRequest;
30:
31: import org.sakaiproject.jsf.util.RendererUtil;
32:
33: public class CourierRenderer extends Renderer {
34: public boolean supportsComponentType(UIComponent component) {
35: return (component instanceof UIOutput);
36: }
37:
38: public void decode(FacesContext context, UIComponent component) {
39: }
40:
41: public void encodeBegin(FacesContext context, UIComponent component)
42: throws IOException {
43: }
44:
45: public void encodeChildren(FacesContext context,
46: UIComponent component) throws IOException {
47: }
48:
49: public void encodeEnd(FacesContext context, UIComponent component)
50: throws IOException {
51: ResponseWriter writer = context.getResponseWriter();
52: HttpServletRequest req = (HttpServletRequest) context
53: .getExternalContext().getRequest();
54:
55: // update time, in seconds
56: String updateTime = (String) RendererUtil.getAttribute(context,
57: component, "refresh");
58: if (updateTime == null || updateTime.length() == 0) {
59: updateTime = "10";
60: }
61:
62: // the current tool's placement ID
63: String placementId = (String) req
64: .getAttribute("sakai.tool.placement.id");
65: if (placementId == null) {
66: // FIXME:
67: // TODO: Report an error
68: }
69: writer
70: .write("<script type=\"text/javascript\" language=\"JavaScript\">\n");
71: writer.write("updateTime = " + updateTime + "000;\n");
72: writer.write("updateUrl = \"" + serverUrl(req) + "/courier/"
73: + placementId + "\";\n");
74: writer.write("scheduleUpdate();\n");
75: writer.write("</script>\n");
76: }
77:
78: /**
79: * This method is a duplicate of org.sakaiproject.util.web.Web.serverUrl()
80: * Duplicated here from org.sakaiproject.util.web.Web.java so that
81: * the JSF tag library doesn't have a direct jar dependency on more of Sakai.
82: */
83: private static String serverUrl(HttpServletRequest req) {
84: StringBuffer url = new StringBuffer();
85: url.append(req.getScheme());
86: url.append("://");
87: url.append(req.getServerName());
88: if (((req.getServerPort() != 80) && (!req.isSecure()))
89: || ((req.getServerPort() != 443) && (req.isSecure()))) {
90: url.append(":");
91: url.append(req.getServerPort());
92: }
93:
94: return url.toString();
95: }
96: }
|