KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > syndication > feed > synd > impl > ConverterForRSS094


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.Guid;
22 import com.sun.syndication.feed.rss.Item;
23 import com.sun.syndication.feed.synd.SyndEntry;
24 import com.sun.syndication.feed.synd.SyndFeed;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.HashSet JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Set JavaDoc;
30
31 /**
32  */

33 public class ConverterForRSS094 extends ConverterForRSS093 {
34
35     public ConverterForRSS094() {
36         this("rss_0.94");
37     }
38
39     protected ConverterForRSS094(String JavaDoc type) {
40         super(type);
41     }
42
43     public void copyInto(WireFeed feed,SyndFeed syndFeed) {
44         Channel channel = (Channel) feed;
45         super.copyInto(channel,syndFeed);
46         List JavaDoc cats = channel.getCategories(); //c
47
if (cats.size()>0) {
48             Set JavaDoc s = new HashSet JavaDoc(); // using a set to remove duplicates
49
s.addAll(createSyndCategories(cats)); // feed native categories (as syndcat)
50
s.addAll(syndFeed.getCategories()); // DC subjects (as syndcat)
51
syndFeed.setCategories(new ArrayList JavaDoc(s));
52         }
53     }
54
55     protected SyndEntry createSyndEntry(Item item) {
56         SyndEntry syndEntry = super.createSyndEntry(item);
57         syndEntry.setAuthor(item.getAuthor()); //c
58

59         Guid guid = item.getGuid();
60         if (guid!=null) {
61             syndEntry.setUri(guid.getValue());
62             if (item.getLink()==null && guid.isPermaLink()) {
63                 syndEntry.setLink(guid.getValue());
64             }
65         }
66         else {
67             syndEntry.setUri(item.getLink());
68         }
69         return syndEntry;
70     }
71
72
73     protected WireFeed createRealFeed(String JavaDoc type,SyndFeed syndFeed) {
74         Channel channel = (Channel) super.createRealFeed(type,syndFeed);
75         List JavaDoc cats = syndFeed.getCategories(); //c
76
if (cats.size()>0) {
77             channel.setCategories(createRSSCategories(cats));
78         }
79         return channel;
80     }
81
82     protected Item createRSSItem(SyndEntry sEntry) {
83         Item item = super.createRSSItem(sEntry);
84         item.setAuthor(sEntry.getAuthor()); //c
85

86         Guid guid = null;
87         String JavaDoc uri = sEntry.getUri();
88         if (uri!=null) {
89             guid = new Guid();
90             guid.setPermaLink(false);
91             guid.setValue(uri);
92         }
93         else {
94             String JavaDoc link = sEntry.getLink();
95             if (link!=null) {
96                 guid = new Guid();
97                 guid.setPermaLink(true);
98                 guid.setValue(link);
99             }
100         }
101         item.setGuid(guid);
102
103         return item;
104     }
105
106 }
107
Popular Tags