summaryrefslogtreecommitdiff
path: root/src/de/podfetcher/syndication/handler
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2012-06-28 13:28:24 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2012-06-28 13:28:24 +0200
commit3c4167ed498c90363f07c9755247b1ce7211470d (patch)
tree31f86392c0d1e5deefc29f8da529638b25819651 /src/de/podfetcher/syndication/handler
parentfdd5c2dc7e6536f06df053709d383609ecaf9ac1 (diff)
downloadAntennaPod-3c4167ed498c90363f07c9755247b1ce7211470d.zip
Added more error handling when adding new feeds
Diffstat (limited to 'src/de/podfetcher/syndication/handler')
-rw-r--r--src/de/podfetcher/syndication/handler/FeedHandler.java25
-rw-r--r--src/de/podfetcher/syndication/handler/TypeGetter.java6
-rw-r--r--src/de/podfetcher/syndication/handler/UnsupportedFeedtypeException.java29
3 files changed, 41 insertions, 19 deletions
diff --git a/src/de/podfetcher/syndication/handler/FeedHandler.java b/src/de/podfetcher/syndication/handler/FeedHandler.java
index 110ac2b90..f52dcbdec 100644
--- a/src/de/podfetcher/syndication/handler/FeedHandler.java
+++ b/src/de/podfetcher/syndication/handler/FeedHandler.java
@@ -12,25 +12,18 @@ import org.xml.sax.SAXException;
import de.podfetcher.feed.Feed;
public class FeedHandler {
-
-
- public Feed parseFeed(Feed feed) {
+
+ public Feed parseFeed(Feed feed) throws SAXException, IOException,
+ ParserConfigurationException, UnsupportedFeedtypeException {
TypeGetter tg = new TypeGetter();
TypeGetter.Type type = tg.getType(feed);
SyndHandler handler = new SyndHandler(feed, type);
- try {
- SAXParserFactory factory = SAXParserFactory.newInstance();
- factory.setNamespaceAware(true);
- SAXParser saxParser = factory.newSAXParser();
- saxParser.parse(new File(feed.getFile_url()), handler);
- } catch (SAXException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } catch(ParserConfigurationException e) {
- e.printStackTrace();
- }
-
+
+ SAXParserFactory factory = SAXParserFactory.newInstance();
+ factory.setNamespaceAware(true);
+ SAXParser saxParser = factory.newSAXParser();
+ saxParser.parse(new File(feed.getFile_url()), handler);
+
return handler.state.feed;
}
}
diff --git a/src/de/podfetcher/syndication/handler/TypeGetter.java b/src/de/podfetcher/syndication/handler/TypeGetter.java
index 71aa9970d..82bd371de 100644
--- a/src/de/podfetcher/syndication/handler/TypeGetter.java
+++ b/src/de/podfetcher/syndication/handler/TypeGetter.java
@@ -25,7 +25,7 @@ public class TypeGetter {
private static final String ATOM_ROOT = "feed";
private static final String RSS_ROOT = "rss";
- public Type getType(Feed feed) {
+ public Type getType(Feed feed) throws UnsupportedFeedtypeException {
XmlPullParserFactory factory;
try {
factory = XmlPullParserFactory.newInstance();
@@ -47,7 +47,7 @@ public class TypeGetter {
return Type.RSS20;
} else {
Log.d(TAG, "Type is invalid");
- return Type.INVALID;
+ throw new UnsupportedFeedtypeException(Type.INVALID);
}
} else {
eventType = xpp.next();
@@ -60,7 +60,7 @@ public class TypeGetter {
e.printStackTrace();
}
Log.d(TAG, "Type is invalid");
- return Type.INVALID;
+ throw new UnsupportedFeedtypeException(Type.INVALID);
}
private Reader createReader(Feed feed) {
diff --git a/src/de/podfetcher/syndication/handler/UnsupportedFeedtypeException.java b/src/de/podfetcher/syndication/handler/UnsupportedFeedtypeException.java
new file mode 100644
index 000000000..2ca6f02b0
--- /dev/null
+++ b/src/de/podfetcher/syndication/handler/UnsupportedFeedtypeException.java
@@ -0,0 +1,29 @@
+package de.podfetcher.syndication.handler;
+
+import de.podfetcher.syndication.handler.TypeGetter.Type;
+
+public class UnsupportedFeedtypeException extends Exception {
+ private static final long serialVersionUID = 9105878964928170669L;
+ private TypeGetter.Type type;
+
+ public UnsupportedFeedtypeException(Type type) {
+ super();
+ this.type = type;
+
+ }
+
+ public TypeGetter.Type getType() {
+ return type;
+ }
+
+ @Override
+ public String getMessage() {
+ if (type == TypeGetter.Type.INVALID) {
+ return "Invalid type";
+ } else {
+ return "Type " + type + " not supported";
+ }
+ }
+
+
+}