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.feed.synd.impl;
18  
19  import com.sun.syndication.feed.WireFeed;
20  import com.sun.syndication.feed.module.impl.ModuleUtils;
21  import com.sun.syndication.feed.rss.Channel;
22  import com.sun.syndication.feed.rss.Description;
23  import com.sun.syndication.feed.rss.Item;
24  import com.sun.syndication.feed.synd.SyndFeedI;
25  import com.sun.syndication.feed.synd.SyndContentI;
26  import com.sun.syndication.feed.synd.SyndEntryI;
27  import com.sun.syndication.feed.synd.SyndContent;
28  
29  import java.util.List;
30  import java.util.ArrayList;
31  
32  /***
33   */
34  public class ConverterForRSS10 extends ConverterForRSS090 {
35  
36      public String getType() {
37          return "rss_1.0";
38      }
39  
40      public void copyInto(WireFeed feed,SyndFeedI syndFeed) {
41          Channel channel = (Channel) feed;
42          super.copyInto(channel,syndFeed);
43  
44          syndFeed.setModules(ModuleUtils.cloneModules(channel.getModules()));
45  
46      }
47  
48      protected SyndEntryI createSyndEntry(Item item) {
49          SyndEntryI syndEntry = super.createSyndEntry(item);
50  
51          Description desc = item.getDescription();
52          if (desc!=null) {
53              SyndContentI content = new SyndContent();
54              content.setType(desc.getType());
55              content.setValue(desc.getValue());
56              syndEntry.setDescription(content);
57  
58              // contents[0] and description then reference the same content
59              //
60              List contents = new ArrayList();
61              contents.add(content);
62              syndEntry.setContents(contents);
63  
64          }
65  
66          syndEntry.setModules(ModuleUtils.cloneModules(item.getModules()));
67  
68  
69          return syndEntry;
70      }
71  
72      protected WireFeed createRealFeed(String type,SyndFeedI syndFeed) {
73          Channel channel = (Channel) super.createRealFeed(type,syndFeed);
74          channel.setModules(ModuleUtils.cloneModules(syndFeed.getModules()));
75          return channel;
76      }
77  
78      protected Item createRSSItem(SyndEntryI sEntry) {
79          Item item = super.createRSSItem(sEntry);
80  
81          SyndContentI sContent = sEntry.getDescription();
82          if (sContent!=null) {
83              item.setDescription(createItemDescription(sContent));
84          }
85  
86          item.setModules(ModuleUtils.cloneModules(sEntry.getModules()));
87          return item;
88      }
89  
90      protected Description createItemDescription(SyndContentI sContent) {
91          Description desc = new Description();
92          desc.setValue(sContent.getValue());
93          desc.setType(sContent.getType());
94          return desc;
95      }
96  
97  }