KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > communication > forum > renderer > html > TopicsRenderer


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.forum.renderer.html;
6
7 import java.io.IOException JavaDoc;
8 import java.util.ResourceBundle JavaDoc;
9 import javax.faces.component.UIComponent;
10 import javax.faces.context.ExternalContext;
11 import javax.faces.context.FacesContext;
12 import javax.faces.context.ResponseWriter;
13 import org.exoplatform.faces.core.component.model.PageListDataHandler;
14 import org.exoplatform.faces.core.component.model.Parameter;
15 import org.exoplatform.faces.core.renderer.html.HtmlBasicRenderer;
16 import org.exoplatform.portlets.communication.forum.component.UITopics;
17 import org.exoplatform.services.communication.forum.Topic;
18 /**
19  * @email: tuan08@users.sourceforge.net
20  * @version: $Id: TopicsRenderer.java,v 1.11 2004/10/20 18:46:31 benjmestrallet Exp $
21  */

22 public class TopicsRenderer extends HtmlBasicRenderer {
23
24   final public void encodeChildren( FacesContext context, UIComponent component ) throws IOException JavaDoc {
25     ResponseWriter w = context.getResponseWriter() ;
26     ExternalContext eContext = context.getExternalContext() ;
27     ResourceBundle JavaDoc res = getApplicationResourceBundle(eContext) ;
28     UITopics uiTopics = (UITopics) component ;
29         
30     w.write("<table width='100%'>") ;
31     w. write("<tr>");
32     w. write("<td>");
33     linkRenderer_.render(w,uiTopics, res.getString("UITopics.button.forum-index"), UITopics.viewForumsParams) ;
34     w. write("</td>");
35     w. write("<td align='right'>");
36     if(uiTopics.hasCreateTopicRole()) {
37       linkRenderer_.render(w,uiTopics, res.getString("UITopics.button.new-topic"), UITopics.newTopicParams) ;
38     }
39     w. write("</td>");
40     w. write("</tr>");
41     w.write("</table>") ;
42     addTopicsSection(context, w, res, uiTopics) ;
43     w.write("<table width='100%'>") ;
44     w. write("<tr>");
45     w. write("<td>");
46     linkRenderer_.render(w,uiTopics, res.getString("UITopics.button.forum-index"),
47                          UITopics.viewForumsParams) ;
48     w. write("</td>");
49     w. write("<td align='right'>");
50     if(uiTopics.getUser() != null) {
51       linkRenderer_.render(w,uiTopics, res.getString("UITopics.button.watch-forum"),
52                            UITopics.watchForumParams) ;
53       linkRenderer_.render(w,uiTopics, res.getString("UITopics.button.stop-watch-forum"),
54                            UITopics.stopWatchForumParams) ;
55     }
56     if(uiTopics.hasCreateTopicRole()) {
57       linkRenderer_.render(w,uiTopics, res.getString("UITopics.button.new-topic"), UITopics.newTopicParams) ;
58     }
59     w. write("</td>");
60     w. write("</tr>");
61     w.write("</table>") ;
62   }
63
64   private void addTopicsSection(FacesContext context, ResponseWriter w,
65                                 ResourceBundle JavaDoc res, UITopics uiTopics) throws IOException JavaDoc {
66     Parameter topicIdParam = new Parameter("topicId" , "");
67     Parameter[] viewTopicParams = { UITopics.VIEW_POSTS , topicIdParam} ;
68     Parameter[] deleteTopicParams = { UITopics.DELETE_TOPIC , topicIdParam} ;
69     Parameter[] watchTopicParams = { UITopics.watchTopicParam , topicIdParam} ;
70     Parameter[] stopWatchTopicParams = { UITopics.stopWatchTopicParam , topicIdParam} ;
71     String JavaDoc delButton = res.getString("UITopics.button.delete");
72     String JavaDoc watchTopicButton = res.getString("UITopics.button.watch-topic");
73     String JavaDoc stopWatchTopicButton = res.getString("UITopics.button.stop-watch-topic");
74     String JavaDoc topicIcon = res.getString("UITopics.img.topic-icon");
75     String JavaDoc guestUser = res.getString("UIPosts.label.guest-user") ;
76     PageListDataHandler dh = uiTopics.getUIPageIterator().getPageListDataHandler();
77     w.write("<table class='UITopics'>") ;
78     w. write("<tr>");
79     w. write("<th width='*' colspan='2'>");
80     w. write(res.getString("UITopics.header.topics"));
81     w. write("</th>");
82     w. write("<th width='75'>");
83     w. write(res.getString("UITopics.header.replies"));
84     w. write("</th>");
85     w. write("<th width='75'>");
86     w. write(res.getString("UITopics.header.author"));
87     w. write("</th>");
88     w. write("<th width='75'>");
89     w. write(res.getString("UITopics.header.views"));
90     w. write("</th>");
91     w. write("<th width='200'>");
92     w. write(res.getString("UITopics.header.last-post"));
93     w. write("</th>");
94     w. write("<th width='25'>"); w.write("-"); w.write("</th>");
95     w. write("</tr>");
96     dh.begin() ;
97     while(dh.nextRow()) {
98       Topic topic = (Topic) dh.getCurrentObject() ;
99       topicIdParam.setValue(topic.getId()) ;
100       String JavaDoc owner = topic.getOwner() ;
101       if(owner == null) owner = guestUser ;
102       String JavaDoc lastPostUser = topic.getLastPostBy() ;
103       if(lastPostUser == null) lastPostUser = guestUser ;
104       boolean hasNewPosts = uiTopics.hasNewPosts( topic );
105       w.write("<tr>");
106       w. write("<td width='40'>");
107         w.write(topicIcon);
108         if(hasNewPosts) {
109           w.write(res.getString("UITopics.img.newest-reply-icon"));
110         }
111       w.write("</td>");
112       w. write("<td style='text-align: left'>");
113       linkRenderer_.render(w,uiTopics
114               , hasNewPosts ? "<b>" + topic.getTopic() + "</b>" : topic.getTopic()
115               , viewTopicParams) ;
116       w. write("<br/>"); w.write(topic.getDescription()) ;
117       w. write("</td>");
118       w. write("<td>");w.write(Integer.toString(topic.getPostCount())); w.write("</td>");
119       w. write("<td>"); w.write(owner);w.write("</td>");
120       w. write("<td>"); w.write("N/A"); w.write("</td>");
121       w. write("<td>");
122       w. write(ft_.format(topic.getLastPostDate()));
123       w. write("<br/>");
124       w. write(lastPostUser);
125       w. write("</td>");
126       w. write("<td width='60' valign='middle'>");
127       if(uiTopics.getUser() != null) {
128         linkRenderer_.render(w,uiTopics, watchTopicButton, watchTopicParams) ;
129         linkRenderer_.render(w,uiTopics, stopWatchTopicButton, stopWatchTopicParams) ;
130       } else {
131         w.write(watchTopicButton);
132         w.write(stopWatchTopicButton);
133       }
134       if (uiTopics.isModerator()) {
135         linkRenderer_.render(w,uiTopics, delButton, deleteTopicParams) ;
136       }
137       w. write("</td>");
138       w.write("</tr>");
139     }
140     dh.end() ;
141     w. write("<tr>");
142     w. write("<td colspan='7' style='text-align: right;'>");
143     uiTopics.getUIPageIterator().encodeBegin(context) ;
144     w. write("</td>");
145     w. write("</tr>");
146     w.write("</table>");
147   }
148 }
Popular Tags