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.Category;
21  import com.sun.syndication.feed.rss.Channel;
22  import com.sun.syndication.feed.rss.Cloud;
23  import com.sun.syndication.feed.rss.Description;
24  import com.sun.syndication.feed.rss.Enclosure;
25  import com.sun.syndication.feed.rss.Item;
26  import com.sun.syndication.feed.rss.Source;
27  import org.jdom.Element;
28  
29  import java.util.ArrayList;
30  import java.util.List;
31  
32  /***
33   */
34  public class RSS092Parser extends RSS091Parser {
35  
36      public RSS092Parser() {
37          this("rss_0.92");
38      }
39  
40      protected RSS092Parser(String type) {
41          super(type);
42      }
43  
44      protected String getRSSVersion() {
45              return "0.92";
46      }
47  
48      protected WireFeed parseChannel(Element rssRoot)  {
49          Channel channel = (Channel) super.parseChannel(rssRoot);
50  
51          Element eCloud = rssRoot.getChild("cloud",getRSSNamespace());
52          if (eCloud!=null) {
53              Cloud cloud = new Cloud();
54              String att = eCloud.getAttributeValue("domain");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
55              if (att!=null) {
56                  cloud.setDomain(att);
57              }
58              att = eCloud.getAttributeValue("port");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
59              if (att!=null) {
60                  cloud.setPort(Integer.parseInt(att));
61              }
62              att = eCloud.getAttributeValue("registerProcedure");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
63              if (att!=null) {
64                  cloud.setRegisterProcedure(att);
65              }
66              att = eCloud.getAttributeValue("protocol");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
67              if (att!=null) {
68                  cloud.setProtocol(att);
69              }
70          }
71          return channel;
72      }
73  
74      protected Item parseItem(Element rssRoot,Element eItem) {
75          Item item = super.parseItem(rssRoot,eItem);
76  
77          Element e = eItem.getChild("source",getRSSNamespace());
78          if (e!=null) {
79              Source source = new Source();
80              String url = e.getAttributeValue("url");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
81              source.setUrl(url);
82              source.setValue(e.getText());
83              item.setSource(source);
84          }
85  
86          // 0.92 allows one enclosure occurrence, 0.93 multiple
87          // just saving to write some code.
88          List eEnclosures = eItem.getChildren("enclosure");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
89          if (eEnclosures.size()>0) {
90              List enclosures = new ArrayList();
91              for (int i=0;i<eEnclosures.size();i++) {
92                  e = (Element) eEnclosures.get(i);
93  
94                  Enclosure enclosure = new Enclosure();
95                  String att = e.getAttributeValue("url");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
96                  if (att!=null) {
97                      enclosure.setUrl(att);
98                  }
99                  att = e.getAttributeValue("length");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
100                 if (att!=null) {
101                     enclosure.setLength(Integer.parseInt(att));
102                 }
103                 att = e.getAttributeValue("type");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
104                 if (att!=null) {
105                     enclosure.setUrl(att);
106                 }
107                 enclosures.add(enclosure);
108             }
109             item.setEnclosures(enclosures);
110         }
111 
112         List eCats = eItem.getChildren("category");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
113         item.setCategories(parseCategories(eCats));
114 
115         return item;
116     }
117 
118     protected List parseCategories(List eCats) {
119         List cats = null;
120         if (eCats.size()>0) {
121             cats = new ArrayList();
122             for (int i=0;i<eCats.size();i++) {
123                 Category cat = new Category();
124                 Element e = (Element) eCats.get(i);
125                 String att = e.getAttributeValue("domain");//getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
126                 if (att!=null) {
127                     cat.setDomain(att);
128                 }
129                 cat.setValue(e.getText());
130                 cats.add(cat);
131             }
132         }
133         return cats;
134     }
135 
136     protected Description parseItemDescription(Element rssRoot,Element eDesc) {
137         Description desc = super.parseItemDescription(rssRoot,eDesc);
138         desc.setType("text/html");
139         return desc;
140     }
141 
142 }