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.DCModule;
21  import com.sun.syndication.feed.rss.Channel;
22  import com.sun.syndication.feed.rss.Description;
23  import com.sun.syndication.feed.rss.Image;
24  import com.sun.syndication.feed.rss.Item;
25  import com.sun.syndication.feed.synd.SyndFeed;
26  import com.sun.syndication.feed.synd.SyndContent;
27  import com.sun.syndication.feed.synd.SyndEntry;
28  import com.sun.syndication.feed.synd.SyndImage;
29  import com.sun.syndication.feed.synd.SyndContentImpl;
30  
31  import java.util.*;
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          Date pubDate = channel.getPubDate();
51          if (pubDate!=null) {
52              syndFeed.setPublishedDate(pubDate);     //c
53          }
54  
55          String author = channel.getManagingEditor();
56          if (author!=null) {    
57              List creators = ((DCModule) syndFeed.getModule(DCModule.URI)).getCreators();
58              if (!creators.contains(author)) {
59                  Set s = new HashSet(); // using a set to remove duplicates
60                  s.addAll(creators);    // DC creators
61                  s.add(author);         // feed native author
62                  creators.clear();
63                  creators.addAll(s);
64              }
65          }
66  
67      }
68  
69      protected SyndImage createSyndImage(Image rssImage) {
70          SyndImage syndImage = super.createSyndImage(rssImage);
71          syndImage.setDescription(rssImage.getDescription());
72          return syndImage;
73      }
74  
75      protected SyndEntry createSyndEntry(Item item) {
76          SyndEntry syndEntry = super.createSyndEntry(item);
77          Description desc = item.getDescription();
78          if (desc!=null) {
79              SyndContent content = new SyndContentImpl();
80              content.setType(desc.getType());
81              content.setValue(desc.getValue());
82              syndEntry.setDescription(content);
83  
84              // contents[0] and description then reference the same content
85              //
86              List contents = new ArrayList();
87              contents.add(content);
88              syndEntry.setContents(contents);
89  
90          }
91          return syndEntry;
92      }
93  
94      protected WireFeed createRealFeed(String type,SyndFeed syndFeed) {
95          Channel channel = (Channel) super.createRealFeed(type,syndFeed);
96          channel.setLanguage(syndFeed.getLanguage());        //c
97          channel.setCopyright(syndFeed.getCopyright());      //c
98          channel.setPubDate(syndFeed.getPublishedDate());    //c
99          channel.setManagingEditor(syndFeed.getAuthor());    //c
100         return channel;
101     }
102 
103     protected Image createRSSImage(SyndImage sImage) {
104         Image image = super.createRSSImage(sImage);
105         image.setDescription(sImage.getDescription());
106         return image;
107     }
108 
109     protected Item createRSSItem(SyndEntry sEntry) {
110         Item item = super.createRSSItem(sEntry);
111 
112         SyndContent sContent = sEntry.getDescription();
113         if (sContent!=null) {
114             item.setDescription(createItemDescription(sContent));
115         }
116         return item;
117     }
118 
119     protected Description createItemDescription(SyndContent sContent) {
120         Description desc = new Description();
121         desc.setValue(sContent.getValue());
122         desc.setType(sContent.getType());
123         return desc;
124     }
125 
126 
127 }