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.WireFeed;
20  import com.sun.syndication.feed.rss.Channel;
21  import com.sun.syndication.feed.rss.Description;
22  import com.sun.syndication.feed.rss.Guid;
23  import com.sun.syndication.feed.rss.Item;
24  import org.jdom.Element;
25  
26  import java.util.List;
27  
28  /***
29   */
30  public class RSS094Parser extends RSS093Parser {
31  
32      public RSS094Parser() {
33          this("rss_0.94");
34      }
35  
36      protected RSS094Parser(String type) {
37          super(type);
38      }
39  
40      protected String getRSSVersion() {
41              return "0.94";
42      }
43  
44      protected WireFeed parseChannel(Element rssRoot)  {
45          Channel channel = (Channel) super.parseChannel(rssRoot);
46          Element eChannel = rssRoot.getChild("channel",getRSSNamespace());
47  
48          List eCats = eChannel.getChildren("category",getRSSNamespace());
49          channel.setCategories(parseCategories(eCats));
50  
51          Element eTtl = eChannel.getChild("ttl",getRSSNamespace());
52          if (eTtl!=null) {
53              Integer ttlValue = new Integer(eTtl.getText());
54              if (ttlValue != null) {
55                  channel.setTtl(ttlValue.intValue());
56              }
57          }
58  
59          return channel;
60      }
61  
62      protected Item parseItem(Element rssRoot,Element eItem) {
63          Item item = super.parseItem(rssRoot,eItem);
64          item.setExpirationDate(null);
65  
66          Element e = eItem.getChild("author",getRSSNamespace());
67          if (e!=null) {
68              item.setAuthor(e.getText());
69          }
70  
71          e = eItem.getChild("guid",getRSSNamespace());
72          if (e!=null) {
73              Guid guid = new Guid();
74              String att = e.getAttributeValue("isPermaLink");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
75              if (att!=null) {
76                  guid.setPermaLink(att.equalsIgnoreCase("true"));
77              }
78              guid.setValue(e.getText());
79              item.setGuid(guid);
80          }
81  
82          e = eItem.getChild("comments",getRSSNamespace());
83          if (e!=null) {
84              item.setComments(e.getText());
85          }
86  
87          return item;
88      }
89  
90      protected Description parseItemDescription(Element rssRoot,Element eDesc) {
91          Description desc = super.parseItemDescription(rssRoot,eDesc);
92          String att = eDesc.getAttributeValue("type");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
93          if (att==null) {
94              att = "text/html";
95          }
96          desc.setType(att);
97          return desc;
98      }
99  
100 }