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 import java.util.List;
26
27
28 /***
29 * Feed Generator for RSS 2.0
30 * <p/>
31 *
32 * @author Elaine Chien
33 *
34 */
35
36 public class RSS20Generator extends RSS094Generator {
37
38 /***
39 * rss_2.0.feed.ModuleGenerator.classes= [className] ...
40 *
41 */
42 public static final String FEED_MODULE_GENERATORS_KEY = "rss_2.0.feed.ModuleGenerator.classes";
43
44 /***
45 * rss_2.0.item.ModuleGenerator.classes= [className] ...
46 *
47 */
48 public static final String ITEM_MODULE_GENERATORS_KEY = "rss_2.0.item.ModuleGenerator.classes";
49
50 private static ModuleGenerators FEED_MODULES_GENERATOR = new ModuleGenerators(FEED_MODULE_GENERATORS_KEY);
51 private static ModuleGenerators ITEM_MODULES_GENERATOR = new ModuleGenerators(ITEM_MODULE_GENERATORS_KEY);
52
53 private static final String VERSION = "2.0";
54
55 public RSS20Generator() {
56 super("rss_2.0");
57 }
58
59 protected RSS20Generator(String feedType) {
60 super(feedType);
61 }
62
63 protected String getVersion() {
64 return VERSION;
65 }
66
67 protected Element generateChannelElement(Channel channel)
68 throws FeedException {
69
70 Element channelElement = super.generateChannelElement(channel);
71
72 if (channel.getRating() != null) {
73 channelElement.addContent(generateSimpleElement("rating", channel.getRating()));
74 }
75
76 if (channel.getGenerator() != null) {
77 channelElement.addContent(generateSimpleElement("generator", channel.getGenerator()));
78 }
79 if (channel.getTtl() != 0) {
80 channelElement.addContent(generateSimpleElement("ttl", String.valueOf(channel.getTtl())));
81 }
82
83
84
85
86
87
88
89 List modules = channel.getModules();
90 if (modules != null) {
91 FEED_MODULES_GENERATOR.generateModules(modules, channelElement);
92 }
93
94 return channelElement;
95 }
96
97 protected Element generateItemElement(Item item)
98 throws FeedException {
99
100 Element itemElement = super.generateItemElement(item);
101
102 if (item.getAuthor() != null) {
103 itemElement.addContent(generateSimpleElement("author", item.getAuthor()));
104 }
105 if (item.getComments() != null) {
106 itemElement.addContent(generateSimpleElement("comments", item.getComments()));
107 }
108 if (item.getGuid() != null) {
109 itemElement.addContent(generateSimpleElement("guid", item.getGuid().toString()));
110 }
111 List modules = item.getModules();
112 if (modules != null) {
113 ITEM_MODULES_GENERATOR.generateModules(modules, itemElement);
114 }
115
116 return itemElement;
117 }
118
119 protected Description parseItemDescription(Element rssRoot,Element eDesc) {
120 Description desc = new Description();
121 desc.setType("text/html");
122 desc.setValue(eDesc.getText());
123 return desc;
124 }
125
126 }