KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > console > renderer > html > AdminConsolePortletRenderer


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.console.renderer.html;
6
7 import java.util.List JavaDoc ;
8 import java.util.ResourceBundle JavaDoc ;
9 import java.io.IOException JavaDoc;
10 import javax.faces.component.UIComponent;
11 import javax.faces.context.FacesContext;
12 import javax.faces.context.ResponseWriter;
13 import org.exoplatform.faces.core.component.UINode ;
14 import org.exoplatform.faces.core.component.UIExoComponent ;
15 import org.exoplatform.faces.core.component.model.Parameter ;
16 import org.exoplatform.faces.core.renderer.html.HtmlBasicRenderer;
17 import org.exoplatform.portlets.console.component.UIAdminConsolePortlet;
18 /**
19  * Jul 29, 2004
20  * @author: Tuan Nguyen
21  * @email: tuan08@users.sourceforge.net
22  * @version: $Id$
23  */

24 public class AdminConsolePortletRenderer extends HtmlBasicRenderer {
25     public void encodeChildren( FacesContext context, UIComponent component ) throws IOException JavaDoc {
26     UIAdminConsolePortlet uiPortlet = (UIAdminConsolePortlet) component ;
27     ResourceBundle JavaDoc res = getApplicationResourceBundle(context.getExternalContext()) ;
28     ResponseWriter w = context.getResponseWriter() ;
29     Parameter componentIdParam = new Parameter(UIAdminConsolePortlet.COMPONENT_ID,"") ;
30     Parameter[] params = {UIAdminConsolePortlet.CHANGE_COMPONENT, componentIdParam} ;
31     w.write("<table class='UIAdminConsolePortlet'>") ;
32     w. write("<tr>");
33     w. write("<td class='header' colspan='2'>") ;
34     w. write(res.getString("UIAdminConsolePortlet.header.title"));
35     w. write("</td>");
36     w. write("</tr>");
37     w. write("<tr>");
38     w. write("<td class='navigation'>") ;
39     renderNavigation(w, uiPortlet, res, params) ;
40     w. write("</td>") ;
41     w. write("<td class='component'>") ;
42     renderChildren(context, uiPortlet) ;
43     w. write("</td>") ;
44     w. write("</tr>");
45     w. write("<tr>");
46     w. write("<td class='footer' colspan='2'>") ;
47     w. write("</td>");
48     w. write("</tr>");
49     w.write("</table>") ;
50     }
51   
52   private void renderNavigation(ResponseWriter w, UIAdminConsolePortlet uiPortlet,
53                                 ResourceBundle JavaDoc res, Parameter[] params ) throws IOException JavaDoc {
54     List JavaDoc children = uiPortlet.getChildren() ;
55     for(int i = 0; i < children.size() ; i++) {
56       Object JavaDoc obj = children.get(i) ;
57       if(obj instanceof UINode) {
58         UINode uiNode = (UINode) obj ;
59         renderNode(w, uiPortlet, uiNode, res, params) ;
60       } else {
61         UIExoComponent uiComponent = (UIExoComponent) obj ;
62         w.write("<ul>") ;
63         renderComponent(w, uiPortlet, uiComponent, res, params) ;
64         w.write("</ul>") ;
65       }
66     }
67   }
68   
69   
70   private void renderNode(ResponseWriter w, UIAdminConsolePortlet uiPortlet,
71                           UINode uiNode, ResourceBundle JavaDoc res, Parameter[] params ) throws IOException JavaDoc {
72     w.write("<ul>") ;
73     params[1].setValue(uiNode.getId()) ;
74     w.write("<li>") ;
75     linkRenderer_.render(w, uiPortlet, res.getString(uiNode.getName()), params) ;
76     if(uiNode.isRendered()) {
77       w.write("<ul>") ;
78       List JavaDoc children = uiNode.getChildren() ;
79       for(int i = 0; i < children.size() ; i++) {
80         UIExoComponent uiComponent = (UIExoComponent) children.get(i) ;
81         renderComponent(w, uiPortlet, uiComponent, res, params) ;
82       }
83       w.write("</ul>") ;
84     }
85     w.write("</li>") ;
86     w.write("</ul>") ;
87   }
88   
89   private void renderComponent(ResponseWriter w, UIAdminConsolePortlet uiPortlet,
90                                UIExoComponent uiComponent, ResourceBundle JavaDoc res, Parameter[] params) throws IOException JavaDoc {
91     w.write("<li>") ;
92     params[1].setValue(uiComponent.getId()) ;
93     linkRenderer_.render(w, uiPortlet, res.getString("UINode.label." + uiComponent.getId()), params) ;
94     w.write("</li>") ;
95   }
96 }
97
Popular Tags