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