01: package pygmy.nntp.http;
02:
03: import pygmy.nntp.NewsGroup;
04: import pygmy.nntp.http.View;
05:
06: import java.util.Iterator;
07: import java.io.IOException;
08:
09: import pygmy.core.HttpRequest;
10:
11: public class ThreadMapView extends View {
12:
13: NewsGroup topic;
14: ForumMessage message;
15:
16: public ThreadMapView(String urlPrefix, NewsGroup topic,
17: ForumMessage message) {
18: super (urlPrefix);
19: this .topic = topic;
20: this .message = message;
21: }
22:
23: public String render(HttpRequest request) throws IOException {
24: addThreadSummary();
25: return buffer.toString();
26: }
27:
28: private void addThreadSummary() {
29: // buffer.append("<p><p>\n<table width=\"100%\" cellspacing=\"0\" cellpadding=\"1\" border=\"0\" bgcolor=\"#000000\">\n<tr>\n<td>\n<table width=\"100%\" cellspacing=\"0\" cellpadding=\"3\" border=\"0\" >\n");
30: // addTableRow( "navigationbar" );
31: // buffer.append("<td align=\"left\"><font class=\"title\">Threads</font></td>\n");
32: // tableRowEnd();
33: // addTableRow("fileentry");
34: buffer.append("<div class=\"box\">\n");
35: buffer.append("<h5>Threads</h5>\n");
36: buffer.append("<div class=\"body\">\n");
37: ForumMessage parent = getRootMessage(message);
38: renderThreadTree(parent, 0);
39: buffer.append("</div>\n");
40: buffer.append("</div>\n");
41: // tableRowEnd();
42: // buffer.append( "</table></td></tr></table>\n");
43: }
44:
45: private ForumMessage getRootMessage(ForumMessage aMessage) {
46: ForumMessage parent = aMessage;
47: while (parent.isReply()) {
48: // parent = topic.getMessage( parent.getParentGuid() );
49: }
50: return parent;
51: }
52:
53: private void renderThreadTree(ForumMessage parent, int indention) {
54: String clazz = "even";
55: if (parent.equals(message)) {
56: clazz = "selected";
57: }
58: buffer.append("<div class=\"");
59: buffer.append(clazz);
60: buffer.append("\">");
61:
62: for (int i = 0; i < indention; i++) {
63: buffer.append(" ");
64: }
65: createLink(parent.getSubject(), getForumUrl(parent.getUrl()),
66: null);
67: buffer.append("<br>");
68: for (int i = 0; i < indention; i++) {
69: buffer.append(" ");
70: }
71: buffer.append("<small>Posted by ");
72: buffer.append(message.getAuthor());
73: buffer.append(" on ");
74: buffer.append(message.getPostDate());
75: buffer.append("</small>\n");
76: buffer.append("</div>\n");
77:
78: for (Iterator i = parent.threadIterator(); i.hasNext();) {
79: renderThreadTree((ForumMessage) i.next(), indention + 5);
80: }
81: }
82: }
|