01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/syllabus/tags/sakai_2-4-1/syllabus-app/src/java/org/sakaiproject/jsf/syllabus/SyllabusIfNotRender.java $
03: * $Id: SyllabusIfNotRender.java 8802 2006-05-03 15:06:26Z cwen@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2003, 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.jsf.syllabus;
21:
22: import java.io.IOException;
23: import java.util.Iterator;
24:
25: import javax.faces.component.UIComponent;
26: import javax.faces.context.FacesContext;
27: import javax.faces.context.ResponseWriter;
28: import javax.faces.render.Renderer;
29:
30: public class SyllabusIfNotRender extends Renderer {
31: public boolean supportsComponentType(UIComponent component) {
32: return (component instanceof org.sakaiproject.jsf.syllabus.SyllabusIfNotComponent);
33: }
34:
35: public void encodeBegin(FacesContext context, UIComponent component)
36: throws IOException {
37: ResponseWriter writer = context.getResponseWriter();
38:
39: String test = (String) component.getAttributes().get("test");
40: if (test != null)
41: test = test.trim();
42:
43: if ((test != null) && (!test.equals(""))) {
44: writer.write("<div>");
45: }
46: }
47:
48: public void encodeEnd(FacesContext context, UIComponent component)
49: throws IOException {
50: ResponseWriter writer = context.getResponseWriter();
51:
52: String test = (String) component.getAttributes().get("test");
53: if (test != null)
54: test = test.trim();
55:
56: if ((test != null) && (!test.equals(""))) {
57: writer.write("</div>");
58: }
59: }
60:
61: public void encodeChildren(FacesContext context,
62: UIComponent component) throws IOException {
63: if (context == null || component == null) {
64: throw new NullPointerException();
65: }
66:
67: String test = (String) component.getAttributes().get("test");
68: if (test != null)
69: test = test.trim();
70:
71: if ((test != null) && (!test.equals(""))) {
72: Iterator kids = component.getChildren().iterator();
73:
74: while (kids.hasNext()) {
75: UIComponent kid = (UIComponent) kids.next();
76: kid.encodeBegin(context);
77: if (kid.getRendersChildren()) {
78: kid.encodeChildren(context);
79: }
80: kid.encodeEnd(context);
81: }
82: } else {
83: }
84: }
85: }
|