01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/help/tags/sakai_2-4-1/help-tool/src/java/org/sakaiproject/jsf/help/TocTreeRender.java $
03: * $Id: TocTreeRender.java 7653 2006-04-12 12:10:02Z marquard@ched.uct.ac.za $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2003, 2004 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.help;
21:
22: import java.io.IOException;
23: import java.util.Iterator;
24: import java.util.Set;
25:
26: import javax.faces.component.UIComponent;
27: import javax.faces.component.UIData;
28: import javax.faces.context.FacesContext;
29: import javax.faces.context.ResponseWriter;
30: import javax.faces.render.Renderer;
31:
32: import org.sakaiproject.api.app.help.Category;
33: import org.sakaiproject.api.app.help.Resource;
34:
35: /**
36: * toc tree renderer
37: * @version $Id: TocTreeRender.java 7653 2006-04-12 12:10:02Z marquard@ched.uct.ac.za $
38: */
39: public class TocTreeRender extends Renderer {
40:
41: /**
42: * @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
43: */
44: public void encodeBegin(FacesContext context, UIComponent component)
45: throws IOException {
46: String jsLibraryUrl = "../js";
47: ResponseWriter writer = context.getResponseWriter();
48: writer
49: .write("<script type=\"text/javascript\">var _editor_url = \""
50: + jsLibraryUrl + "/\";</script>\n");
51: writer.write("<script type=\"text/javascript\" src=\""
52: + jsLibraryUrl + "/divTree.js\"></script>\n");
53: writer
54: .write("<link href=\"../css/divTree.css\" type=\"text/css\" rel=\"stylesheet\">");
55:
56: UIData data = (UIData) component;
57: Object value = data.getValue();
58: Set categories = (Set) value;
59: encodeRecursive(writer, categories);
60: }
61:
62: /**
63: * encode recursively
64: * @param writer
65: * @param categories
66: * @throws IOException
67: */
68: private void encodeRecursive(ResponseWriter writer, Set categories)
69: throws IOException {
70: for (Iterator i = categories.iterator(); i.hasNext();) {
71: Category category = (Category) i.next();
72: writer
73: .write("<a class=\"trigger\" href=\"javascript:showBranch('"
74: + category.getName() + "');\">");
75: writer
76: .write("<img border=\"0\" alt=\"expand/collapse\" src=\"../image/toc_closed.gif\"");
77: writer.write(" id=\"I" + category.getName() + "\">");
78: writer.write(category.getName() + "</a>");
79: writer.write("<div class=\"branch\" id=\""
80: + category.getName() + "\">");
81: Set resources = category.getResources();
82: Set subCategories = category.getCategories();
83: encodeRecursive(writer, subCategories);
84: if (resources != null) {
85: for (Iterator j = categories.iterator(); j.hasNext();) {
86: Resource resource = (Resource) j.next();
87: writer.write("<div>");
88: writer.write("<img src=\"../image/topic.gif\">");
89: writer.write("<a href=\"content.hlp?docId="
90: + resource.getDocId()
91: + "\" target = \"content\">"
92: + resource.getName() + "</a></div>");
93: }
94: }
95: writer.write("</div>");
96: }
97: }
98: }
|