Print log

This commit is contained in:
Martin Fietz 2016-03-08 09:47:04 +01:00
parent 5e7b328d83
commit d0126b54f1
7 changed files with 84 additions and 97 deletions

View File

@ -328,6 +328,7 @@ public class OnlineFeedViewActivity extends ActionBarActivity {
subscriber.onError(e);
}
} catch (Exception e) {
Log.e(TAG, Log.getStackTraceString(e));
subscriber.onError(e);
} finally {
boolean rc = new File(feed.getFile_url()).delete();

View File

@ -2,8 +2,6 @@ package de.danoeh.antennapod.core.syndication.namespace;
import org.xml.sax.Attributes;
import java.util.Stack;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.syndication.handler.HandlerState;
import de.danoeh.antennapod.core.util.DateUtils;
@ -24,14 +22,10 @@ public class NSDublinCore extends Namespace {
@Override
public void handleElementEnd(String localName, HandlerState state) {
if (state.getCurrentItem() != null && state.getTagstack().size() >= 2 &&
state.getContentBuf() != null) {
if (state.getCurrentItem() != null && state.getContentBuf() != null &&
state.getTagstack() != null && state.getTagstack().size() >= 2) {
FeedItem currentItem = state.getCurrentItem();
Stack<SyndElement> tagStack = state.getTagstack();
if(tagStack.size() < 2) {
return;
}
String top = tagStack.peek().getName();
String top = state.getTagstack().peek().getName();
String second = state.getSecondTag().getName();
if (DATE.equals(top) && ITEM.equals(second)) {
String content = state.getContentBuf().toString();
@ -39,4 +33,5 @@ public class NSDublinCore extends Namespace {
}
}
}
}

View File

@ -52,18 +52,15 @@ public class NSITunes extends Namespace {
@Override
public void handleElementEnd(String localName, HandlerState state) {
if(state.getContentBuf() == null) {
return;
}
if (AUTHOR.equals(localName)) {
if (state.getContentBuf() != null && state.getFeed() != null) {
if (state.getFeed() != null) {
String author = state.getContentBuf().toString();
if(TextUtils.isEmpty(author)) {
return;
}
state.getFeed().setAuthor(author);
}
} else if (DURATION.equals(localName)) {
if (state.getContentBuf() == null) {
return;
}
String duration = state.getContentBuf().toString();
if(TextUtils.isEmpty(duration)) {
return;
@ -86,9 +83,6 @@ public class NSITunes extends Namespace {
Log.e(NSTAG, Log.getStackTraceString(e));
}
} else if (SUBTITLE.equals(localName)) {
if (state.getContentBuf() == null) {
return;
}
String subtitle = state.getContentBuf().toString();
if (TextUtils.isEmpty(subtitle)) {
return;
@ -103,9 +97,6 @@ public class NSITunes extends Namespace {
}
}
} else if (SUMMARY.equals(localName)) {
if (state.getContentBuf() == null) {
return;
}
String summary = state.getContentBuf().toString();
if (TextUtils.isEmpty(summary)) {
return;

View File

@ -1,5 +1,6 @@
package de.danoeh.antennapod.core.syndication.namespace;
import android.text.TextUtils;
import android.util.Log;
import org.xml.sax.Attributes;
@ -29,11 +30,15 @@ public class NSMedia extends Namespace {
if (CONTENT.equals(localName)) {
String url = attributes.getValue(DOWNLOAD_URL);
String type = attributes.getValue(MIME_TYPE);
if (state.getCurrentItem() != null && state.getCurrentItem().getMedia() == null
&& url != null
&& (SyndTypeUtils.enclosureTypeValid(type) || ((type = SyndTypeUtils
.getValidMimeTypeFromUrl(url)) != null))) {
boolean validType;
if(SyndTypeUtils.enclosureTypeValid(type)) {
validType = true;
} else {
type = SyndTypeUtils.getValidMimeTypeFromUrl(url);
validType = type != null;
}
if (state.getCurrentItem() != null && state.getCurrentItem().getMedia() == null &&
url != null && validType) {
long size = 0;
try {
size = Long.parseLong(attributes.getValue(SIZE));
@ -41,19 +46,19 @@ public class NSMedia extends Namespace {
Log.e(TAG, "Length attribute could not be parsed.");
}
int duration = 0;
int durationMs = 0;
String durationStr = attributes.getValue(DURATION);
if (durationStr != null) {
if (!TextUtils.isEmpty(durationStr)) {
try {
duration = (int) TimeUnit.MILLISECONDS.convert(
Long.parseLong(durationStr), TimeUnit.SECONDS);
long duration = Long.parseLong(durationStr);
durationMs = (int) TimeUnit.MILLISECONDS.convert(duration, TimeUnit.SECONDS);
} catch (NumberFormatException e) {
Log.e(TAG, "Duration attribute could not be parsed");
}
}
FeedMedia media = new FeedMedia(state.getCurrentItem(), url, size, type);
if(duration > 0) {
media.setDuration(duration);
if(durationMs > 0) {
media.setDuration(durationMs);
}
state.getCurrentItem().setMedia(media);
}

View File

@ -51,10 +51,15 @@ public class NSRSS20 extends Namespace {
} else if (ENCLOSURE.equals(localName)) {
String type = attributes.getValue(ENC_TYPE);
String url = attributes.getValue(ENC_URL);
boolean validType;
if(SyndTypeUtils.enclosureTypeValid(type)) {
validType = true;
} else {
type = type = SyndTypeUtils.getValidMimeTypeFromUrl(url);
validType = type != null;
}
if (state.getCurrentItem() != null && state.getCurrentItem().getMedia() == null &&
(SyndTypeUtils.enclosureTypeValid(type) || ((type = SyndTypeUtils
.getValidMimeTypeFromUrl(url)) != null))) {
validType) {
long size = 0;
try {
size = Long.parseLong(attributes.getValue(ENC_LEN));
@ -115,7 +120,6 @@ public class NSRSS20 extends Namespace {
if (state.getTagstack().size() >= 3) {
third = state.getThirdTag().getName();
}
if (GUID.equals(top) && ITEM.equals(second)) {
// some feed creators include an empty or non-standard guid-element in their feed, which should be ignored
if (!TextUtils.isEmpty(content) && state.getCurrentItem() != null) {
@ -127,7 +131,7 @@ public class NSRSS20 extends Namespace {
state.getCurrentItem().setTitle(title);
} else if (CHANNEL.equals(second) && state.getFeed() != null) {
state.getFeed().setTitle(title);
} else if (IMAGE.equals(second) && third != null && CHANNEL.equals(third)) {
} else if (IMAGE.equals(second) && CHANNEL.equals(third)) {
if(state.getFeed() != null && state.getFeed().getImage() != null &&
state.getFeed().getImage().getTitle() == null) {
state.getFeed().getImage().setTitle(title);
@ -141,8 +145,7 @@ public class NSRSS20 extends Namespace {
}
} else if (PUBDATE.equals(top) && ITEM.equals(second) && state.getCurrentItem() != null) {
state.getCurrentItem().setPubDate(DateUtils.parse(content));
} else if (URL.equals(top) && IMAGE.equals(second) && third != null
&& CHANNEL.equals(third)) {
} else if (URL.equals(top) && IMAGE.equals(second) && CHANNEL.equals(third)) {
// prefer itunes:image
if(state.getFeed() != null && state.getFeed().getImage() != null &&
state.getFeed().getImage().getDownload_url() == null) {

View File

@ -1,5 +1,6 @@
package de.danoeh.antennapod.core.syndication.namespace.atom;
import android.text.TextUtils;
import android.util.Log;
import org.xml.sax.Attributes;
@ -65,21 +66,21 @@ public class NSAtom extends Namespace {
@Override
public SyndElement handleElementStart(String localName, HandlerState state,
Attributes attributes) {
if (localName.equals(ENTRY)) {
if (ENTRY.equals(localName)) {
state.setCurrentItem(new FeedItem());
state.getItems().add(state.getCurrentItem());
state.getCurrentItem().setFeed(state.getFeed());
} else if (localName.matches(isText)) {
String type = attributes.getValue(TEXT_TYPE);
return new AtomText(localName, this, type);
} else if (localName.equals(LINK)) {
} else if (LINK.equals(localName)) {
String href = attributes.getValue(LINK_HREF);
String rel = attributes.getValue(LINK_REL);
SyndElement parent = state.getTagstack().peek();
if (parent.getName().matches(isFeedItem)) {
if (rel == null || rel.equals(LINK_REL_ALTERNATE)) {
if (LINK_REL_ALTERNATE.equals(rel)) {
state.getCurrentItem().setLink(href);
} else if (rel.equals(LINK_REL_ENCLOSURE)) {
} else if (LINK_REL_ENCLOSURE.equals(rel)) {
String strSize = attributes.getValue(LINK_LENGTH);
long size = 0;
try {
@ -90,40 +91,45 @@ public class NSAtom extends Namespace {
Log.d(TAG, "Length attribute could not be parsed.");
}
String type = attributes.getValue(LINK_TYPE);
if (SyndTypeUtils.enclosureTypeValid(type)
|| (type = SyndTypeUtils.getValidMimeTypeFromUrl(href)) != null) {
boolean validType;
if(SyndTypeUtils.enclosureTypeValid(type)) {
validType = true;
} else {
type = SyndTypeUtils.getValidMimeTypeFromUrl(href);
validType = type != null;
}
if (validType) {
FeedItem currItem = state.getCurrentItem();
if(!currItem.hasMedia()) {
if(currItem != null && !currItem.hasMedia()) {
currItem.setMedia(new FeedMedia(currItem, href, size, type));
}
}
} else if (rel.equals(LINK_REL_PAYMENT)) {
} else if (LINK_REL_PAYMENT.equals(rel)) {
state.getCurrentItem().setPaymentLink(href);
}
} else if (parent.getName().matches(isFeed)) {
if (rel == null || rel.equals(LINK_REL_ALTERNATE)) {
if (LINK_REL_ALTERNATE.equals(rel)) {
String type = attributes.getValue(LINK_TYPE);
/*
* Use as link if a) no type-attribute is given and
* feed-object has no link yet b) type of link is
* LINK_TYPE_HTML or LINK_TYPE_XHTML
*/
if ((type == null && state.getFeed().getLink() == null)
|| (type != null && (type.equals(LINK_TYPE_HTML)
|| type.equals(LINK_TYPE_XHTML)))) {
if (state.getFeed() != null &&
((type == null && state.getFeed().getLink() == null) ||
(LINK_TYPE_HTML.equals(type) || LINK_TYPE_XHTML.equals(type)))) {
state.getFeed().setLink(href);
} else if (type != null && (type.equals(LINK_TYPE_ATOM)
|| type.equals(LINK_TYPE_RSS))) {
} else if (LINK_TYPE_ATOM.equals(type) || LINK_TYPE_RSS.equals(type)) {
// treat as podlove alternate feed
String title = attributes.getValue(LINK_TITLE);
if (title == null) {
if (TextUtils.isEmpty(title)) {
title = href;
}
state.addAlternateFeedUrl(title, href);
}
} else if (rel.equals(LINK_REL_PAYMENT)) {
} else if (LINK_REL_PAYMENT.equals(rel) && state.getFeed() != null) {
state.getFeed().setPaymentLink(href);
} else if (rel.equals(LINK_REL_NEXT)) {
} else if (LINK_REL_NEXT.equals(rel) && state.getFeed() != null) {
state.getFeed().setPaged(true);
state.getFeed().setNextPageLink(href);
}
@ -134,11 +140,13 @@ public class NSAtom extends Namespace {
@Override
public void handleElementEnd(String localName, HandlerState state) {
if (localName.equals(ENTRY)) {
if (ENTRY.equals(localName)) {
if (state.getCurrentItem() != null &&
state.getTempObjects().containsKey(NSITunes.DURATION)) {
if (state.getCurrentItem().hasMedia()) {
state.getCurrentItem().getMedia().setDuration((Integer) state.getTempObjects().get(NSITunes.DURATION));
FeedItem currentItem = state.getCurrentItem();
if (currentItem.hasMedia()) {
Integer duration = (Integer) state.getTempObjects().get(NSITunes.DURATION);
currentItem.getMedia().setDuration(duration);
}
state.getTempObjects().remove(NSITunes.DURATION);
}
@ -163,47 +171,32 @@ public class NSAtom extends Namespace {
textElement.setContent(content);
}
if (top.equals(ID)) {
if (second.equals(FEED)) {
if (ID.equals(top)) {
if (FEED.equals(second) && state.getFeed() != null) {
state.getFeed().setFeedIdentifier(content);
} else if (second.equals(ENTRY)) {
} else if (ENTRY.equals(second) && state.getCurrentItem() != null) {
state.getCurrentItem().setItemIdentifier(content);
}
} else if (top.equals(TITLE)) {
if (second.equals(FEED)) {
} else if (TITLE.equals(top) && textElement != null) {
if (FEED.equals(second) && state.getFeed() != null) {
state.getFeed().setTitle(textElement.getProcessedContent());
} else if (second.equals(ENTRY)) {
state.getCurrentItem().setTitle(
textElement.getProcessedContent());
}
} else if (top.equals(SUBTITLE)) {
if (second.equals(FEED)) {
state.getFeed().setDescription(
textElement.getProcessedContent());
}
} else if (top.equals(CONTENT)) {
if (second.equals(ENTRY)) {
state.getCurrentItem().setDescription(
textElement.getProcessedContent());
}
} else if (top.equals(UPDATED)) {
if (second.equals(ENTRY)
&& state.getCurrentItem().getPubDate() == null) {
state.getCurrentItem().setPubDate(
DateUtils.parse(content));
}
} else if (top.equals(PUBLISHED)) {
if (second.equals(ENTRY)) {
state.getCurrentItem().setPubDate(
DateUtils.parse(content));
}
} else if (top.equals(IMAGE)) {
if(state.getFeed().getImage() == null) {
state.getFeed().setImage(new FeedImage(state.getFeed(), content, null));
} else if (ENTRY.equals(second) && state.getCurrentItem() != null) {
state.getCurrentItem().setTitle(textElement.getProcessedContent());
}
} else if (SUBTITLE.equals(top) && FEED.equals(second) && textElement != null &&
state.getFeed() != null) {
state.getFeed().setDescription(textElement.getProcessedContent());
} else if (CONTENT.equals(top) && ENTRY.equals(second) && textElement != null &&
state.getCurrentItem() != null) {
state.getCurrentItem().setDescription(textElement.getProcessedContent());
} else if (UPDATED.equals(top) && ENTRY.equals(second) && state.getCurrentItem() != null &&
state.getCurrentItem().getPubDate() == null) {
state.getCurrentItem().setPubDate(DateUtils.parse(content));
} else if (PUBLISHED.equals(top) && ENTRY.equals(second) && state.getCurrentItem() != null) {
state.getCurrentItem().setPubDate(DateUtils.parse(content));
} else if (IMAGE.equals(top) && state.getFeed() != null && state.getFeed().getImage() == null) {
state.getFeed().setImage(new FeedImage(state.getFeed(), content, null));
}
}
}

View File

@ -30,8 +30,7 @@ public class SyndTypeUtils {
if (url != null) {
String extension = FilenameUtils.getExtension(url);
if (extension != null) {
String type = MimeTypeMap.getSingleton()
.getMimeTypeFromExtension(extension);
String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
if (type != null && enclosureTypeValid(type)) {
return type;
}