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.rss.Channel;
21  import com.sun.syndication.feed.rss.Description;
22  import com.sun.syndication.feed.rss.Item;
23  import com.sun.syndication.feed.synd.SyndContent;
24  import com.sun.syndication.feed.synd.SyndContentImpl;
25  import com.sun.syndication.feed.synd.SyndEntry;
26  import com.sun.syndication.feed.synd.SyndFeed;
27  
28  import java.util.ArrayList;
29  import java.util.List;
30  
31  /***
32   */
33  public class ConverterForRSS10 extends ConverterForRSS090 {
34  
35      public ConverterForRSS10() {
36          this("rss_1.0");
37      }
38  
39      protected ConverterForRSS10(String type) {
40          super(type);
41      }
42  
43      public void copyInto(WireFeed feed,SyndFeed syndFeed) {
44          Channel channel = (Channel) feed;
45          super.copyInto(channel,syndFeed);
46          if (channel.getUri() != null) {
47          	syndFeed.setUri(channel.getUri());
48          } else {
49          	// if URI is not set use the value for link
50          	syndFeed.setUri(channel.getLink());
51          }
52      }
53  
54      protected SyndEntry createSyndEntry(Item item) {
55          SyndEntry syndEntry = super.createSyndEntry(item);
56  
57          Description desc = item.getDescription();
58          if (desc!=null) {
59              SyndContent content = new SyndContentImpl();
60              content.setType(desc.getType());
61              content.setValue(desc.getValue());
62              syndEntry.setDescription(content);
63  
64              // contents[0] and description then reference the same content
65              //
66              List contents = new ArrayList();
67              contents.add(content);
68              syndEntry.setContents(contents);
69  
70          }
71          
72          return syndEntry;
73      }
74  
75      protected WireFeed createRealFeed(String type,SyndFeed syndFeed) {
76          Channel channel = (Channel) super.createRealFeed(type,syndFeed);        
77          if (syndFeed.getUri() != null) {
78          	channel.setUri(syndFeed.getUri());
79          } else {
80          	// if URI is not set use the value for link
81          	channel.setUri(syndFeed.getLink());
82          }
83          
84          return channel;
85      }
86  
87      protected Item createRSSItem(SyndEntry sEntry) {
88          Item item = super.createRSSItem(sEntry);
89  
90          SyndContent sContent = sEntry.getDescription();
91          if (sContent!=null) {
92              item.setDescription(createItemDescription(sContent));
93          }
94          
95          String uri = sEntry.getUri();
96          if (uri != null) {
97              item.setUri(uri);
98          }
99          
100         return item;
101     }
102 
103     protected Description createItemDescription(SyndContent sContent) {
104         Description desc = new Description();
105         desc.setValue(sContent.getValue());
106         desc.setType(sContent.getType());
107         return desc;
108     }
109 
110 }