KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.* ;
8 import java.util.ResourceBundle JavaDoc ;
9 import javax.faces.component.UIComponent;
10 import javax.faces.context.FacesContext;
11 import javax.faces.context.ResponseWriter;
12 import org.exoplatform.commons.utils.Formater;
13 import org.exoplatform.faces.core.component.model.*;
14 import org.exoplatform.faces.core.renderer.html.HtmlBasicRenderer;
15 import org.exoplatform.portlets.user.component.UIUserProfileSummary;
16 import java.io.IOException JavaDoc;
17
18 /**
19  * @email: tuan08@users.sourceforge.net
20  * @version: $Id: UserProfileRenderer.java,v 1.8 2004/07/22 17:08:18 tuan08 Exp $
21  */

22 public class UserProfileRenderer extends HtmlBasicRenderer {
23   private static Parameter[] backParams = { new Parameter(ACTION , BACK_ACTION)} ;
24   static private Formater ft_ = Formater.getFormater(null) ;
25    
26   final public void encodeBegin( FacesContext context, UIComponent component ) throws IOException JavaDoc {
27     ResourceBundle JavaDoc res = getApplicationResourceBundle(context.getExternalContext()) ;
28     ResponseWriter w = context.getResponseWriter() ;
29     UIUserProfileSummary uiUserProfile = (UIUserProfileSummary) component ;
30     Map userInfo = uiUserProfile.getUserInfoMap() ;
31     String JavaDoc title = res.getString("UIUserProfile.header.viewing-user-info") ;
32     w.write("<table class='UIUserProfile'>");
33     w. write("<tr>");
34     w. write("<th colspan='2' class='header'>");
35     w. write(title);
36     w. write("</th>");
37     w. write("</tr>");
38     w. write("<tr>");
39     w. write("<td width='50%'>");
40     addSection(w, res, userInfo, "UIUserProfile.header.personal-info", UIUserProfileSummary.PERSONAL_INFO_KEYS) ;
41     addSection(w, res, userInfo, "UIUserProfile.header.user-home-info", UIUserProfileSummary.HOME_INFO_KEYS) ;
42     addSection(w, res, userInfo, "UIUserProfile.header.user-businese-info", UIUserProfileSummary.BUSINESE_INFO_KEYS) ;
43     w. write("</td>");
44     w. write("<td class='avatar'>");
45     String JavaDoc avatarURL = (String JavaDoc)userInfo.get("user.other-info.avatar.url") ;
46     if(avatarURL == null) avatarURL = "/user/images/no_pic.gif" ;
47     w. write("<img SRC='");w.write(avatarURL); w.write("'/>") ;
48     w. write("</td>");
49     w. write("</tr>");
50     w.write("<tr>");
51     w. write("<td class='footer' colspan='2'>");
52     if(uiUserProfile.showBackButton()) {
53       linkRenderer_.render(w,uiUserProfile, res.getString("UIUserProfile.button.back"),backParams) ;
54     }
55     w. write("</td>");
56     w.write("</tr>");
57     w.write("</table>");
58   }
59
60   private void addSection(ResponseWriter w, ResourceBundle JavaDoc res, Map userInfo,
61                           String JavaDoc titleKey, String JavaDoc[] keys) throws IOException JavaDoc {
62     w.write("<table class='section'>");
63     w. write("<tr>");
64     w. write("<th colspan='2'>"); w.write(res.getString(titleKey)); w.write("</th>") ;
65     w. write("</tr>") ;
66     for (int i = 0 ; i < keys.length; i++) {
67       if (i % 2 == 0) {
68         w.write("<tr class='even'>");
69       } else {
70         w.write("<tr class='odd'>");
71       }
72       w. write("<td class='label'>");w.write(res.getString(keys[i])) ;w.write("</td>");
73       w. write("<td>");w.write(ft_.format((String JavaDoc) userInfo.get(keys[i])));w.write("</td>");
74       w.write("</tr>");
75     }
76     w.write("</table>") ;
77   }
78 }
Popular Tags