KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > communication > message > renderer > html > MessagesRenderer


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.communication.message.renderer.html;
6
7 import java.io.IOException JavaDoc;
8 import java.util.*;
9 import javax.faces.component.UIComponent;
10 import javax.faces.context.FacesContext;
11 import javax.faces.context.ResponseWriter;
12 import org.exoplatform.faces.core.component.model.Parameter;
13 import org.exoplatform.faces.core.renderer.html.*;
14 import org.exoplatform.portlets.communication.message.component.*;
15 import org.exoplatform.services.communication.message.*;
16 /**
17  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
18  * @since Aug 27, 2004
19  * @version $Id: MessagesRenderer.java,v 1.3 2004/11/03 04:24:55 tuan08 Exp $
20  */

21 public class MessagesRenderer extends HtmlBasicRenderer {
22   
23   public MessagesRenderer() {
24     buttonRenderer_ = new ThreeImagePatternButton("ic3-button", "ic3-select-button") ;
25   }
26   
27   public void encodeChildren(FacesContext context, UIComponent component) throws IOException JavaDoc {
28     UIMessages uiFolder = (UIMessages) component;
29     ResponseWriter w = context.getResponseWriter();
30     ResourceBundle res = getApplicationResourceBundle(context.getExternalContext());
31     w.write("<table class='UIMessageFolder'>");
32     w. write("<tr>");
33     w. write("<th>");
34     w. write(res.getString("UIMessages.header.icon"));
35     w. write("</th>");
36     w. write("<th>"); w.write(res.getString("UIMessages.header.subject")); w.write("</th>");
37     w. write("<th>"); w.write(res.getString("UIMessages.header.from")); w.write("</th>");
38     w. write("<th>"); w.write(res.getString("UIMessages.header.date")); w.write("</th>");
39     w. write("</tr>");
40     List messages = uiFolder.getMessages();
41     Parameter messageIdParam = new Parameter(UIMessages.MESSAGE_ID, "");
42     Parameter[] viewMessageParams = { UIMessages.viewMessageParam_, messageIdParam };
43     if (messages.size() == 0) {
44       w.write("<tr>");
45       w. write("<td colspan='4'>");
46       w. write(res.getString("UIMessages.label.no-message"));
47       w. write("</td>");
48       w.write("</tr>");
49     } else {
50       for (int i = 0; i < messages.size(); i++) {
51         Message message = (Message) messages.get(i);
52         String JavaDoc subject = message.getSubject();
53         if (subject == null || subject.length() == 0)
54           subject = "No Subject";
55         messageIdParam.setValue(message.getId());
56         if(message.isNew())
57           w.write("<tr class='new'>");
58         else
59           w.write("<tr class='read'>");
60           
61         w.write("<td>"); w.write(resolveIcon(res, message)); w.write("</td>");
62         w.write("<td class='subject'>");
63         linkRenderer_.render(w, uiFolder, subject, viewMessageParams);
64         w.write("</td>");
65
66         w.write("<td>"); w.write(ft_.format(message.getFrom())); w.write("</td>");
67
68         w.write("<td>"); w.write(ft_.format(message.getReceivedDate())); w.write("</td>");
69         w.write("</tr>");
70
71       }
72     }
73     w.write("<tr>");
74     w. write("<td colspan='4' class='footer'>");
75     renderChildren(context, component) ;
76     w. write("</td>");
77     w.write("</tr>");
78     w.write("</table>");
79   }
80
81   private String JavaDoc resolveIcon(ResourceBundle res, Message message) {
82     String JavaDoc icon = "";
83     if(message.isNew()){
84       icon = res.getString("UIMessages.icon.new");
85     }else {
86       icon = res.getString("UIMessages.icon.read");
87     }
88     return icon;
89   }
90 }
Popular Tags