001: package pygmy.nntp.http;
002:
003: import pygmy.core.HttpRequest;
004:
005: import java.io.IOException;
006:
007: public abstract class View {
008: StringBuffer buffer = new StringBuffer();
009: String urlPrefix;
010:
011: public View(String urlPrefix) {
012: this .urlPrefix = urlPrefix;
013: }
014:
015: public abstract String render(HttpRequest request)
016: throws IOException;
017:
018: protected String getForumUrl(String relativeUrl) {
019: return urlPrefix + relativeUrl;
020: }
021:
022: protected void createLink(String text, String url, String clazz) {
023: buffer.append("<a href=\"");
024: buffer.append(url);
025: buffer.append("\"");
026: if (clazz != null) {
027: buffer.append(" class=\"");
028: buffer.append(clazz);
029: buffer.append("\"");
030: }
031: buffer.append(">");
032: buffer.append(text);
033: buffer.append("</a>\n");
034: }
035:
036: protected void createWhiteLink(String text, String url) {
037: createLink(text, url, "whitelink");
038: }
039:
040: protected void addTableHeaders(String[] headers) {
041: buffer.append("<tr class=\"tableheader\">\n");
042: for (int i = 0; i < headers.length; i++) {
043: buffer.append("<td align=\"center\">");
044: buffer.append(headers[i]);
045: buffer.append("</td>\n");
046: }
047: buffer.append("</tr>\n");
048: }
049:
050: protected void addTableColumn(String text, String url) {
051: addTableColumn(text, url, "center");
052: }
053:
054: protected void addTableColumnOptions(String text, String url,
055: String options) {
056: buffer.append("\n<td ");
057: buffer.append(options);
058: buffer.append("> <small>");
059: if (url != null) {
060: createLink(text, url, null);
061: } else {
062: buffer.append(text);
063: }
064: buffer.append("</small></td>\n");
065: }
066:
067: protected void addTableColumn(String text, String url,
068: String alignment) {
069: addTableColumnOptions(text, url, "align=\"" + alignment + "\"");
070: }
071:
072: protected void addTableRow(String rowStyle) {
073: buffer.append("<tr class=\"");
074: buffer.append(rowStyle);
075: buffer.append("\">\n");
076: }
077:
078: protected void addTableRow(String rowStyle, int colspan) {
079: buffer.append("<tr class=\"");
080: buffer.append(rowStyle);
081: buffer.append("\" colspan=\"");
082: buffer.append(colspan);
083: buffer.append("\">\n");
084: }
085:
086: protected void tableRowEnd() {
087: buffer.append("</tr>\n");
088: }
089:
090: protected void createTextField(String name, String defaultValue,
091: int size) {
092: buffer.append("<input type=\"text\" name=\"");
093: buffer.append(name);
094: buffer.append("\" size=\"");
095: buffer.append(size);
096: buffer.append("\" ");
097: if (defaultValue != null) {
098: buffer.append("value=\"");
099: buffer.append(defaultValue);
100: buffer.append("\"");
101: }
102: buffer.append(">");
103: }
104:
105: protected void createHiddenField(String name, Object value) {
106: buffer.append("<input type=\"hidden\" name=\"");
107: buffer.append(name);
108: buffer.append("\" value=\"");
109: buffer.append(value.toString());
110: buffer.append("\">");
111: }
112:
113: protected String createIcon(String iconUrl, int width, int height) {
114: StringBuffer buf = new StringBuffer("<img src=\"");
115: buf.append(iconUrl);
116: buf.append("\" width=\"");
117: buf.append(width);
118: buf.append("\" height=\"");
119: buf.append(height);
120: buf.append("\" border=\"0\">");
121: return buf.toString();
122: }
123:
124: }
|