KickJava   Java API By Example, From Geeks To Geeks.

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


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.portlets.nav.renderer.html;
6
7 import java.io.IOException JavaDoc;
8 import java.util.ResourceBundle JavaDoc;
9 import javax.faces.component.UIComponent;
10 import javax.faces.context.FacesContext;
11 import javax.faces.context.ResponseWriter;
12 import org.exoplatform.container.SessionContainer;
13 import org.exoplatform.portal.session.ExoPortal;
14 import org.exoplatform.portal.session.RequestInfo;
15 import org.exoplatform.portlets.nav.component.UIMenu;
16 import org.exoplatform.services.portal.model.Node;
17 import org.exoplatform.services.portal.model.PageReference;
18 /**
19  * Thu, May 5, 2004 @ 15:38
20  *
21  * @author: Tuan Nguyen
22  * @email: tuan08@users.sourceforge.net
23  * @version: $Id: ExoMenuTreeRenderer.java,v 1.2 2004/09/23 12:44:45 tuan08 Exp $
24  */

25 public class ExoMenuTreeRenderer extends ExoMenuRenderer {
26   public void encodeChildren(FacesContext context, UIComponent component) throws IOException JavaDoc {
27     UIMenu uiMenu = (UIMenu) component;
28     ResourceBundle JavaDoc res = getApplicationResourceBundle(context.getExternalContext()) ;
29     ResponseWriter w = context.getResponseWriter();
30     SessionContainer scontainer = SessionContainer.getInstance() ;
31     ExoPortal portal = (ExoPortal)scontainer.getComponentInstanceOfType(ExoPortal.class) ;
32     RequestInfo rinfo = (RequestInfo)scontainer.getComponentInstanceOfType(RequestInfo.class);
33     String JavaDoc ownerURI = rinfo.getOwnerURI() ;
34     String JavaDoc mimeType = uiMenu.getPreferedMimeType() ;
35     Node root = portal.getRootNode() ;
36     w.write("<a HREF='"); w.write(ownerURI); w.write("'>") ;
37     w. write("Home") ;
38     w.write("</a>") ;
39     w.write("<ul>");
40     for(int i = 0; i < root.getChildrenSize(); i++){
41       Node child = root.getChild(i);
42       PageReference pref = child.getPageReference(mimeType) ;
43       if(pref == null || pref.isVisible()) {
44         w.write("<li>");
45         w. write("<a HREF='"); w.write(ownerURI); w.write(child.getUri()); w.write("'>") ;
46         w. write(child.getResolvedLabel()) ;
47         w. write("</a>") ;
48         encodeNode(child,mimeType, w , ownerURI);
49         w.write("</li>");
50       }
51     }
52     w.write("</ul>");
53     renderAdmin(res, w, uiMenu);
54   }
55
56   public void encodeNode(Node node, String JavaDoc mimeType, ResponseWriter w, String JavaDoc ownerURI) throws IOException JavaDoc {
57     w.write("<ul>");
58     for (int n = 0; n < node.getChildrenSize(); n++) {
59       Node child = node.getChild(n);
60       PageReference pref = child.getPageReference(mimeType) ;
61       if(pref == null || pref.isVisible()) {
62         w.write("<li>");
63         w. write("<a HREF='"); w.write(ownerURI); w.write(child.getUri()); w.write("'>") ;
64         w. write(child.getResolvedLabel()) ;
65         w. write("</a>") ;
66         encodeNode(child, mimeType, w, ownerURI);
67         w.write("</li>");
68       }
69     }
70     w.write("</ul>");
71   }
72 }
Popular Tags