KickJava   Java API By Example, From Geeks To Geeks.

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


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.FacesConstants;
9 import org.exoplatform.faces.core.component.model.Parameter;
10 import org.exoplatform.faces.core.renderer.html.HtmlBasicRenderer;
11 import org.exoplatform.faces.user.component.UILanguageSelector;
12 import org.exoplatform.portal.session.ExoPortal;
13 import org.exoplatform.portlets.nav.component.UIBreadcrumbs;
14 import org.exoplatform.services.portal.model.Node;
15 /**
16  *
17  * @version $Revision: 1.1.1.1 $ $Date: 2004/08/05 13:11:13 $
18  * @author Fahrid Djebbari
19  *
20  */

21 public class BreadcrumbsRenderer extends HtmlBasicRenderer {
22   private static Parameter CHANGE_NODE = new Parameter(FacesConstants.ACTION,
23       "changeNode");
24
25   public void encodeBegin(FacesContext context, UIComponent component)
26       throws IOException JavaDoc {
27   }
28
29   public void encodeChildren(FacesContext context, UIComponent component) throws IOException JavaDoc {
30     UIBreadcrumbs breadcrumbs = (UIBreadcrumbs) component;
31     ExoPortal portal = (ExoPortal)SessionContainer.getComponent(ExoPortal.class) ;
32
33     ResponseWriter writer = context.getResponseWriter();
34
35     String JavaDoc baseURL = breadcrumbs.getBaseURL(context);
36     Node selectedNode = portal.getSelectedNode();
37
38     writer.write("<div class='UIBreadcrumbs'>");
39     writer.write("<div>");
40     this.encodeNode(portal.getRootNode(), selectedNode, baseURL, writer);
41     writer.write("</div>");
42     writer.write("<div class='flags'>");
43     UILanguageSelector languageSelector = (UILanguageSelector) breadcrumbs.getChildren().get(0);
44     languageSelector.encodeBegin(context);
45     languageSelector.encodeChildren(context);
46     languageSelector.encodeEnd(context);
47     writer.write("</div>");
48     writer.write("</div>");
49   }
50
51   private void encodeNode(Node node, Node selectedNode, String JavaDoc baseURL,
52       ResponseWriter writer) throws IOException JavaDoc {
53     writer.write("<span>");//class='UIBreadcrumbs'
54

55     if (node == selectedNode) {
56       writer.write(node.getResolvedLabel());
57     } else {
58       Parameter nodeUriParam = new Parameter("uri", "");
59       Parameter[] changeNodeParams = { CHANGE_NODE, nodeUriParam };
60       nodeUriParam.setValue(node.getUri());
61       appendLink(writer, node.getResolvedLabel(), baseURL, changeNodeParams, "");
62     }
63     writer.write("</span>");
64     for (int i = 0; i < node.getChildrenSize(); i++) {
65       Node child = node.getChild(i);
66       if (selectedNode.getUri().startsWith(child.getUri())) {
67         writer.write("<span>&nbsp;>&nbsp;</span>");
68         this.encodeNode(child, selectedNode, baseURL, writer);
69       }
70     }
71   }
72
73   public void encodeEnd(FacesContext context, UIComponent component)
74       throws IOException JavaDoc {
75   }
76 }
Popular Tags