aktueller Stand
[yacyandroid:yacyandroid.git] / src / net / yacy / rss / RSSFeedParser.java
1 package net.yacy.rss;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.io.StringReader;
6 import java.net.MalformedURLException;
7 import java.net.URL;
8 import java.util.ArrayList;
9 import java.util.Iterator;
10 import java.util.List;
11
12 import org.jdom.Document;
13 import org.jdom.Element;
14 import org.jdom.JDOMException;
15 import org.jdom.Text;
16 import org.jdom.input.SAXBuilder;
17 import org.json.JSONArray;
18 import org.json.JSONException;
19 import org.json.JSONObject;
20 import org.xml.sax.helpers.DefaultHandler;
21
22 import android.content.Context;
23 import android.widget.Toast;
24
25
26 public class RSSFeedParser extends DefaultHandler
27 {
28         static final String TITLE = "title";
29         static final String DESCRIPTION = "description";
30         static final String CHANNEL = "channel";
31         static final String LANGUAGE = "language";
32         static final String COPYRIGHT = "copyright";
33         static final String LINK = "link";
34         static final String AUTHOR = "author";
35         static final String ITEM = "item";
36         static final String PUB_DATE = "pubDate";
37         static final String GUID = "guid";
38
39
40         @SuppressWarnings("null")
41         public Feed readFeed(StringBuilder rss) 
42         {
43                 Feed feed = null;
44                 FeedMessage fm = null;
45                 boolean isFeedHeader = true;
46                 // Set header values intial to the empty string
47                 String description = "";
48                 String title = "";
49                 String link = "";
50                 String language = "";
51                 String copyright = "";
52                 String author = "";
53                 String pubdate = "";
54                 String guid = "";
55                 Document doc = null;
56                 Element root;
57                 Element itemListe;
58                 Element item;
59                 Iterator iter;
60 List liste = null; 
61 JSONArray feld = null;
62 String tmp;
63 Text text;
64                 
65                 SAXBuilder builder = new SAXBuilder();
66                 try
67                 {
68                         // Die Ergebnisse "raussuchen"
69                         doc = builder.build(new StringReader(rss.toString()));
70                         root = doc.getRootElement();
71                         itemListe = root.getChild("channel");
72                         iter = itemListe.getDescendants();
73                         // alle Items auslesen und die Links auslesen
74                         while (iter.hasNext())
75                         {
76                                 fm = new FeedMessage();         // neue Message anlegen
77                                 // Ist Item = Text dann überlesen
78                                 // anderenfalls die Rückgabe füllen
79                                 try
80                                 {
81                                         item = (Element) iter.next();
82 tmp = item.getName();
83 System.out.println("test0");
84                                 }
85                                 catch (Exception e)
86                                 {
87 System.out.println("test1");                    
88                                 }
89 System.out.println("test2");                            
90                         }
91                         
92                 }
93                 catch (JDOMException e)
94                 {
95                         // TODO Auto-generated catch block
96                         e.printStackTrace();
97                 }
98                 catch (IOException e)
99                 {
100                         // TODO Auto-generated catch block
101                         e.printStackTrace();
102                 }
103                         
104         
105                 return feed;
106
107         }
108
109 }