Added content:encoded support

This commit is contained in:
daniel oeh 2012-06-23 22:37:54 +02:00
parent f54593e2c1
commit cdc8adab8d
6 changed files with 78 additions and 4 deletions

View File

@ -83,7 +83,7 @@ public class ItemviewActivity extends SherlockActivity {
.getTime(), System.currentTimeMillis(), DateFormat.MEDIUM,
DateFormat.SHORT));
txtvTitle.setText(item.getTitle());
webvDescription.loadData(item.getDescription(), "text/html", null);
webvDescription.loadData(item.getContentEncoded(), "text/html", null);
}
/* TODO implement

View File

@ -11,6 +11,7 @@ import java.util.Date;
public class FeedItem extends FeedComponent{
private String title;
private String description;
private String contentEncoded;
private String link;
private Date pubDate;
private FeedMedia media;
@ -84,5 +85,14 @@ public class FeedItem extends FeedComponent{
public boolean isRead() {
return read;
}
public String getContentEncoded() {
return contentEncoded;
}
public void setContentEncoded(String contentEncoded) {
this.contentEncoded = contentEncoded;
}
}

View File

@ -76,8 +76,10 @@ public class FeedManager {
launchIntent.putExtra(PlaybackService.EXTRA_MEDIA_ID, media.getId());
launchIntent.putExtra(PlaybackService.EXTRA_FEED_ID, media.getItem()
.getFeed().getId());
launchIntent.putExtra(PlaybackService.EXTRA_START_WHEN_PREPARED, startWhenPrepared);
launchIntent.putExtra(PlaybackService.EXTRA_SHOULD_STREAM, shouldStream);
launchIntent.putExtra(PlaybackService.EXTRA_START_WHEN_PREPARED,
startWhenPrepared);
launchIntent
.putExtra(PlaybackService.EXTRA_SHOULD_STREAM, shouldStream);
context.startService(launchIntent);
if (showPlayer) {
// Launch Mediaplayer
@ -409,6 +411,8 @@ public class FeedManager {
.getColumnIndex(PodDBAdapter.KEY_LINK)));
item.setDescription(itemlistCursor.getString(itemlistCursor
.getColumnIndex(PodDBAdapter.KEY_DESCRIPTION)));
item.setContentEncoded(itemlistCursor.getString(itemlistCursor
.getColumnIndex(PodDBAdapter.KEY_CONTENT_ENCODED)));
item.setPubDate(new Date(itemlistCursor.getLong(itemlistCursor
.getColumnIndex(PodDBAdapter.KEY_PUBDATE))));
item.setMedia(adapter.getFeedMedia(itemlistCursor

View File

@ -51,6 +51,7 @@ public class PodDBAdapter {
public static final String KEY_FEEDFILETYPE = "feedfile_type";
public static final String KEY_COMPLETION_DATE = "completion_date";
public static final String KEY_FEEDITEM = "feeditem";
public static final String KEY_CONTENT_ENCODED = "content_encoded";
// Table names
public static final String TABLE_NAME_FEEDS = "Feeds";
@ -74,6 +75,7 @@ public class PodDBAdapter {
private static final String CREATE_TABLE_FEED_ITEMS = "CREATE TABLE "
+ TABLE_NAME_FEED_ITEMS + " (" + TABLE_PRIMARY_KEY + KEY_TITLE
+ " TEXT," + KEY_LINK + " TEXT," + KEY_DESCRIPTION + " TEXT,"
+ KEY_CONTENT_ENCODED + " TEXT,"
+ KEY_PUBDATE + " INTEGER," + KEY_MEDIA + " INTEGER," + KEY_FEED
+ " INTEGER," + KEY_READ + " INTEGER)";
@ -253,6 +255,7 @@ public class PodDBAdapter {
values.put(KEY_TITLE, item.getTitle());
values.put(KEY_LINK, item.getLink());
values.put(KEY_DESCRIPTION, item.getDescription());
values.put(KEY_CONTENT_ENCODED, item.getContentEncoded());
values.put(KEY_PUBDATE, item.getPubDate().getTime());
if (item.getMedia() != null) {
if (item.getMedia().getId() == 0) {

View File

@ -10,6 +10,7 @@ import de.podfetcher.feed.Feed;
import de.podfetcher.syndication.namespace.Namespace;
import de.podfetcher.syndication.namespace.SyndElement;
import de.podfetcher.syndication.namespace.atom.NSAtom;
import de.podfetcher.syndication.namespace.content.NSContent;
import de.podfetcher.syndication.namespace.rss20.NSRSS20;
/** Superclass for all SAX Handlers which process Syndication formats */
@ -77,13 +78,18 @@ public class SyndHandler extends DefaultHandler {
state.defaultNamespaces.push(new NSAtom());
} else if (prefix.equals(NSAtom.NSTAG)) {
state.namespaces.put(uri, new NSAtom());
Log.d(TAG, "Recognized Atom namespace");
}
} else if (uri.equals(NSContent.NSURI) && prefix.equals(NSContent.NSTAG)) {
state.namespaces.put(uri, new NSContent());
Log.d(TAG, "Recognized Content namespace");
}
}
private Namespace getHandlingNamespace(String uri) {
Namespace handler = state.namespaces.get(uri);
if (handler == null && uri.equals(DEFAULT_PREFIX) &&!state.defaultNamespaces.empty()) {
if (handler == null && uri.equals(DEFAULT_PREFIX)
&& !state.defaultNamespaces.empty()) {
handler = state.defaultNamespaces.peek();
}
return handler;

View File

@ -0,0 +1,51 @@
package de.podfetcher.syndication.namespace.content;
import org.xml.sax.Attributes;
import de.podfetcher.syndication.handler.HandlerState;
import de.podfetcher.syndication.namespace.Namespace;
import de.podfetcher.syndication.namespace.SyndElement;
import de.podfetcher.syndication.namespace.rss20.NSRSS20;
public class NSContent extends Namespace {
public static final String NSTAG = "content";
public static final String NSURI = "http://purl.org/rss/1.0/modules/content/";
private static final String ENCODED = "encoded";
private StringBuffer encoded;
@Override
public SyndElement handleElementStart(String localName, HandlerState state,
Attributes attributes) {
if (localName.equals(ENCODED)) {
encoded = new StringBuffer();
}
return new SyndElement(localName, this);
}
@Override
public void handleCharacters(HandlerState state, char[] ch, int start,
int length) {
if (state.getTagstack().size() >= 2) {
String content = new String(ch, start, length);
SyndElement topElement = state.getTagstack().peek();
String top = topElement.getName();
SyndElement secondElement = state.getSecondTag();
String second = secondElement.getName();
if (top.equals(ENCODED) && second.equals(NSRSS20.ITEM)) {
encoded.append(content);
}
}
}
@Override
public void handleElementEnd(String localName, HandlerState state) {
if (localName.equals(ENCODED)) {
state.getCurrentItem().setContentEncoded(encoded.toString());
encoded = null;
}
}
}