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.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;
26  import java.util.List;
27  
28  /***
29   */
30  public class ConverterForRSS092 extends ConverterForRSS091Userland {
31  
32      public ConverterForRSS092() {
33          this("rss_0.92");
34      }
35  
36      protected ConverterForRSS092(String type) {
37          super(type);
38      }
39  
40      protected SyndEntry createSyndEntry(Item item) {
41          SyndEntry syndEntry = super.createSyndEntry(item);
42          List cats =  item.getCategories();
43          if (cats!=null) {
44              syndEntry.setCategories(createSyndCategories(cats));    //c
45          }
46          return syndEntry;
47      }
48  
49      protected List createSyndCategories(List rssCats) {
50          List syndCats = new ArrayList();
51          for (int i=0;i<rssCats.size();i++) {
52              Category rssCat = (Category) rssCats.get(i);
53              SyndCategory sCat = new SyndCategoryImpl();
54              sCat.setTaxonomyUri(rssCat.getDomain());
55              sCat.setName(rssCat.getValue());
56              syndCats.add(sCat);
57          }
58          return syndCats;
59      }
60  
61      protected Item createRSSItem(SyndEntry sEntry) {
62          Item item = super.createRSSItem(sEntry);
63  
64          List sCats =  sEntry.getCategories();    //c
65          if (sCats!=null) {
66              item.setCategories(createRSSCategories(sCats));
67          }
68          return item;
69      }
70  
71      protected List createRSSCategories(List sCats) {
72          List cats = new ArrayList();
73          for (int i=0;i<sCats.size();i++) {
74              SyndCategory sCat = (SyndCategory) sCats.get(i);
75              Category cat = new Category();
76              cat.setDomain(sCat.getTaxonomyUri());
77              cat.setValue(sCat.getName());
78              cats.add(cat);
79          }
80          return cats;
81      }
82  
83  }