Fixed bug when parsing enclosures

This commit is contained in:
daniel oeh 2012-07-04 10:45:17 +02:00
parent 0c60b8edf0
commit f81f3972ba
1 changed files with 14 additions and 7 deletions

View File

@ -41,6 +41,8 @@ public class NSRSS20 extends Namespace {
public final static String ENC_LEN = "length"; public final static String ENC_LEN = "length";
public final static String ENC_TYPE = "type"; public final static String ENC_TYPE = "type";
public final static String VALID_MIMETYPE = "audio/.*" + "|" + "video/.*";
@Override @Override
public SyndElement handleElementStart(String localName, HandlerState state, public SyndElement handleElementStart(String localName, HandlerState state,
Attributes attributes) { Attributes attributes) {
@ -50,12 +52,16 @@ public class NSRSS20 extends Namespace {
state.getCurrentItem().setFeed(state.getFeed()); state.getCurrentItem().setFeed(state.getFeed());
} else if (localName.equals(ENCLOSURE)) { } else if (localName.equals(ENCLOSURE)) {
state.getCurrentItem() String type = attributes.getValue(ENC_TYPE);
.setMedia( if (state.getCurrentItem().getMedia() == null
new FeedMedia(state.getCurrentItem(), attributes && (type.matches(VALID_MIMETYPE))) {
.getValue(ENC_URL), Long state.getCurrentItem().setMedia(
.parseLong(attributes.getValue(ENC_LEN)), new FeedMedia(state.getCurrentItem(), attributes
attributes.getValue(ENC_TYPE))); .getValue(ENC_URL), Long.parseLong(attributes
.getValue(ENC_LEN)), attributes
.getValue(ENC_TYPE)));
}
} else if (localName.equals(IMAGE)) { } else if (localName.equals(IMAGE)) {
state.getFeed().setImage(new FeedImage()); state.getFeed().setImage(new FeedImage());
} }
@ -66,7 +72,8 @@ public class NSRSS20 extends Namespace {
public void handleElementEnd(String localName, HandlerState state) { public void handleElementEnd(String localName, HandlerState state) {
if (localName.equals(ITEM)) { if (localName.equals(ITEM)) {
state.setCurrentItem(null); state.setCurrentItem(null);
} else if (state.getTagstack().size() >= 2 && state.getContentBuf() != null) { } else if (state.getTagstack().size() >= 2
&& state.getContentBuf() != null) {
String content = state.getContentBuf().toString(); String content = state.getContentBuf().toString();
SyndElement topElement = state.getTagstack().peek(); SyndElement topElement = state.getTagstack().peek();
String top = topElement.getName(); String top = topElement.getName();