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.Content;
22  import com.sun.syndication.feed.rss.Description;
23  import com.sun.syndication.feed.rss.Item;
24  import com.sun.syndication.feed.synd.SyndContent;
25  import com.sun.syndication.feed.synd.SyndContentImpl;
26  import com.sun.syndication.feed.synd.SyndEntry;
27  import com.sun.syndication.feed.synd.SyndFeed;
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      // for rss -> synd
55      // rss.content -> synd.content
56      // rss.description -> synd.description
57      
58      protected SyndEntry createSyndEntry(Item item) {
59          SyndEntry syndEntry = super.createSyndEntry(item);
60  
61          Description desc = item.getDescription();
62          if (desc!=null) {
63              SyndContent descContent = new SyndContentImpl();
64              descContent.setType(desc.getType());
65              descContent.setValue(desc.getValue());
66              syndEntry.setDescription(descContent);
67          }
68          Content cont = item.getContent();
69          if (cont!=null) {
70              SyndContent contContent = new SyndContentImpl();
71              contContent.setType(cont.getType());
72              contContent.setValue(cont.getValue());
73              List contents = new ArrayList();
74              contents.add(contContent);
75              syndEntry.setContents(contents);
76          }
77                  
78          return syndEntry;
79      }
80  
81      protected WireFeed createRealFeed(String type,SyndFeed syndFeed) {
82          Channel channel = (Channel) super.createRealFeed(type,syndFeed);        
83          if (syndFeed.getUri() != null) {
84          	channel.setUri(syndFeed.getUri());
85          } else {
86          	// if URI is not set use the value for link
87          	channel.setUri(syndFeed.getLink());
88          }
89          
90          return channel;
91      }
92      
93      // for synd -> rss
94      // synd.content -> rss.content
95      // synd.description -> rss.description
96      
97      protected Item createRSSItem(SyndEntry sEntry) {
98          Item item = super.createRSSItem(sEntry);
99  
100         SyndContent desc = sEntry.getDescription();
101         if (desc!=null) {
102             item.setDescription(createItemDescription(desc));
103         }
104         List contents = sEntry.getContents();
105         if (contents!=null && contents.size() > 0) {
106             item.setContent(createItemContent((SyndContent)contents.get(0)));
107         }
108         
109         String uri = sEntry.getUri();
110         if (uri != null) {
111             item.setUri(uri);
112         }
113         
114         return item;
115     }
116 
117     protected Description createItemDescription(SyndContent sContent) {
118         Description desc = new Description();
119         desc.setValue(sContent.getValue());
120         desc.setType(sContent.getType());
121         return desc;
122     }
123 
124     protected Content createItemContent(SyndContent sContent) {
125         Content cont = new Content();
126         cont.setValue(sContent.getValue());
127         cont.setType(sContent.getType());
128         return cont;
129     }
130 
131 }