1 5 package org.exoplatform.portlets.user.renderer.html; 6 7 import java.util.* ; 8 import java.util.ResourceBundle ; 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 ; 17 18 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 { 27 ResourceBundle res = getApplicationResourceBundle(context.getExternalContext()) ; 28 ResponseWriter w = context.getResponseWriter() ; 29 UIUserProfileSummary uiUserProfile = (UIUserProfileSummary) component ; 30 Map userInfo = uiUserProfile.getUserInfoMap() ; 31 String 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 avatarURL = (String )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 res, Map userInfo, 61 String titleKey, String [] keys) throws IOException { 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 ) userInfo.get(keys[i])));w.write("</td>"); 74 w.write("</tr>"); 75 } 76 w.write("</table>") ; 77 } 78 } | Popular Tags |