KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.exoplatform.portlets.nav.renderer.xhtmlmp;
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 import org.exoplatform.services.portal.model.PageReference;
14 /**
15  * @author Fahrid Djebbari
16  * @version $Revision: 1.6 $ $Date: 2004/10/08 13:43:52 $
17  */

18 public class SitemapRenderer extends HtmlBasicRenderer {
19
20   public void encodeChildren(FacesContext context, UIComponent component) throws IOException JavaDoc {
21     UISitemap sitemap = (UISitemap) component;
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     String JavaDoc mimeType = sitemap.getPreferedMimeType() ;
28     Node root = portal.getRootNode() ;
29     w.write("<a HREF='"); w.write(ownerURI); w.write(root.getUri()); w.write("'>") ;
30     w. write("Home") ;
31     w.write("</a>") ;
32     if (root.getChildrenSize() > 0) w.write("<ul>");
33     for(int i = 0; i < root.getChildrenSize(); i++){
34       Node child = root.getChild(i);
35       PageReference pref = child.getPageReference(mimeType) ;
36       if(pref == null || pref.isVisible()) {
37         w.write("<li>");
38         w.write("<a HREF='"); w.write(ownerURI); w.write(child.getUri()); w.write("'>") ;
39         w. write(child.getResolvedLabel()) ;
40         w.write("</a>") ;
41         encodeNode(child,mimeType, w , ownerURI);
42         w.write("</li>");
43       }
44     }
45     if (root.getChildrenSize() > 0) w.write("</ul>");
46   }
47
48   public void encodeNode(Node node, String JavaDoc mimeType, ResponseWriter w, String JavaDoc baseURL) throws IOException JavaDoc {
49     if (node.getChildrenSize() > 0) w.write("<ul>");
50     for (int n = 0; n < node.getChildrenSize(); n++) {
51       Node child = node.getChild(n);
52       PageReference pref = child.getPageReference(mimeType) ;
53       if(pref == null || pref.isVisible()) {
54         w.write("<li>");
55         w. write("<a HREF='"); w.write(baseURL); w.write(child.getUri()); w.write("'>") ;
56         w. write(child.getResolvedLabel()) ;
57         w. write("</a>") ;
58         encodeNode(child, mimeType, w, baseURL);
59         w.write("</li>");
60       }
61     }
62     if (node.getChildrenSize() > 0) w.write("</ul>");
63   }
64 }
Popular Tags