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.Guid;
23  import com.sun.syndication.feed.rss.Item;
24  import com.sun.syndication.feed.synd.SyndEntry;
25  import com.sun.syndication.feed.synd.SyndFeed;
26  import com.sun.syndication.feed.synd.SyndPerson;
27  
28  import java.util.ArrayList;
29  import java.util.HashSet;
30  import java.util.List;
31  import java.util.Set;
32  
33  /**
34   */
35  public class ConverterForRSS094 extends ConverterForRSS093 {
36  
37      public ConverterForRSS094() {
38          this("rss_0.94");
39      }
40  
41      protected ConverterForRSS094(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          List cats = channel.getCategories();    //c
49          if (cats.size()>0) {
50              Set s = new HashSet();                // using a set to remove duplicates
51              s.addAll(createSyndCategories(cats)); // feed native categories (as syndcat)
52              s.addAll(syndFeed.getCategories());   // DC subjects (as syndcat)
53              syndFeed.setCategories(new ArrayList(s));
54          }
55      }
56  
57      protected SyndEntry createSyndEntry(Item item) {
58          SyndEntry syndEntry = super.createSyndEntry(item);
59  
60          // adding native feed author to DC creators list
61          String author = item.getAuthor();
62          if (author!=null) {
63              List creators = ((DCModule)syndEntry.getModule(DCModule.URI)).getCreators();
64              if (!creators.contains(author)) {
65                  Set s = new HashSet(); // using a set to remove duplicates
66                  s.addAll(creators);    // DC creators
67                  s.add(author);         // feed native author
68                  creators.clear();
69                  creators.addAll(s);
70              }
71          }
72  
73          Guid guid = item.getGuid();
74          if (guid!=null) {
75              syndEntry.setUri(guid.getValue());
76              if (item.getLink()==null && guid.isPermaLink()) {
77                  syndEntry.setLink(guid.getValue());
78              }
79          }
80          else {
81              syndEntry.setUri(item.getLink());
82          }
83          return syndEntry;
84      }
85  
86  
87      protected WireFeed createRealFeed(String type,SyndFeed syndFeed) {
88          Channel channel = (Channel) super.createRealFeed(type,syndFeed);
89          List cats = syndFeed.getCategories();    //c
90          if (cats.size()>0) {
91              channel.setCategories(createRSSCategories(cats));
92          }
93          return channel;
94      }
95  
96      protected Item createRSSItem(SyndEntry sEntry) {
97          Item item = super.createRSSItem(sEntry);     
98          if (sEntry.getAuthors()!=null && sEntry.getAuthors().size() > 0) {
99              SyndPerson author = (SyndPerson)sEntry.getAuthors().get(0);
100             item.setAuthor(author.getEmail());  
101         }  
102 
103         Guid guid = null;
104         String uri = sEntry.getUri();
105         if (uri!=null) {
106             guid = new Guid();
107             guid.setPermaLink(false);
108             guid.setValue(uri);
109         }
110         else {
111             String link = sEntry.getLink();
112             if (link!=null) {
113                 guid = new Guid();
114                 guid.setPermaLink(true);
115                 guid.setValue(link);
116             }
117         }
118         item.setGuid(guid);
119 
120         return item;
121     }
122 
123 }