diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2012-07-23 17:05:34 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2012-07-23 17:05:34 +0200 |
commit | c9197522de26754994c01b5162246ded01413568 (patch) | |
tree | 377ed23f392e7e4c36bd4b907aaed77d7b479850 /src/de/danoeh/antennapod/opml | |
parent | d33b959e1197d1f2968530fe5a8d74842cbe118b (diff) | |
download | AntennaPod-c9197522de26754994c01b5162246ded01413568.zip |
Added chooser activity
Diffstat (limited to 'src/de/danoeh/antennapod/opml')
-rw-r--r-- | src/de/danoeh/antennapod/opml/OpmlReader.java | 95 |
1 files changed, 55 insertions, 40 deletions
diff --git a/src/de/danoeh/antennapod/opml/OpmlReader.java b/src/de/danoeh/antennapod/opml/OpmlReader.java index 82ba38dea..0deed97ea 100644 --- a/src/de/danoeh/antennapod/opml/OpmlReader.java +++ b/src/de/danoeh/antennapod/opml/OpmlReader.java @@ -16,7 +16,7 @@ import android.util.Log; /** Reads OPML documents. */ public class OpmlReader { private static final String TAG = "OpmlReader"; - + // TAGS private static final String OPML = "opml"; private static final String BODY = "body"; @@ -25,54 +25,69 @@ public class OpmlReader { private static final String XMLURL = "xmlUrl"; private static final String HTMLURL = "htmlUrl"; private static final String TYPE = "type"; - + // ATTRIBUTES private boolean isInOpml = false; private boolean isInBody = false; private ArrayList<OpmlElement> elementList; - - /** Reads an Opml document and returns a list of all OPML elements it can find + + /** + * Reads an Opml document and returns a list of all OPML elements it can + * find + * * @throws IOException - * @throws XmlPullParserException*/ - public ArrayList<OpmlElement> readDocument(Reader reader) throws XmlPullParserException, IOException { + * @throws XmlPullParserException + */ + public ArrayList<OpmlElement> readDocument(Reader reader) + throws XmlPullParserException, IOException { elementList = new ArrayList<OpmlElement>(); XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); - factory.setNamespaceAware(true); - XmlPullParser xpp = factory.newPullParser(); - xpp.setInput(reader); - int eventType = xpp.getEventType(); - - while (eventType != XmlPullParser.END_DOCUMENT) { - switch (eventType) { - case XmlPullParser.START_DOCUMENT: - if (AppConfig.DEBUG) Log.d(TAG, "Reached beginning of document"); - break; - case XmlPullParser.START_TAG: - if (xpp.getName().equals(OPML)) { - isInOpml = true; - if (AppConfig.DEBUG) Log.d(TAG, "Reached beginning of OPML tree."); - } else if (isInOpml && xpp.getName().equals(BODY)) { - isInBody = true; - if (AppConfig.DEBUG) Log.d(TAG, "Reached beginning of body tree."); + factory.setNamespaceAware(true); + XmlPullParser xpp = factory.newPullParser(); + xpp.setInput(reader); + int eventType = xpp.getEventType(); + + while (eventType != XmlPullParser.END_DOCUMENT) { + switch (eventType) { + case XmlPullParser.START_DOCUMENT: + if (AppConfig.DEBUG) + Log.d(TAG, "Reached beginning of document"); + break; + case XmlPullParser.START_TAG: + if (xpp.getName().equals(OPML)) { + isInOpml = true; + if (AppConfig.DEBUG) + Log.d(TAG, "Reached beginning of OPML tree."); + } else if (isInOpml && xpp.getName().equals(BODY)) { + isInBody = true; + if (AppConfig.DEBUG) + Log.d(TAG, "Reached beginning of body tree."); + + } else if (isInBody && xpp.getName().equals(OUTLINE)) { + if (AppConfig.DEBUG) + Log.d(TAG, "Found new Opml element"); + OpmlElement element = new OpmlElement(); + element.setText(xpp.getAttributeValue(null, TEXT)); + element.setXmlUrl(xpp.getAttributeValue(null, XMLURL)); + element.setHtmlUrl(xpp.getAttributeValue(null, HTMLURL)); + element.setType(xpp.getAttributeValue(null, TYPE)); + if (element.getXmlUrl() != null) { + elementList.add(element); + } else { + if (AppConfig.DEBUG) + Log.d(TAG, + "Skipping element because of missing xml url"); + } + } + break; + } + eventType = xpp.next(); + } + + if (AppConfig.DEBUG) + Log.d(TAG, "Parsing finished."); - } else if (isInBody && xpp.getName().equals(OUTLINE)) { - if (AppConfig.DEBUG) Log.d(TAG, "Found new Opml element"); - OpmlElement element = new OpmlElement(); - element.setText(xpp.getAttributeValue(null, TEXT)); - element.setXmlUrl(xpp.getAttributeValue(null, XMLURL)); - element.setHtmlUrl(xpp.getAttributeValue(null, HTMLURL)); - element.setType(xpp.getAttributeValue(null, TYPE)); - elementList.add(element); - } - break; - } - eventType = xpp.next(); - } - - if (AppConfig.DEBUG) Log.d(TAG, "Parsing finished."); - return elementList; } - } |