KickJava   Java API By Example, From Geeks To Geeks.

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


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

32 public class ConverterForRSS092 extends ConverterForRSS091Userland {
33
34     public ConverterForRSS092() {
35         this("rss_0.92");
36     }
37
38     protected ConverterForRSS092(String JavaDoc type) {
39         super(type);
40     }
41
42     protected SyndEntry createSyndEntry(Item item) {
43         SyndEntry syndEntry = super.createSyndEntry(item);
44         List JavaDoc cats = item.getCategories();
45         if (cats.size()>0) {
46             Set JavaDoc s = new HashSet JavaDoc(); // using a set to remove duplicates
47
s.addAll(createSyndCategories(cats)); // feed native categories (as syndcat)
48
s.addAll(syndEntry.getCategories()); // DC subjects (as syndcat)
49
syndEntry.setCategories(new ArrayList JavaDoc(s)); //c
50
}
51         return syndEntry;
52     }
53
54     protected List JavaDoc createSyndCategories(List JavaDoc rssCats) {
55         List JavaDoc syndCats = new ArrayList JavaDoc();
56         for (int i=0;i<rssCats.size();i++) {
57             Category rssCat = (Category) rssCats.get(i);
58             SyndCategory sCat = new SyndCategoryImpl();
59             sCat.setTaxonomyUri(rssCat.getDomain());
60             sCat.setName(rssCat.getValue());
61             syndCats.add(sCat);
62         }
63         return syndCats;
64     }
65
66     protected Item createRSSItem(SyndEntry sEntry) {
67         Item item = super.createRSSItem(sEntry);
68
69         List JavaDoc sCats = sEntry.getCategories(); //c
70
if (sCats.size()>0) {
71             item.setCategories(createRSSCategories(sCats));
72         }
73         return item;
74     }
75
76     protected List JavaDoc createRSSCategories(List JavaDoc sCats) {
77         List JavaDoc cats = new ArrayList JavaDoc();
78         for (int i=0;i<sCats.size();i++) {
79             SyndCategory sCat = (SyndCategory) sCats.get(i);
80             Category cat = new Category();
81             cat.setDomain(sCat.getTaxonomyUri());
82             cat.setValue(sCat.getName());
83             cats.add(cat);
84         }
85         return cats;
86     }
87
88 }
89
Popular Tags