KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > nav > renderer > html > SitemapRenderer


1 package org.exoplatform.portlets.nav.renderer.html;
2
3 import java.io.IOException JavaDoc;
4 import javax.faces.component.UIComponent;
5 import javax.faces.context.FacesContext;
6 import javax.faces.context.ResponseWriter;
7 import org.exoplatform.container.SessionContainer;
8 import org.exoplatform.faces.core.renderer.html.HtmlBasicRenderer;
9 import org.exoplatform.portal.session.ExoPortal;
10 import org.exoplatform.portal.session.RequestInfo;
11 import org.exoplatform.portlets.nav.component.UISitemap;
12 import org.exoplatform.services.portal.model.Node;
13 /**
14  * @author Fahrid Djebbari
15  * @version $Revision: 1.3 $ $Date: 2004/09/23 16:22:14 $
16  */

17 public class SitemapRenderer extends HtmlBasicRenderer {
18   private static int MAX_LEVEL = 3;
19   private static int COLUMNS_NUMBER = 3;
20
21   public void encodeChildren(FacesContext context, UIComponent component) throws IOException JavaDoc {
22     ResponseWriter w = context.getResponseWriter();
23     SessionContainer scontainer = SessionContainer.getInstance() ;
24     ExoPortal portal = (ExoPortal)scontainer.getComponentInstanceOfType(ExoPortal.class) ;
25     RequestInfo rinfo = (RequestInfo)scontainer.getComponentInstanceOfType(RequestInfo.class);
26     String JavaDoc ownerURI = rinfo.getOwnerURI() ;
27     Node root = portal.getRootNode();
28
29     w.write("<div class=\"UISitemap\">");
30     int trigger = Math.abs(root.getChildrenSize()/COLUMNS_NUMBER) + 1;
31     for(int i = 0; i < COLUMNS_NUMBER; i++){
32       String JavaDoc clazz = "odd";
33       if (i % 2 == 0)
34         clazz = "even";
35       w. write("<div class='" + clazz + "'>");
36       int startIndex = i * trigger;
37       for (int n = startIndex; n < startIndex + trigger; n++) {
38         Node child = root.getChild(n);
39         if (child == null)
40           break;
41         w. write("<ul class='first-level'>");
42         w. write("<li>");
43         w. write("<a HREF='"); w.write(ownerURI); w.write(child.getUri()); w.write("'>") ;
44         w. write(child.getResolvedLabel()) ;
45         w. write("</a>") ;
46         encodeNode(child, MAX_LEVEL, w, ownerURI);
47         w. write("</li>");
48         w. write("</ul>");
49       }
50       w. write("</div>");
51     }
52     w.write("</div>");
53   }
54
55   public void encodeNode(Node node, int level, ResponseWriter w, String JavaDoc ownerURI) throws IOException JavaDoc {
56     if (level > 0) {
57       w.write("<ul class='nth-level'>");
58       for (int n = 0; n < node.getChildrenSize(); n++) {
59         Node child = node.getChild(n);
60         w.write("<li>");
61         w. write("<a HREF='"); w.write(ownerURI); w.write(child.getUri()); w.write("'>") ;
62         w. write(child.getResolvedLabel()) ;
63         w. write("</a>") ;
64         this.encodeNode(child, level - 1, w, ownerURI);
65         w.write("</li>");
66       }
67       w.write("</ul>");
68     }
69   }
70 }
Popular Tags