01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/jsf/widgets/src/java/org/theospi/jsf/renderer/XHeaderDrawerRenderer.java $
03: * $Id: XHeaderDrawerRenderer.java 22559 2007-03-13 19:46:06Z gsilver@umich.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 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.theospi.jsf.renderer;
21:
22: import java.io.IOException;
23: import java.util.Iterator;
24:
25: import javax.faces.component.UIComponent;
26: import javax.faces.component.UIOutput;
27: import javax.faces.context.FacesContext;
28: import javax.faces.context.ResponseWriter;
29: import javax.faces.render.Renderer;
30:
31: import org.sakaiproject.jsf.util.RendererUtil;
32: import org.theospi.jsf.component.XHeaderDrawerComponent;
33: import org.theospi.jsf.util.OspxTagHelper;
34:
35: public class XHeaderDrawerRenderer extends Renderer {
36: public boolean supportsComponentType(UIComponent component) {
37: return (component instanceof UIOutput);
38: }
39:
40: public void encodeBegin(FacesContext context,
41: UIComponent inComponent) throws IOException {
42: if (!(inComponent instanceof XHeaderDrawerComponent))
43: throw new IOException(
44: "the xheaderdrawer was expecting an xheaderdrawercomponent");
45:
46: ResponseWriter writer = context.getResponseWriter();
47: XHeaderDrawerComponent component = (XHeaderDrawerComponent) inComponent;
48:
49: String initiallyexpandedStr = (String) RendererUtil
50: .getAttribute(context, component, "initiallyexpanded");
51: String cssclass = (String) RendererUtil.getAttribute(context,
52: component, "cssclass");
53:
54: if (initiallyexpandedStr == null)
55: initiallyexpandedStr = "false";
56:
57: boolean initiallyexpanded = OspxTagHelper
58: .parseBoolean(initiallyexpandedStr);
59:
60: writer.write("<div");
61: RendererUtil.writeAttr(writer, "class", cssclass);
62: RendererUtil.writeAttr(writer, "id", component.getDivId());
63: if (!initiallyexpanded)
64: //removed padding - let the css deal with that
65: RendererUtil.writeAttr(writer, "style", "display:none;");
66: else
67: RendererUtil.writeAttr(writer, "style", "display:block;");
68: writer.write(">");
69: }
70:
71: /**
72: * @param context FacesContext for the request we are processing
73: * @param inComponent UIComponent to be rendered
74: * @exception IOException if an input/output error occurs while rendering
75: * @exception NullPointerException if <code>context</code> or <code>component</code> is null
76: */
77: public void encodeEnd(FacesContext context, UIComponent inComponent)
78: throws IOException {
79: XHeaderDrawerComponent component = (XHeaderDrawerComponent) inComponent;
80: ResponseWriter writer = context.getResponseWriter();
81:
82: writer.write("</div>");
83: writer.write("<script type=\"text/javascript\">\n");
84: writer.write("function refreshChildren"
85: + Math.abs(component.getDivId().hashCode()) + "() {");
86:
87: for (Iterator i = component.getInitScripts().iterator(); i
88: .hasNext();) {
89: writer.write(i.next().toString());
90: }
91:
92: writer.write("}");
93: writer.write("</script>\n");
94: }
95: }
|