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 org.jdom.Attribute;
21  import org.jdom.Document;
22  import org.jdom.Element;
23  
24  /**
25   */
26  public class RSS20Parser extends RSS094Parser {
27  
28      public RSS20Parser() {
29          this("rss_2.0");
30      }
31  
32      protected RSS20Parser(String type) {
33          super(type);
34      }
35  
36      protected String getRSSVersion() {
37              return "2.0";
38      }
39  
40      protected boolean isHourFormat24(Element rssRoot) {
41          return false;
42      }
43  
44      protected Description parseItemDescription(Element rssRoot,Element eDesc) {
45          Description desc = super.parseItemDescription(rssRoot,eDesc);
46          desc.setType("text/html"); // change as per https://rome.dev.java.net/issues/show_bug.cgi?id=26 
47          return desc;
48      }
49      
50      public boolean isMyType(Document document) {
51          boolean ok;
52          Element rssRoot = document.getRootElement();
53          ok = rssRoot.getName().equals("rss");
54          if (ok) {
55              ok = false;
56              Attribute version = rssRoot.getAttribute("version");
57              if (version!=null) {
58                  // At this point, as far ROME is concerned RSS 2.0, 2.00 and 
59                  // 2.0.X are all the same, so let's use startsWith for leniency.
60                  ok = version.getValue().startsWith(getRSSVersion());
61              }
62          }
63          return ok;
64      }
65  
66  }