diff options
Diffstat (limited to 'src/de/podfetcher/syndication/handler')
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"; + } + } + + +} |