Merge pull request #274 from mishako/rss-2-by-default
Use RSS2 parser as fallback when no version is set
This commit is contained in:
commit
a058deb267
2 changed files with 12 additions and 1 deletions
|
@ -51,7 +51,8 @@ public class RSS20Parser extends RSS094Parser {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMyType(final Document document) {
|
public boolean isMyType(final Document document) {
|
||||||
return rootElementMatches(document) && versionMatches(document);
|
return rootElementMatches(document)
|
||||||
|
&& (versionMatches(document) || versionAbsent(document));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean rootElementMatches(final Document document) {
|
private boolean rootElementMatches(final Document document) {
|
||||||
|
@ -63,4 +64,8 @@ public class RSS20Parser extends RSS094Parser {
|
||||||
return (version != null)
|
return (version != null)
|
||||||
&& version.getValue().trim().startsWith(getRSSVersion());
|
&& version.getValue().trim().startsWith(getRSSVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean versionAbsent(final Document document) {
|
||||||
|
return document.getRootElement().getAttribute("version") == null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,4 +44,10 @@ public class RSS20ParserTest {
|
||||||
document.setRootElement(new Element("rss").setAttribute("version", "2.0test"));
|
document.setRootElement(new Element("rss").setAttribute("version", "2.0test"));
|
||||||
assertTrue(parser.isMyType(document));
|
assertTrue(parser.isMyType(document));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsMyTypeVersionAbsent() {
|
||||||
|
document.setRootElement(new Element("rss"));
|
||||||
|
assertTrue(parser.isMyType(document));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue