01: package pygmy.nntp.http;
02:
03: import pygmy.nntp.NewsGroup;
04: import pygmy.core.HttpRequest;
05: import pygmy.core.UUID;
06:
07: import java.util.Iterator;
08: import java.util.ListIterator;
09: import java.io.IOException;
10:
11: public class TopicView extends View {
12: NewsGroup topic;
13: UUID startingMessage;
14: int displayLength;
15:
16: public TopicView(String urlPrefix, NewsGroup topic,
17: UUID startingMessage, int displayLength) {
18: super (urlPrefix);
19: this .topic = topic;
20: this .startingMessage = startingMessage;
21: this .displayLength = displayLength;
22: }
23:
24: public String render(HttpRequest request) throws IOException {
25: buffer.append("<div class=\"box2\">");
26: buffer
27: .append("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"3\" border=\"0\" >");
28:
29: String[] headings = new String[] { "Message", "Author",
30: "Replies", "Date" };
31: addNavigationBar(request, headings);
32: addTableHeaders(headings);
33:
34: addTopicTable(startingMessage, displayLength);
35: addNextAndPreviousButtons(startingMessage, headings.length);
36: buffer.append("</table>\n");
37: buffer.append("</div>\n");
38:
39: return buffer.toString();
40: }
41:
42: private void addTopicTable(UUID startMessage, int length) {
43: String[] styles = { "fileentry", "altfileentry" };
44: int count = 0;
45: // ListIterator i = topic.getTopicIterator( startMessage );
46: // for( ; i.hasNext() && count < length; count++ ) {
47: // ForumMessage message = (ForumMessage) i.next();
48: // addTableRow( styles[ count % 2] );
49: // addTableColumn( message.getSubject(), getForumUrl( message.getUrl() ), "left" );
50: // addTableColumn( message.getAuthor(), null );
51: // addTableColumn( String.valueOf( message.getThreadSize() ), null );
52: // addTableColumn( message.getPostDate().toString(), null );
53: // tableRowEnd();
54: // }
55: // return (i.hasNext()) ? ((ForumMessage)i.next()).getGuid() : null;
56: }
57:
58: private void addNavigationBar(HttpRequest request, String[] columns)
59: throws IOException {
60: buffer.append("<tr class=\"navigationbar\"><td colspan=\"");
61: buffer.append(columns.length);
62: buffer.append("\">");
63: buffer.append(createIcon(request.createUrl("/topic_icon.gif"),
64: 16, 16));
65: buffer.append("<b><font class=\"title\"> ");
66: // createWhiteLink( topic.getName(), getForumUrl( topic.getUrl() ) );
67: buffer.append("</font></b>\n</td>\n");
68: // buffer.append( "<td align=\"right\">" );
69: // createWhiteLink( "[back to fourms]", getForumUrl( "/" ) );
70: // buffer.append( "</td>\n" );
71: buffer.append("</tr>\n");
72: }
73:
74: private void addNextAndPreviousButtons(UUID startMessage, int span) {
75: // buffer.append( "<tr class=\"navigationbar\"><td align=\"right\" colspan=\"");
76: // buffer.append( span );
77: // buffer.append( "\"> " );
78: // try {
79: // createWhiteLink( "[Prev]", getForumUrl( topic.getPrevUrl( startMessage, displayLength ) ) );
80: // } catch( IndexOutOfBoundsException e ) {
81: // buffer.append( "[Prev]" );
82: // }
83: // buffer.append( " " );
84: // try {
85: // createWhiteLink( "[Next]", getForumUrl( topic.getNextUrl( startMessage, displayLength ) ) );
86: // } catch( IndexOutOfBoundsException e ) {
87: // buffer.append( "[Next]" );
88: // }
89: // buffer.append( "\n</td>\n" );
90: }
91:
92: }
|