b761b886affdf0aab0005d97e40138f4ae4056ff
[pnews.git] / src / main / java / pnews / HTML.java
1 package pnews;
2
3 import java.util.List;
4
5 import com.rometools.rome.feed.synd.SyndEntry;
6 import com.rometools.rome.feed.synd.SyndFeed;
7
8 public class HTML {
9         private static void appendA(StringBuffer buf, String child, String href) {
10                 buf.append("<a href='");
11                 buf.append(href);
12                 buf.append("'>");
13                 buf.append(child);
14                 buf.append("</a>");
15         }
16         
17         private static void appendDiv(StringBuffer buf, String child) {
18                 buf.append("<div>");
19                 buf.append(child);
20                 buf.append("</div>\n");
21         }
22         
23         private static void append(StringBuffer buf, SyndEntry entry) {
24                 buf.append("<div>");
25                 appendA(buf, entry.getTitle(), entry.getLink());
26                 buf.append("</div>\n");
27                 
28                 appendDiv(buf, entry.getPublishedDate().toString());
29                 appendDiv(buf, entry.getDescription().getValue());
30         }
31         
32         public static void append(StringBuffer buf, SyndFeed feed) {
33                 for (SyndEntry e: feed.getEntries()) {
34                         append(buf, e);
35                 }
36         }
37         
38         public static String toHTML(List<SyndFeed> feeds) {
39                 StringBuffer buf;
40                 
41                 buf = new StringBuffer();
42                 buf.append("<!DOCTYPE html>\n");
43                 buf.append("<html>\n");
44                 buf.append("<head>\n");
45                 buf.append("<meta charset=\"UTF-8\">\n");
46                 buf.append("</head>\n");
47                 buf.append("<body>\n");
48                 
49                 for (SyndFeed e: feeds)
50                         append(buf, e);
51                 
52                 buf.append("</body>\n");
53                 buf.append("</html>\n");
54         
55                 return buf.toString();
56         }
57 }