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.io.FeedException;
20 import com.sun.syndication.feed.rss.Channel;
21 import com.sun.syndication.feed.rss.Item;
22 import com.sun.syndication.feed.rss.Description;
23 import org.jdom.Element;
24
25
26 /***
27 * Feed Generator for RSS 2.0
28 * <p/>
29 *
30 * @author Elaine Chien
31 *
32 */
33
34 public class RSS20Generator extends RSS094Generator {
35
36 private static final String VERSION = "2.0";
37
38 public RSS20Generator() {
39 super("rss_2.0");
40 }
41
42 protected RSS20Generator(String feedType) {
43 super(feedType);
44 }
45
46 protected String getVersion() {
47 return VERSION;
48 }
49
50 protected Element generateChannelElement(Channel channel)
51 throws FeedException {
52
53 Element channelElement = super.generateChannelElement(channel);
54
55 if (channel.getRating() != null) {
56 channelElement.addContent(generateSimpleElement("rating", channel.getRating()));
57 }
58
59 if (channel.getGenerator() != null) {
60 channelElement.addContent(generateSimpleElement("generator", channel.getGenerator()));
61 }
62 if (channel.getTtl() != 0) {
63 channelElement.addContent(generateSimpleElement("ttl", String.valueOf(channel.getTtl())));
64 }
65
66
67
68
69
70
71
72 return channelElement;
73 }
74
75 protected Element generateItemElement(Item item)
76 throws FeedException {
77
78 Element itemElement = super.generateItemElement(item);
79
80 if (item.getAuthor() != null) {
81 itemElement.addContent(generateSimpleElement("author", item.getAuthor()));
82 }
83 if (item.getComments() != null) {
84 itemElement.addContent(generateSimpleElement("comments", item.getComments()));
85 }
86 if (item.getGuid() != null) {
87 itemElement.addContent(generateSimpleElement("guid", item.getGuid().toString()));
88 }
89
90 return itemElement;
91 }
92
93 protected Description parseItemDescription(Element rssRoot,Element eDesc) {
94 Description desc = new Description();
95 desc.setType("text/html");
96 desc.setValue(eDesc.getText());
97 return desc;
98 }
99
100 }