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.io.impl;
18  
19  import com.sun.syndication.feed.rss.Description;
20  import com.sun.syndication.feed.rss.Channel;
21  import com.sun.syndication.feed.rss.Item;
22  import com.sun.syndication.feed.WireFeed;
23  import org.jdom.Element;
24  
25  import java.util.List;
26  
27  /***
28   */
29  public class RSS20Parser extends RSS094Parser {
30  
31      /***
32       * rss_2.0.feed.ModuleParser.classes=  [className] ...
33       *
34       */
35      public static final String FEED_MODULE_PARSERS_KEY = "rss_2.0.feed.ModuleParser.classes";
36  
37      /***
38       * rss_2.0.item.ModuleParser.classes= [className] ...
39       *
40       */
41      public static final String ITEM_MODULE_PARSERS_KEY = "rss_2.0.item.ModuleParser.classes";
42  
43      private static ModuleParsers FEED_MODULES_PARSER = new ModuleParsers(FEED_MODULE_PARSERS_KEY);
44      private static ModuleParsers ITEM_MODULES_PARSER = new ModuleParsers(ITEM_MODULE_PARSERS_KEY);
45  
46      public RSS20Parser() {
47          this("rss_2.0");
48      }
49  
50      protected RSS20Parser(String type) {
51          super(type);
52      }
53  
54      protected String getRSSVersion() {
55              return "2.0";
56      }
57  
58      protected boolean isHourFormat24(Element rssRoot) {
59          return false;
60      }
61  
62      protected WireFeed parseChannel(Element rssRoot)  {
63          Channel channel = (Channel) super.parseChannel(rssRoot);
64          List modules = FEED_MODULES_PARSER.parseModules(rssRoot.getChild("channel",getRSSNamespace()));
65          if (modules!=null) {
66              channel.setModules(modules);
67          }
68          return channel;
69      }
70  
71      protected Item parseItem(Element rssRoot,Element eItem) {
72          Item item = super.parseItem(rssRoot,eItem);
73          List modules = ITEM_MODULES_PARSER.parseModules(eItem);
74          if (modules!=null) {
75              item.setModules(modules);
76          }
77          return item;
78      }
79  
80  
81      protected Description parseItemDescription(Element rssRoot,Element eDesc) {
82          Description desc = super.parseItemDescription(rssRoot,eDesc);
83          desc.setType("text/plain"); // JDOM unescapes it, not sure if it's always OK
84          return desc;
85      }
86  
87  }