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",Integer.toString(i));
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 if (link!=null) {
79 eItem.setAttribute("about",Integer.toString(index),getRDFNamespace());
80 }
81 Description description = item.getDescription();
82 if (description!=null) {
83 eItem.addContent(generateSimpleElement("description",description.getValue()));
84 }
85 }
86
87 protected void checkChannelConstraints(Element eChannel) throws FeedException {
88 checkNotNullAndLength(eChannel,"title", 0, -1);
89 checkNotNullAndLength(eChannel,"description", 0, -1);
90 checkNotNullAndLength(eChannel,"link", 0, -1);
91 }
92
93 protected void checkImageConstraints(Element eImage) throws FeedException {
94 checkNotNullAndLength(eImage,"title", 0, -1);
95 checkNotNullAndLength(eImage,"url", 0, -1);
96 checkNotNullAndLength(eImage,"link", 0, -1);
97 }
98
99 protected void checkTextInputConstraints(Element eTextInput) throws FeedException {
100 checkNotNullAndLength(eTextInput,"title", 0, -1);
101 checkNotNullAndLength(eTextInput,"description", 0, -1);
102 checkNotNullAndLength(eTextInput,"name", 0, -1);
103 checkNotNullAndLength(eTextInput,"link", 0, -1);
104 }
105
106 protected void checkItemsConstraints(Element parent) throws FeedException {
107 }
108
109 protected void checkItemConstraints(Element eItem) throws FeedException {
110 checkNotNullAndLength(eItem,"title", 0, -1);
111 checkNotNullAndLength(eItem,"link", 0, -1);
112 }
113
114 }
115