View Javadoc

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.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  
26  /***
27   * Feed Generator for RSS 2.0
28   * <p/>
29   *
30   * @author Elaine Chien
31   *
32   */
33  
34  public class RSS20Generator extends RSS094Generator {
35  
36      private static final String VERSION = "2.0";
37  
38      public RSS20Generator() {
39          super("rss_2.0");
40      }
41  
42      protected RSS20Generator(String feedType) {
43          super(feedType);
44      }
45  
46      protected String getVersion() {
47          return VERSION;
48      }
49  
50      protected Element generateChannelElement(Channel channel)
51          throws FeedException {
52  
53          Element channelElement = super.generateChannelElement(channel);
54  
55          if (channel.getRating() != null) {
56              channelElement.addContent(generateSimpleElement("rating", channel.getRating()));
57          }
58  
59          if (channel.getGenerator() != null) {
60              channelElement.addContent(generateSimpleElement("generator", channel.getGenerator()));
61          }
62          if (channel.getTtl() != 0) {
63              channelElement.addContent(generateSimpleElement("ttl", String.valueOf(channel.getTtl())));
64          }
65  
66          /* TODO: need to handle categories with domain as attribute
67          if (channel.getCategories() != null) {
68              channelElement.addContent(generateCategoryElement(channel.getCategory()));
69          }
70          */
71  
72          return channelElement;
73      }
74  
75      protected Element generateItemElement(Item item)
76          throws FeedException {
77  
78          Element itemElement = super.generateItemElement(item);
79  
80          if (item.getAuthor() != null) {
81              itemElement.addContent(generateSimpleElement("author", item.getAuthor()));
82          }
83          if (item.getComments() != null) {
84              itemElement.addContent(generateSimpleElement("comments", item.getComments()));
85          }
86          if (item.getGuid() != null) {
87              itemElement.addContent(generateSimpleElement("guid", item.getGuid().toString()));
88          }
89  
90          return itemElement;
91      }
92  
93      protected Description parseItemDescription(Element rssRoot,Element eDesc) {
94          Description desc = new Description();
95          desc.setType("text/html");
96          desc.setValue(eDesc.getText());
97          return desc;
98      }
99  
100 }