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  import com.sun.syndication.feed.synd.SyndPerson;
31  
32  import java.util.*;
33  
34  /***
35   */
36  public class ConverterForRSS091Userland extends ConverterForRSS090 {
37  
38      public ConverterForRSS091Userland() {
39          this("rss_0.91U");
40      }
41  
42      protected ConverterForRSS091Userland(String type) {
43          super(type);
44      }
45  
46      public void copyInto(WireFeed feed,SyndFeed syndFeed) {
47          Channel channel = (Channel) feed;
48          super.copyInto(channel,syndFeed);
49          syndFeed.setLanguage(channel.getLanguage());        //c
50          syndFeed.setCopyright(channel.getCopyright());      //c
51          Date pubDate = channel.getPubDate();
52          if (pubDate!=null) {
53              syndFeed.setPublishedDate(pubDate);     //c
54          }
55  
56          String author = channel.getManagingEditor();
57          if (author!=null) {    
58              List creators = ((DCModule) syndFeed.getModule(DCModule.URI)).getCreators();
59              if (!creators.contains(author)) {
60                  Set s = new HashSet(); // using a set to remove duplicates
61                  s.addAll(creators);    // DC creators
62                  s.add(author);         // feed native author
63                  creators.clear();
64                  creators.addAll(s);
65              }
66          }
67  
68      }
69  
70      protected SyndImage createSyndImage(Image rssImage) {
71          SyndImage syndImage = super.createSyndImage(rssImage);
72          syndImage.setDescription(rssImage.getDescription());
73          return syndImage;
74      }
75  
76      protected SyndEntry createSyndEntry(Item item) {
77          SyndEntry syndEntry = super.createSyndEntry(item);
78          Description desc = item.getDescription();
79          if (desc!=null) {
80              SyndContent content = new SyndContentImpl();
81              content.setType(desc.getType());
82              content.setValue(desc.getValue());
83              syndEntry.setDescription(content);
84  
85              // contents[0] and description then reference the same content
86              //
87              List contents = new ArrayList();
88              contents.add(content);
89              syndEntry.setContents(contents);
90  
91          }
92          return syndEntry;
93      }
94  
95      protected WireFeed createRealFeed(String type,SyndFeed syndFeed) {
96          Channel channel = (Channel) super.createRealFeed(type,syndFeed);
97          channel.setLanguage(syndFeed.getLanguage());        //c
98          channel.setCopyright(syndFeed.getCopyright());      //c
99          channel.setPubDate(syndFeed.getPublishedDate());    //c        
100         if (syndFeed.getAuthors()!=null && syndFeed.getAuthors().size() > 0) {
101             SyndPerson author = (SyndPerson)syndFeed.getAuthors().get(0);
102             channel.setManagingEditor(author.getName());  
103         }        
104         return channel;
105     }
106 
107     protected Image createRSSImage(SyndImage sImage) {
108         Image image = super.createRSSImage(sImage);
109         image.setDescription(sImage.getDescription());
110         return image;
111     }
112 
113     protected Item createRSSItem(SyndEntry sEntry) {
114         Item item = super.createRSSItem(sEntry);
115 
116         SyndContent sContent = sEntry.getDescription();
117         if (sContent!=null) {
118             item.setDescription(createItemDescription(sContent));
119         }
120         return item;
121     }
122 
123     protected Description createItemDescription(SyndContent sContent) {
124         Description desc = new Description();
125         desc.setValue(sContent.getValue());
126         desc.setType(sContent.getType());
127         return desc;
128     }
129 
130 
131 }