KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.faces.component.UIComponent;
9 import javax.faces.context.FacesContext;
10 import javax.faces.context.ResponseWriter;
11 import org.exoplatform.container.SessionContainer;
12 import org.exoplatform.faces.core.component.UIExoComponent;
13 import org.exoplatform.faces.core.component.model.Parameter;
14 import org.exoplatform.faces.core.renderer.html.HtmlBasicRenderer;
15 import org.exoplatform.portal.session.ExoPortal;
16 import org.exoplatform.portlets.nav.component.UIFirstLevelMenu;
17 import org.exoplatform.portlets.nav.component.UINavigation;
18 import org.exoplatform.services.portal.model.Node;
19
20 /**
21  * Created y the eXo platform team
22  * User: Benjamin Mestrallet
23  * Date: 6 sept. 2004
24  */

25 public class FirstLevelMenuRenderer extends HtmlBasicRenderer {
26   final static protected Parameter LOGOUT = new Parameter(ACTION, UIFirstLevelMenu.LOGOUT_ACTION);
27
28   public void encodeChildren(FacesContext context, UIComponent uiComponent) throws IOException JavaDoc {
29     UIFirstLevelMenu uiMenu = (UIFirstLevelMenu) uiComponent;
30     ResponseWriter w = context.getResponseWriter();
31     ExoPortal portal = (ExoPortal)SessionContainer.getComponent(ExoPortal.class) ;
32     Node rootNode = portal.getRootNode();
33     w.write("<div class='UIFirstLevelMenu'>");
34     w.write("<div class='" + rootNode.getName() + "'>");
35     Parameter nodeUriParam = new Parameter("uri", rootNode.getUri());
36     Parameter[] changeToRootNodeParams = {UINavigation.CHANGE_NODE, nodeUriParam};
37     render(w, uiMenu, rootNode.getResolvedLabel(), changeToRootNodeParams);
38     w.write("</div>");
39     for (int i = 0; i < rootNode.getChildrenSize(); i++) {
40       Node node = rootNode.getChild(i);
41       nodeUriParam = new Parameter("uri", node.getUri());
42       Parameter[] changeNodeParams = {UINavigation.CHANGE_NODE, nodeUriParam};
43       w.write("<div class='" + node.getName() + "'>");
44       render(w, uiMenu, node.getResolvedLabel(), changeNodeParams);
45       w.write("</div>");
46     }
47     if (context.getExternalContext().getRemoteUser() != null) {
48       w.write("<div class='logout'>");
49       Parameter[] logout = {LOGOUT};
50       render(w, uiMenu, "logout", logout);
51       w.write("</div>");
52     }
53     w.write("</div>");
54   }
55
56   private void render(ResponseWriter w, UIExoComponent component, String JavaDoc text, Parameter[] params)
57       throws IOException JavaDoc {
58     w.write("<a");
59     w.write(" HREF='");
60     w.write(component.getBaseURL());
61     for (int i = 0; i < params.length; i++) {
62       w.write("&amp;");
63       w.write(params[i].getName());
64       w.write('=');
65       w.write(params[i].getValue());
66     }
67     w.write("'");
68     w.write(">");
69     w.write("<span>");
70     w.write(text);
71     w.write("</span>");
72     w.write("</a>");
73   }
74 }
Popular Tags