/* Might be bad timing */
if (viewer == null)
return;
/* Ask for sorted Elements */
NewsBrowserLabelProvider labelProvider = (NewsBrowserLabelProvider) viewer.getLabelProvider();
Object[] children = new Object[0];
if (viewer instanceof NewsBrowserViewer) {
children = ((NewsBrowserViewer) viewer).getFlattendChildren(elements);
((NewsBrowserViewer) viewer).updateViewModel(children);
}
/* Write HTML to the Receiver */
BufferedWriter writer = null;
try {
boolean portable = Controller.getDefault().isPortable();
writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
if (Application.IS_WINDOWS && portable)
writer.append("HTTP/1.1 205 OK").append(CRLF); //$NON-NLS-1$
else
writer.append("HTTP/1.1 200 OK").append(CRLF); //$NON-NLS-1$
synchronized (RFC_1123_DATE) {
writer.append("Date: ").append(RFC_1123_DATE.format(new Date())).append(CRLF); //$NON-NLS-1$
}
writer.append("Server: RSSOwl Local Server").append(CRLF); //$NON-NLS-1$
writer.append("Content-Type: text/html; charset=UTF-8").append(CRLF); //$NON-NLS-1$
writer.append("Connection: close").append(CRLF); //$NON-NLS-1$
writer.append("Expires: 0").append(CRLF); //$NON-NLS-1$
writer.write(CRLF);
/* Begin HTML */
writer.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"); //$NON-NLS-1$
/* Windows only: Mark of the Web */
if (Application.IS_WINDOWS) {
writer.write(IE_MOTW);
writer.write("\n"); //$NON-NLS-1$
}
writer.write("<html>\n <head>\n"); //$NON-NLS-1$
/* Append Base URI if available */
String base = getBase(children);
if (base != null) {
writer.write(" <base href=\""); //$NON-NLS-1$
writer.write(base);
writer.write("\">"); //$NON-NLS-1$
}
writer.write("\n <title></title>"); //$NON-NLS-1$
writer.write("\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n"); //$NON-NLS-1$
/* CSS */
labelProvider.writeCSS(writer);
/* Open Body */
writer.write(" </head>\n <body id=\"owlbody\">\n"); //$NON-NLS-1$
/* Output each Element as HTML */
for (int i = 0; i < children.length; i++) {
String html = unicodeToEntities(labelProvider.getText(children[i], true, true, i));
writer.write(html);
}
/* End HTML */
writer.write("\n </body>\n</html>"); //$NON-NLS-1$