Added value check when feed has been parsed

This commit is contained in:
daniel oeh 2012-08-04 15:20:11 +02:00
parent 6254053226
commit 7f100f8072
2 changed files with 45 additions and 3 deletions

View File

@ -29,6 +29,7 @@ import de.danoeh.antennapod.storage.DownloadRequester;
import de.danoeh.antennapod.syndication.handler.FeedHandler;
import de.danoeh.antennapod.syndication.handler.UnsupportedFeedtypeException;
import de.danoeh.antennapod.util.DownloadError;
import de.danoeh.antennapod.util.InvalidFeedException;
import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.NotificationManager;
@ -398,6 +399,9 @@ public class DownloadService extends Service {
private Feed feed;
private DownloadService service;
private int reason;
private boolean successful;
public FeedSyncThread(Feed feed, DownloadService service) {
this.feed = feed;
this.service = service;
@ -408,8 +412,8 @@ public class DownloadService extends Service {
long imageId = 0;
boolean hasImage = false;
long downloadId = feed.getDownloadId();
int reason = 0;
boolean successful = true;
reason = 0;
successful = true;
FeedManager manager = FeedManager.getInstance();
FeedHandler handler = new FeedHandler();
feed.setDownloaded(true);
@ -418,7 +422,9 @@ public class DownloadService extends Service {
feed = handler.parseFeed(feed);
if (AppConfig.DEBUG)
Log.d(TAG, feed.getTitle() + " parsed");
if (checkFeedData(feed) == false) {
throw new InvalidFeedException();
}
feed.setDownloadId(0);
// Save information of feed in DB
savedFeed = manager.updateFeed(service, feed);
@ -447,6 +453,10 @@ public class DownloadService extends Service {
e.printStackTrace();
successful = false;
reason = DownloadError.ERROR_UNSUPPORTED_TYPE;
} catch (InvalidFeedException e) {
e.printStackTrace();
successful = false;
reason = DownloadError.ERROR_PARSER_EXCEPTION;
}
requester.removeDownload(feed);
@ -460,6 +470,17 @@ public class DownloadService extends Service {
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 */
private void cleanup() {
if (feed.getFile_url() != null) {

View File

@ -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);
}
}