KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > user > renderer > html > UserInfoRenderer


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.user.renderer.html;
6
7 import java.io.IOException JavaDoc;
8 import java.util.Iterator 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.exoplatform.faces.core.component.model.Parameter;
14 import org.exoplatform.faces.core.renderer.html.HtmlBasicRenderer;
15 import org.exoplatform.portlets.user.component.UIUserInfo;
16 import org.exoplatform.services.organization.Membership;
17 /**
18  * @email: tuan08@users.sourceforge.net
19  * @version: $Id: UserInfoRenderer.java,v 1.15 2004/10/21 15:25:17 tuan08 Exp $
20  */

21 public class UserInfoRenderer extends HtmlBasicRenderer {
22   private static Parameter DELETE_MEMBERSHIP = new Parameter(ACTION , "deleteMembership") ;
23   private static Parameter[] backParams = {new Parameter(ACTION , "back")} ;
24
25   final public void encodeBegin( FacesContext context, UIComponent component ) throws IOException JavaDoc {
26     ResourceBundle JavaDoc res = getApplicationResourceBundle(context.getExternalContext()) ;
27     ResponseWriter w = context.getResponseWriter() ;
28  
29     UIUserInfo uiUserInfo = (UIUserInfo) component ;
30     w.write("<table class='UIUserInfo'>");
31     w. write("<tr>");
32     w. write("<td class='form'>");
33     uiUserInfo.getUIAccountForm().encodeChildren(context) ;
34     w. write("</td>");
35     w. write("<td class='user-roles'>");
36     addUserRoleInfo(context, res, uiUserInfo) ;
37     w. write("</td>");
38     w. write("</tr>");
39     w. write("<tr>");
40     w. write("<td colspan='2' class='footer'>");
41     linkRenderer_.render(w,uiUserInfo, res.getString("UIUserInfo.button.back"), backParams) ;
42     w. write("</td>");
43     w. write("</tr>");
44     w.write("</table>");
45   }
46
47   private void addUserRoleInfo(FacesContext context,
48                                ResourceBundle JavaDoc res, UIUserInfo uiUserInfo) throws IOException JavaDoc {
49     ResponseWriter w = context.getResponseWriter() ;
50     Iterator JavaDoc memberships = uiUserInfo.getMemberships().iterator() ;
51     Parameter membershipIdParam = new Parameter("membershipId", "") ;
52     Parameter[] deleteMembershipParams = { DELETE_MEMBERSHIP , membershipIdParam } ;
53     w.write("<table>");
54     w. write("<tr>");
55     w. write("<th>");
56     w. write(res.getString("UIUserInfo.header.membership"));
57     w. write("</th>");
58     w. write("<th>");
59     w. write(res.getString("UIUserInfo.header.membership-type"));
60     w. write("</th>");
61     w. write("<th>");
62     w. write(res.getString("UIUserInfo.header.group-id"));
63     w. write("</th>");
64     w. write("<th>-</th>");
65     w. write("</tr>") ;
66     int i = 0;
67     while (memberships.hasNext()) {
68       Membership membership = (Membership) memberships.next();
69       String JavaDoc clazz = "odd";
70       if (i % 2 == 0) clazz = "even";
71       w.write("<tr class='" + clazz + "'>") ;
72       w. write("<td>") ; w.write("Membership") ; w.write("</td>") ;
73       w. write("</td>"); w.write("<td>"); w.write(membership.getMembershipType()); w.write("</td>") ;
74       w. write("<td>") ; w.write(membership.getGroupId()) ; w.write("</td>") ;
75       if(uiUserInfo.hasAdminRole()) {
76         w.write("<td>");
77         membershipIdParam.setValue(membership.getId()) ;
78         linkRenderer_.render(w, uiUserInfo, res.getString("UIUserInfo.button.delete"), deleteMembershipParams) ;
79         w.write("</td>");
80       } else {
81         w.write("<td> - </td>");
82       }
83       w.write("</tr>") ;
84       i++;
85     }
86     w. write("</tr>");
87     w. write("<tr>");
88     w. write("<td class='form' colspan='4'>");
89     uiUserInfo.getUIMembershipForm().encodeChildren(context) ;
90     w. write("</td>");
91     w. write("</tr>");
92     w.write("</table>");
93   }
94 }
Popular Tags