1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.sun.syndication.io.impl;
18
19 import com.sun.syndication.feed.rss.Category;
20 import com.sun.syndication.feed.rss.Channel;
21 import com.sun.syndication.feed.rss.Guid;
22 import com.sun.syndication.feed.rss.Item;
23 import org.jdom.Element;
24
25 import java.util.List;
26
27
28
29
30
31
32
33
34
35
36 public class RSS20Generator extends RSS094Generator {
37
38 public RSS20Generator() {
39 this("rss_2.0","2.0");
40 }
41
42 protected RSS20Generator(String feedType,String version) {
43 super(feedType,version);
44 }
45
46 protected void populateChannel(Channel channel,Element eChannel) {
47 super.populateChannel(channel,eChannel);
48
49 String generator = channel.getGenerator();
50 if (generator != null) {
51 eChannel.addContent(generateSimpleElement("generator", generator));
52 }
53
54 int ttl = channel.getTtl();
55 if (ttl>-1) {
56 eChannel.addContent(generateSimpleElement("ttl", String.valueOf(ttl)));
57 }
58
59 List categories = channel.getCategories();
60 for(int i = 0; i < categories.size(); i++) {
61 eChannel.addContent(generateCategoryElement((Category)categories.get(i)));
62 }
63
64 }
65
66 public void populateItem(Item item, Element eItem, int index) {
67 super.populateItem(item,eItem, index);
68
69 Element eDescription = eItem.getChild("description",getFeedNamespace());
70 if (eDescription != null) eDescription.removeAttribute("type");
71
72 String author = item.getAuthor();
73 if (author != null) {
74 eItem.addContent(generateSimpleElement("author", author));
75 }
76
77 String comments = item.getComments();
78 if (comments != null) {
79 eItem.addContent(generateSimpleElement("comments", comments));
80 }
81
82 Guid guid = item.getGuid();
83 if (guid != null) {
84 Element eGuid = generateSimpleElement("guid",guid.getValue());
85 if (!guid.isPermaLink()) {
86 eGuid.setAttribute("isPermaLink", "false");
87 }
88 eItem.addContent(eGuid);
89 }
90 }
91
92 }