KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > syndication > io > impl > RSS20Generator


1 /*
2  * Copyright 2004 Sun Microsystems, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17 package com.sun.syndication.io.impl;
18
19 import com.sun.syndication.feed.rss.Channel;
20 import com.sun.syndication.feed.rss.Guid;
21 import com.sun.syndication.feed.rss.Item;
22 import com.sun.syndication.feed.rss.Category;
23 import org.jdom.Element;
24
25 import java.util.List JavaDoc;
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     public RSS20Generator() {
39         this("rss_2.0","2.0");
40     }
41
42     protected RSS20Generator(String JavaDoc feedType,String JavaDoc version) {
43         super(feedType,version);
44     }
45
46     protected void populateChannel(Channel channel,Element eChannel) {
47         super.populateChannel(channel,eChannel);
48
49         String JavaDoc generator = channel.getGenerator();
50         if (generator != null) {
51             eChannel.addContent(generateSimpleElement("generator", generator));
52         }
53
54         int ttl = channel.getTtl();
55         if (ttl>-1) {
56             eChannel.addContent(generateSimpleElement("ttl", String.valueOf(ttl)));
57         }
58
59         List JavaDoc categories = channel.getCategories();
60         for(int i = 0; i < categories.size(); i++) {
61             eChannel.addContent(generateCategoryElement((Category)categories.get(i)));
62         }
63
64     }
65
66     protected void populateItem(Item item, Element eItem, int index) {
67         super.populateItem(item,eItem, index);
68
69         Element eDescription = eItem.getChild("description",getFeedNamespace());
70         //TODO FIX THIS, TEST FOR NULL BEFORE DOING SO
71
eDescription.removeAttribute("type");
72
73         String JavaDoc author = item.getAuthor();
74         if (author != null) {
75             eItem.addContent(generateSimpleElement("author", author));
76         }
77
78         String JavaDoc comments = item.getComments();
79         if (comments != null) {
80             eItem.addContent(generateSimpleElement("comments", comments));
81         }
82
83         Guid guid = item.getGuid();
84         if (guid != null) {
85             Element eGuid = generateSimpleElement("guid",guid.getValue());
86             if (!guid.isPermaLink()) {
87                 eGuid.setAttribute("isPermaLink", "false");
88             }
89             eItem.addContent(eGuid);
90         }
91     }
92
93 }
94
Popular Tags