01: package pygmy.nntp.http;
02:
03: import pygmy.core.HttpRequest;
04:
05: import java.io.IOException;
06: import java.util.StringTokenizer;
07:
08: import pygmy.nntp.NewsGroup;
09:
10: public class MessageView extends View {
11: NewsGroup topic;
12: ForumMessage message;
13:
14: public MessageView(String urlPrefix, NewsGroup topic,
15: ForumMessage message) {
16: super (urlPrefix);
17: this .topic = topic;
18: this .message = message;
19: }
20:
21: public String render(HttpRequest request) throws IOException {
22: renderMessage();
23: return buffer.toString();
24: }
25:
26: private void renderMessage() {
27: buffer.append("<div class=\"box2\">");
28: buffer
29: .append("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"3\" border=\"0\" >\n");
30: startMessage();
31: addMessageHeader();
32: addMessageContents();
33: buffer.append("</table>\n");
34: buffer.append("</div>\n");
35: }
36:
37: private void startMessage() {
38: addTableRow("navigationbar");
39: buffer.append("\n<td nowrap align=\"left\">");
40: buffer.append("<font size=\"+1\" class=\"title\">");
41: buffer.append(message.getSubject());
42: buffer.append("</font>");
43: buffer.append("</td>\n");
44: tableRowEnd();
45: }
46:
47: private void addMessageHeader() {
48: addTableRow("tableheader");
49: buffer.append("<td>");
50: buffer.append("<b>Author:</b> ");
51: buffer.append(message.getAuthor());
52: buffer.append("</br>");
53: buffer.append("<b>Date:</b> ");
54: buffer.append(message.getPostDate());
55: buffer.append("</br>");
56: buffer.append("</td>");
57: tableRowEnd();
58: }
59:
60: private void addMessageContents() {
61: addTableRow("fileentry");
62: buffer.append("<td width=\"100%\" cellpadding=\"5\">");
63: buffer.append("<br>");
64: buffer.append(renderContents(message.getContents()));
65: buffer.append("</td>\n");
66: tableRowEnd();
67: }
68:
69: private String renderContents(String contents) {
70: StringBuffer buffer = new StringBuffer();
71: StringTokenizer tokenizer = new StringTokenizer(contents,
72: "\n\r");
73: while (tokenizer.hasMoreTokens()) {
74: buffer.append(tokenizer.nextToken());
75: buffer.append("<p>");
76: }
77:
78: return buffer.toString();
79: }
80:
81: }
|