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.Description;
20 import com.sun.syndication.feed.rss.Item;
21 import com.sun.syndication.feed.rss.Channel;
22 import com.sun.syndication.io.FeedException;
23 import org.jdom.Element;
24 import org.jdom.Namespace;
25
26 import java.util.List;
27
28 /***
29 * Feed Generator for RSS 1.0
30 * <p/>
31 *
32 * @author Elaine Chien
33 *
34 */
35
36 public class RSS10Generator extends RSS090Generator {
37 private static final String RSS_URI = "http://purl.org/rss/1.0/";
38 private static final Namespace RSS_NS = Namespace.getNamespace(RSS_URI);
39
40 public RSS10Generator() {
41 super("rss_1.0");
42 }
43
44 protected RSS10Generator(String feedType) {
45 super(feedType);
46 }
47
48 protected Namespace getFeedNamespace() {
49 return RSS_NS;
50 }
51
52 protected void populateChannel(Channel channel,Element eChannel) {
53 super.populateChannel(channel,eChannel);
54 if (channel.getUri() != null) {
55 eChannel.setAttribute("about", channel.getUri(), getRDFNamespace());
56 }
57 List items = channel.getItems();
58 if (items.size()>0) {
59 Element eItems = new Element("items",getFeedNamespace());
60 Element eSeq = new Element("Seq",getRDFNamespace());
61 for (int i=0;i<items.size();i++) {
62 Item item = (Item) items.get(i);
63 Element eLi = new Element("li",getRDFNamespace());
64 String link = item.getLink();
65 if (link!=null) {
66 eLi.setAttribute("resource",link);
67 }
68 eSeq.addContent(eLi);
69 }
70 eItems.addContent(eSeq);
71 eChannel.addContent(eItems);
72 }
73 }
74
75 protected void populateItem(Item item, Element eItem, int index) {
76 super.populateItem(item,eItem, index);
77 String link = item.getLink();
78 String uri = item.getUri();
79
80 if (uri != null) {
81 eItem.setAttribute("about", uri, getRDFNamespace());
82 } else if (link != null) {
83 eItem.setAttribute("about", link, getRDFNamespace());
84 }
85
86 Description description = item.getDescription();
87 if (description!=null) {
88 eItem.addContent(generateSimpleElement("description",description.getValue()));
89 }
90 }
91
92 protected void checkChannelConstraints(Element eChannel) throws FeedException {
93 checkNotNullAndLength(eChannel,"title", 0, -1);
94 checkNotNullAndLength(eChannel,"description", 0, -1);
95 checkNotNullAndLength(eChannel,"link", 0, -1);
96 }
97
98 protected void checkImageConstraints(Element eImage) throws FeedException {
99 checkNotNullAndLength(eImage,"title", 0, -1);
100 checkNotNullAndLength(eImage,"url", 0, -1);
101 checkNotNullAndLength(eImage,"link", 0, -1);
102 }
103
104 protected void checkTextInputConstraints(Element eTextInput) throws FeedException {
105 checkNotNullAndLength(eTextInput,"title", 0, -1);
106 checkNotNullAndLength(eTextInput,"description", 0, -1);
107 checkNotNullAndLength(eTextInput,"name", 0, -1);
108 checkNotNullAndLength(eTextInput,"link", 0, -1);
109 }
110
111 protected void checkItemsConstraints(Element parent) throws FeedException {
112 }
113
114 protected void checkItemConstraints(Element eItem) throws FeedException {
115 checkNotNullAndLength(eItem,"title", 0, -1);
116 checkNotNullAndLength(eItem,"link", 0, -1);
117 }
118
119 }
120