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.feed.rss.Category;
20  import com.sun.syndication.feed.rss.Channel;
21  import com.sun.syndication.feed.rss.Guid;
22  import com.sun.syndication.feed.rss.Item;
23  import org.jdom.Element;
24  
25  import java.util.List;
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 feedType,String version) {
43          super(feedType,version);
44      }
45  
46      protected void populateChannel(Channel channel,Element eChannel) {
47          super.populateChannel(channel,eChannel);
48  
49          String 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 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      public void populateItem(Item item, Element eItem, int index) {
67          super.populateItem(item,eItem, index);
68  
69          Element eDescription = eItem.getChild("description",getFeedNamespace());
70          if (eDescription != null) eDescription.removeAttribute("type");
71  
72          String author = item.getAuthor();
73          if (author != null) {
74              eItem.addContent(generateSimpleElement("author", author));
75          }
76  
77          String comments = item.getComments();
78          if (comments != null) {
79              eItem.addContent(generateSimpleElement("comments", comments));
80          }
81  
82          Guid guid = item.getGuid();
83          if (guid != null) {
84              Element eGuid = generateSimpleElement("guid",guid.getValue());
85              if (!guid.isPermaLink()) {
86                  eGuid.setAttribute("isPermaLink", "false");
87              }
88              eItem.addContent(eGuid);
89          }
90      }
91  
92  }