KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > content > explorer > renderer > html > ExplorerRenderer


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.content.explorer.renderer.html;
6
7 import java.io.IOException JavaDoc;
8 import java.util.List JavaDoc;
9 import java.util.ResourceBundle JavaDoc;
10 import javax.faces.component.UIComponent;
11 import javax.faces.context.FacesContext;
12 import javax.faces.context.ResponseWriter;
13 import org.apache.commons.lang.StringUtils;
14 import org.exoplatform.faces.core.component.model.Parameter;
15 import org.exoplatform.faces.core.renderer.html.HtmlBasicRenderer;
16 import org.exoplatform.portlets.content.explorer.component.UIExplorer;
17 import org.exoplatform.portlets.content.explorer.component.model.NodeDescriptor;
18 /**
19  * @email: tuan08@users.sourceforge.net
20  * @version: $Id: ExplorerRenderer.java,v 1.3 2004/09/05 22:06:15 tuan08 Exp $
21  */

22 public class ExplorerRenderer extends HtmlBasicRenderer {
23   private static Parameter CHANGE_NODE = new Parameter(ACTION , UIExplorer.CHANGE_NODE_ACTION) ;
24
25   public void encodeChildren( FacesContext context, UIComponent component ) throws IOException JavaDoc {
26     UIExplorer uiExplorer = (UIExplorer) component;
27     ResourceBundle JavaDoc res = getApplicationResourceBundle(context.getExternalContext()) ;
28     String JavaDoc currentUri = uiExplorer.getSelectNode().getUri() ;
29     String JavaDoc[] path = StringUtils.split(currentUri, "/") ;
30     if(path.length == 0) {
31       path = new String JavaDoc[0] ;
32     }
33     String JavaDoc currentPath = "" ;
34     Parameter uriParam = new Parameter("uri", "/") ;
35     Parameter[] changeNodeParams = { CHANGE_NODE , uriParam} ;
36     ResponseWriter w = context.getResponseWriter() ;
37     //render header
38
w.write("<table class='UIExplorer'>");
39     w. write("<tr>");
40     w. write("<td class='header' colspan='2'>") ;
41     linkRenderer_.render(w, uiExplorer, "/", changeNodeParams) ;
42     String JavaDoc pathSeparator = res.getString("UIExplorer.img.path-separator") ;
43     for (int i = 0; i < path.length; i++) {
44       currentPath += "/" + path[i] ;
45       uriParam.setValue(currentPath) ;
46       w.write("<img SRC='"); w.write(pathSeparator) ; w.write("'/>") ;
47       linkRenderer_.render(w,uiExplorer, path[i], changeNodeParams) ;
48     }
49     w. write("</td>") ;
50     w. write("</tr>");
51     //render body
52
w. write("<tr>");
53     w. write("<td class='tree'>") ;
54     renderNodeTree(w, uiExplorer) ;
55     w. write("</td>");
56     w. write("<td>") ;
57     renderChildren(context, component) ;
58     w. write("</td>");
59     w. write("</tr>");
60     w.write("</table>");
61   }
62   
63   final public void renderNodeTree(ResponseWriter w, UIExplorer uiExplorer) throws IOException JavaDoc {
64     NodeDescriptor node = uiExplorer.getSelectNode() ;
65     Parameter uriParam = new Parameter("uri", "../") ;
66     Parameter[] changeNodeParams = { CHANGE_NODE , uriParam} ;
67     w.write("<div>") ;
68     linkRenderer_.render(w, uiExplorer, "[..]", changeNodeParams) ;
69     w.write("</div>") ;
70     List JavaDoc children = node.getChildren() ;
71     for (int i = 0; i < children.size(); i++) {
72       NodeDescriptor childNode = (NodeDescriptor) children.get(i) ;
73       if (!childNode.isLeafNode()) {
74         uriParam.setValue(childNode.getUri()) ;
75         w.write("<div style='padding: 2px'>") ;
76         w.write(childNode.getIcon()) ;
77         linkRenderer_.render(w,uiExplorer, childNode.getName(), changeNodeParams) ;
78         w.write("</div>") ;
79       }
80     }
81   }
82 }
Popular Tags