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