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.*;
20 import com.sun.syndication.io.FeedException;
21 import org.jdom.Attribute;
22 import org.jdom.Element;
23
24 import java.util.List;
25
26
27
28
29
30
31
32
33
34
35 public class RSS092Generator extends RSS091UserlandGenerator {
36
37 public RSS092Generator() {
38 this("rss_0.92","0.92");
39 }
40
41 protected RSS092Generator(String type,String version) {
42 super(type,version);
43 }
44
45 protected void populateChannel(Channel channel,Element eChannel) {
46 super.populateChannel(channel,eChannel);
47
48 Cloud cloud = channel.getCloud();
49 if (cloud!=null) {
50 eChannel.addContent(generateCloud(cloud));
51 }
52 }
53
54 protected Element generateCloud(Cloud cloud) {
55 Element eCloud = new Element("cloud",getFeedNamespace());
56
57 if (cloud.getDomain() != null) {
58 eCloud.setAttribute(new Attribute("domain", cloud.getDomain()));
59 }
60
61 if (cloud.getPort() != 0) {
62 eCloud.setAttribute(new Attribute("port", String.valueOf(cloud.getPort())));
63 }
64
65 if (cloud.getPath() != null) {
66 eCloud.setAttribute(new Attribute("path", cloud.getPath()));
67 }
68
69 if (cloud.getRegisterProcedure() != null) {
70 eCloud.setAttribute(new Attribute("registerProcedure", cloud.getRegisterProcedure()));
71 }
72
73 if (cloud.getProtocol() != null) {
74 eCloud.setAttribute(new Attribute("protocol", cloud.getProtocol()));
75 }
76 return eCloud;
77 }
78
79
80 protected int getNumberOfEnclosures(List enclosures) {
81 return (enclosures.size()>0) ? 1 : 0;
82 }
83
84 protected void populateItem(Item item, Element eItem, int index) {
85 super.populateItem(item,eItem, index);
86
87 Source source =item.getSource();
88 if (source != null) {
89 eItem.addContent(generateSourceElement(source));
90 }
91
92 List enclosures = item.getEnclosures();
93 for(int i = 0; i < getNumberOfEnclosures(enclosures); i++) {
94 eItem.addContent(generateEnclosure((Enclosure)enclosures.get(i)));
95 }
96
97 List categories = item.getCategories();
98 for(int i = 0; i < categories.size(); i++) {
99 eItem.addContent(generateCategoryElement((Category)categories.get(i)));
100 }
101 }
102
103 protected Element generateSourceElement(Source source) {
104 Element sourceElement = new Element("source",getFeedNamespace());
105 if (source.getUrl() != null) {
106 sourceElement.setAttribute(new Attribute("url", source.getUrl()));
107 }
108 sourceElement.addContent(source.getValue());
109 return sourceElement;
110 }
111
112 protected Element generateEnclosure(Enclosure enclosure) {
113 Element enclosureElement = new Element("enclosure",getFeedNamespace());
114 if (enclosure.getUrl() != null) {
115 enclosureElement.setAttribute("url", enclosure.getUrl());
116 }
117 if (enclosure.getLength() != 0) {
118 enclosureElement.setAttribute("length", String.valueOf(enclosure.getLength()));
119 }
120 if (enclosure.getType() != null) {
121 enclosureElement.setAttribute("type", enclosure.getType());
122 }
123 return enclosureElement;
124 }
125
126 protected Element generateCategoryElement(Category category) {
127 Element categoryElement = new Element("category",getFeedNamespace());
128 if (category.getDomain() != null) {
129 categoryElement.setAttribute("domain", category.getDomain());
130 }
131 categoryElement.addContent(category.getValue());
132 return categoryElement;
133 }
134
135
136 protected void checkChannelConstraints(Element eChannel) throws FeedException {
137 checkNotNullAndLength(eChannel,"title", 0, -1);
138 checkNotNullAndLength(eChannel,"description", 0, -1);
139 checkNotNullAndLength(eChannel,"link", 0, -1);
140 }
141
142 protected void checkImageConstraints(Element eImage) throws FeedException {
143 checkNotNullAndLength(eImage,"title", 0, -1);
144 checkNotNullAndLength(eImage,"url", 0, -1);
145 }
146
147 protected void checkTextInputConstraints(Element eTextInput) throws FeedException {
148 checkNotNullAndLength(eTextInput,"title", 0, -1);
149 checkNotNullAndLength(eTextInput,"description", 0, -1);
150 checkNotNullAndLength(eTextInput,"name", 0, -1);
151 checkNotNullAndLength(eTextInput,"link", 0, -1);
152 }
153
154 protected void checkItemsConstraints(Element parent) throws FeedException {
155 }
156
157 protected void checkItemConstraints(Element eItem) throws FeedException {
158 }
159
160 }