KickJava   Java API By Example, From Geeks To Geeks.

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


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

18 public class HorizontalMenuRenderer extends HtmlBasicRenderer {
19
20   final public static String JavaDoc LEFT_SELECTED_TAB =
21       "<img class='left-selected-tab' SRC='/skin/blank.gif'/>";
22   final public static String JavaDoc RIGHT_SELECTED_TAB =
23       "<img class='right-selected-tab' SRC='/skin/blank.gif'/>";
24   final public static String JavaDoc HOME_ICON = "<img class='home-icon' SRC='/skin/blank.gif' alt='Home'/>";
25
26   public void encodeChildren(FacesContext context, UIComponent component) throws IOException JavaDoc {
27     RequestInfo rinfo = (RequestInfo)SessionContainer.getComponent(RequestInfo.class);
28     String JavaDoc ownerURI = rinfo.getOwnerURI() ;
29     ResponseWriter w = context.getResponseWriter();
30     ExoPortal portal = (ExoPortal)SessionContainer.getComponent(ExoPortal.class) ;
31     Node root = portal.getRootNode();
32     w.write("<script>");
33     w.write("function _showmenu(id){");
34     w.write(" if (document.getElementById) {");
35     w.write(" document.getElementById(id).style.display=\"block\";");
36     w.write(" } else if (document.all) {");
37     w.write(" document.all[id].style.display=\"block\";");
38     w.write(" } else if (document.layers) {");
39     w.write(" document.layers[id].display=\"block\";");
40     w.write(" } }");
41
42     w.write("function _hidemenu(id){");
43     w.write(" if (document.getElementById) {");
44     w.write(" document.getElementById(id).style.display=\"none\";");
45     w.write(" } else if (document.all) {");
46     w.write(" document.all[id].style.display=\"none\";");
47     w.write(" } else if (document.layers) {");
48     w.write(" document.layers[id].display=\"none\";");
49     w.write(" } }");
50     w.write("</script>");
51
52     w.write("<div class='UIHorizontalMenu'>");
53     w. write("<dl class='home-dl'>");
54     w. write("<dt>");
55     w. write("<a HREF='"); w.write(ownerURI); w.write("/'>") ;
56     w. write(HOME_ICON) ;
57     w. write("</a>") ;
58     w.write(" </dt>");
59     w.write(" <dd/>");
60     w.write(" </dl>");
61     encodeNode(root, 2, w, ownerURI);
62     w.write("</div>");
63   }
64
65   public void encodeNode(Node root, int level, ResponseWriter w,
66                          String JavaDoc ownerURI)
67       throws IOException JavaDoc {
68     if (level > 0) {
69       for (int n = 0; n < root.getChildrenSize(); n++) {
70         Node node = root.getChild(n);
71         if(!node.isVisible()) continue ;
72         String JavaDoc jsName = "node_" + node.getUri().replace('/', '_');
73         w.write("<dl onmouseover=\"_showmenu('" + jsName + "');\" onmouseout=\"_hidemenu('" + jsName + "');\">");
74         if (node.isSelectedPath()) {
75           w. write("<dt>");
76           w. write("<span> ");
77           w. write(LEFT_SELECTED_TAB);
78           w. write("<a class='selected' HREF='"); w.write(ownerURI); w.write(node.getUri()); w.write("'>") ;
79           w. write(node.getResolvedLabel()) ;
80           w. write("</a>") ;
81           w. write(RIGHT_SELECTED_TAB);
82           w. write("</span>");
83         } else {
84           w.write(" <dt>");
85           w. write("<a HREF='"); w.write(ownerURI); w.write(node.getUri()); w.write("'>") ;
86           w. write(node.getResolvedLabel()) ;
87           w. write("</a>") ;
88         }
89         w.write(" </dt>");
90         w.write(" <dd id=\"" + jsName + "\" onmouseover=\"_showmenu('" + jsName +
91             "');\" onmouseout=\"_hidemenu('" + jsName + "');\">");
92         w.write(" <ul>");
93         for (int p = 0; p < node.getChildrenSize(); p++) {
94           Node child = node.getChild(p);
95           if(!child.isVisible()) continue ;
96           w. write("<li>");
97           w. write("<a HREF='"); w.write(ownerURI); w.write(child.getUri()); w.write("'>") ;
98           w. write(child.getResolvedLabel()) ;
99           w. write("</a>") ;
100           w. write("</li>");
101         }
102         w.write(" </ul>");
103         w.write(" </dd>");
104         w.write("</dl>");
105       }
106     }
107   }
108 }
Popular Tags