removed 'catch' added check for null
This commit is contained in:
parent
b51aaf2a92
commit
6321136271
|
@ -18,7 +18,7 @@ import de.danoeh.antennapod.feed.Feed;
|
||||||
/** Gets the type of a specific feed by reading the root element. */
|
/** Gets the type of a specific feed by reading the root element. */
|
||||||
public class TypeGetter {
|
public class TypeGetter {
|
||||||
private static final String TAG = "TypeGetter";
|
private static final String TAG = "TypeGetter";
|
||||||
|
|
||||||
enum Type {
|
enum Type {
|
||||||
RSS20, ATOM, INVALID
|
RSS20, ATOM, INVALID
|
||||||
}
|
}
|
||||||
|
@ -28,39 +28,45 @@ public class TypeGetter {
|
||||||
|
|
||||||
public Type getType(Feed feed) throws UnsupportedFeedtypeException {
|
public Type getType(Feed feed) throws UnsupportedFeedtypeException {
|
||||||
XmlPullParserFactory factory;
|
XmlPullParserFactory factory;
|
||||||
try {
|
if (feed.getFile_url() != null) {
|
||||||
factory = XmlPullParserFactory.newInstance();
|
try {
|
||||||
factory.setNamespaceAware(true);
|
factory = XmlPullParserFactory.newInstance();
|
||||||
XmlPullParser xpp = factory.newPullParser();
|
factory.setNamespaceAware(true);
|
||||||
xpp.setInput(createReader(feed));
|
XmlPullParser xpp = factory.newPullParser();
|
||||||
int eventType = xpp.getEventType();
|
xpp.setInput(createReader(feed));
|
||||||
|
int eventType = xpp.getEventType();
|
||||||
while (eventType != XmlPullParser.END_DOCUMENT) {
|
|
||||||
if (eventType == XmlPullParser.START_TAG) {
|
|
||||||
String tag = xpp.getName();
|
|
||||||
if (tag.equals(ATOM_ROOT)) {
|
|
||||||
if (AppConfig.DEBUG) Log.d(TAG, "Recognized type Atom");
|
|
||||||
return Type.ATOM;
|
|
||||||
} else if (tag.equals(RSS_ROOT)
|
|
||||||
&& (xpp.getAttributeValue(null, "version")
|
|
||||||
.equals("2.0"))) {
|
|
||||||
if (AppConfig.DEBUG) Log.d(TAG, "Recognized type RSS 2.0");
|
|
||||||
return Type.RSS20;
|
|
||||||
} else {
|
|
||||||
if (AppConfig.DEBUG) Log.d(TAG, "Type is invalid");
|
|
||||||
throw new UnsupportedFeedtypeException(Type.INVALID);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
eventType = xpp.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (XmlPullParserException e) {
|
while (eventType != XmlPullParser.END_DOCUMENT) {
|
||||||
e.printStackTrace();
|
if (eventType == XmlPullParser.START_TAG) {
|
||||||
} catch (IOException e) {
|
String tag = xpp.getName();
|
||||||
e.printStackTrace();
|
if (tag.equals(ATOM_ROOT)) {
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Recognized type Atom");
|
||||||
|
return Type.ATOM;
|
||||||
|
} else if (tag.equals(RSS_ROOT)
|
||||||
|
&& (xpp.getAttributeValue(null, "version")
|
||||||
|
.equals("2.0"))) {
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Recognized type RSS 2.0");
|
||||||
|
return Type.RSS20;
|
||||||
|
} else {
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Type is invalid");
|
||||||
|
throw new UnsupportedFeedtypeException(Type.INVALID);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eventType = xpp.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (XmlPullParserException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (AppConfig.DEBUG) Log.d(TAG, "Type is invalid");
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Type is invalid");
|
||||||
throw new UnsupportedFeedtypeException(Type.INVALID);
|
throw new UnsupportedFeedtypeException(Type.INVALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,9 +77,6 @@ public class TypeGetter {
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
} catch (NullPointerException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
return reader;
|
return reader;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue