Added value check when feed has been parsed
This commit is contained in:
parent
6254053226
commit
7f100f8072
|
@ -29,6 +29,7 @@ import de.danoeh.antennapod.storage.DownloadRequester;
|
||||||
import de.danoeh.antennapod.syndication.handler.FeedHandler;
|
import de.danoeh.antennapod.syndication.handler.FeedHandler;
|
||||||
import de.danoeh.antennapod.syndication.handler.UnsupportedFeedtypeException;
|
import de.danoeh.antennapod.syndication.handler.UnsupportedFeedtypeException;
|
||||||
import de.danoeh.antennapod.util.DownloadError;
|
import de.danoeh.antennapod.util.DownloadError;
|
||||||
|
import de.danoeh.antennapod.util.InvalidFeedException;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
|
@ -398,6 +399,9 @@ public class DownloadService extends Service {
|
||||||
private Feed feed;
|
private Feed feed;
|
||||||
private DownloadService service;
|
private DownloadService service;
|
||||||
|
|
||||||
|
private int reason;
|
||||||
|
private boolean successful;
|
||||||
|
|
||||||
public FeedSyncThread(Feed feed, DownloadService service) {
|
public FeedSyncThread(Feed feed, DownloadService service) {
|
||||||
this.feed = feed;
|
this.feed = feed;
|
||||||
this.service = service;
|
this.service = service;
|
||||||
|
@ -408,8 +412,8 @@ public class DownloadService extends Service {
|
||||||
long imageId = 0;
|
long imageId = 0;
|
||||||
boolean hasImage = false;
|
boolean hasImage = false;
|
||||||
long downloadId = feed.getDownloadId();
|
long downloadId = feed.getDownloadId();
|
||||||
int reason = 0;
|
reason = 0;
|
||||||
boolean successful = true;
|
successful = true;
|
||||||
FeedManager manager = FeedManager.getInstance();
|
FeedManager manager = FeedManager.getInstance();
|
||||||
FeedHandler handler = new FeedHandler();
|
FeedHandler handler = new FeedHandler();
|
||||||
feed.setDownloaded(true);
|
feed.setDownloaded(true);
|
||||||
|
@ -418,7 +422,9 @@ public class DownloadService extends Service {
|
||||||
feed = handler.parseFeed(feed);
|
feed = handler.parseFeed(feed);
|
||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, feed.getTitle() + " parsed");
|
Log.d(TAG, feed.getTitle() + " parsed");
|
||||||
|
if (checkFeedData(feed) == false) {
|
||||||
|
throw new InvalidFeedException();
|
||||||
|
}
|
||||||
feed.setDownloadId(0);
|
feed.setDownloadId(0);
|
||||||
// Save information of feed in DB
|
// Save information of feed in DB
|
||||||
savedFeed = manager.updateFeed(service, feed);
|
savedFeed = manager.updateFeed(service, feed);
|
||||||
|
@ -447,6 +453,10 @@ public class DownloadService extends Service {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
successful = false;
|
successful = false;
|
||||||
reason = DownloadError.ERROR_UNSUPPORTED_TYPE;
|
reason = DownloadError.ERROR_UNSUPPORTED_TYPE;
|
||||||
|
} catch (InvalidFeedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
successful = false;
|
||||||
|
reason = DownloadError.ERROR_PARSER_EXCEPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
requester.removeDownload(feed);
|
requester.removeDownload(feed);
|
||||||
|
@ -460,6 +470,17 @@ public class DownloadService extends Service {
|
||||||
queryDownloads();
|
queryDownloads();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Checks if the feed was parsed correctly. */
|
||||||
|
private boolean checkFeedData(Feed feed) {
|
||||||
|
if (feed.getTitle() == null) {
|
||||||
|
Log.e(TAG, "Feed has no title.");
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if (AppConfig.DEBUG) Log.d(TAG, "Feed appears to be valid.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Delete files that aren't needed anymore */
|
/** Delete files that aren't needed anymore */
|
||||||
private void cleanup() {
|
private void cleanup() {
|
||||||
if (feed.getFile_url() != null) {
|
if (feed.getFile_url() != null) {
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
package de.danoeh.antennapod.util;
|
||||||
|
|
||||||
|
/** Thrown if a feed has invalid attribute values. */
|
||||||
|
public class InvalidFeedException extends Exception {
|
||||||
|
|
||||||
|
public InvalidFeedException() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public InvalidFeedException(String detailMessage) {
|
||||||
|
super(detailMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InvalidFeedException(Throwable throwable) {
|
||||||
|
super(throwable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InvalidFeedException(String detailMessage, Throwable throwable) {
|
||||||
|
super(detailMessage, throwable);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue