}
- public static void appendHTMLFooter(StringBuffer sb) {
- sb.append("</body>\n");
- sb.append("</html>");
+ private void appendHTMLFooter(StringBuffer sb) throws IOException {
+ sb.append(new String(Files.readAllBytes(config.getHTMLFooterFile().toPath()),
+ StandardCharsets.UTF_8));
+ appendEndTag(sb, "body", 1, true);
+ appendEndTag(sb, "html", 0, false);
}
public String toHTML(SyndEntry entry) throws IOException {
return buf.toString();
}
+ private static void appendStartTag(StringBuffer buf, String tag, int indent, boolean newline) {
+ while (indent > 0) {
+ buf.append('\t');
+ indent--;
+ }
+ buf.append('<');
+ buf.append(tag);
+ buf.append(">");
+
+ if (newline)
+ buf.append('\n');
+ }
+
+ private static void appendEndTag(StringBuffer buf, String tag, int indent, boolean newline) {
+ while (indent > 0) {
+ buf.append('\t');
+ indent--;
+ }
+ buf.append("</");
+ buf.append(tag);
+ buf.append(">");
+
+ if (newline)
+ buf.append('\n');
+ }
+
public String toHTML(Collection<SyndEntry> entries) throws IOException {
StringBuffer buf;
List<SyndEntry> sortedEntries;
appendHTMLHead(buf, config.getFeedTitle());
- buf.append("<body>\n");
+ appendStartTag(buf, "body", 1, true);
appendHTMLContentHeader(buf, config.getFeedTitle());
Collections.sort(sortedEntries, cmp);
for(SyndEntry e: sortedEntries) {
- buf.append("\n<div>");
- buf.append("<h2>");
+ appendStartTag(buf, "article", 3, true);
+ appendStartTag(buf, "header", 4, true);
+ appendStartTag(buf, "h1", 5, false);
buf.append("<a href='" + e.getUri() + "'>");
buf.append(e.getTitle());
- buf.append("</a></h2>");
+ buf.append("</a>");
+ appendEndTag(buf, "h1", 0, true);
+
if (e.getPublishedDate() != null) {
- buf.append("<div class='date'>");
- buf.append(DATE_FORMATTER.format(e.getPublishedDate()));
- buf.append("</div>");
+ buf.append("<div class='date'>");
+ buf.append(DATE_FORMATTER.format(e.getPublishedDate()));
+ buf.append("</div>\n");
}
+
+ appendEndTag(buf, "header", 4, true);
+
buf.append(e.getDescription().getValue());
- buf.append("</div>\n");
+
+ appendEndTag(buf, "article", 3, true);
}
buf.append("</div>\n");
- HTML.appendHTMLFooter(buf);
+ appendHTMLFooter(buf);
return buf.toString();
}