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