Trim rss version string
This commit is contained in:
parent
0c42383b93
commit
0f804c0ab2
2 changed files with 60 additions and 7 deletions
|
@ -14,14 +14,15 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.rometools.rome.io.impl;
|
package com.rometools.rome.io.impl;
|
||||||
|
|
||||||
|
import com.rometools.rome.feed.rss.Description;
|
||||||
|
|
||||||
import org.jdom2.Attribute;
|
import org.jdom2.Attribute;
|
||||||
import org.jdom2.Document;
|
import org.jdom2.Document;
|
||||||
import org.jdom2.Element;
|
import org.jdom2.Element;
|
||||||
|
|
||||||
import com.rometools.rome.feed.rss.Description;
|
|
||||||
|
|
||||||
public class RSS20Parser extends RSS094Parser {
|
public class RSS20Parser extends RSS094Parser {
|
||||||
|
|
||||||
public RSS20Parser() {
|
public RSS20Parser() {
|
||||||
|
@ -50,11 +51,16 @@ public class RSS20Parser extends RSS094Parser {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMyType(final Document document) {
|
public boolean isMyType(final Document document) {
|
||||||
final Element rssRoot = document.getRootElement();
|
return rootElementMatches(document) && versionMatches(document);
|
||||||
final Attribute version = rssRoot.getAttribute("version");
|
|
||||||
// as far ROME is concerned RSS 2.0, 2.00 and 2.0.X are all the same, so let's use
|
|
||||||
// startsWith for leniency.
|
|
||||||
return rssRoot.getName().equals("rss") && version != null && version.getValue().startsWith(getRSSVersion());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean rootElementMatches(final Document document) {
|
||||||
|
return document.getRootElement().getName().equals("rss");
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean versionMatches(final Document document) {
|
||||||
|
final Attribute version = document.getRootElement().getAttribute("version");
|
||||||
|
return (version != null)
|
||||||
|
&& version.getValue().trim().startsWith(getRSSVersion());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
package com.rometools.rome.io.impl;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import com.rometools.rome.io.WireFeedParser;
|
||||||
|
|
||||||
|
import org.jdom2.Document;
|
||||||
|
import org.jdom2.Element;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class RSS20ParserTest {
|
||||||
|
|
||||||
|
private WireFeedParser parser;
|
||||||
|
private Document document;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
parser = new RSS20Parser();
|
||||||
|
document = new Document();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsMyType() {
|
||||||
|
document.setRootElement(new Element("rss").setAttribute("version", "2.0"));
|
||||||
|
assertTrue(parser.isMyType(document));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsMyTypeNotMyType() {
|
||||||
|
document.setRootElement(new Element("rss").setAttribute("version", "1.0"));
|
||||||
|
assertFalse(parser.isMyType(document));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsMyTypeVersionWithSpaces() {
|
||||||
|
document.setRootElement(new Element("rss").setAttribute("version", " 2.0 "));
|
||||||
|
assertTrue(parser.isMyType(document));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsMyTypeVersionWithTrailingText() {
|
||||||
|
document.setRootElement(new Element("rss").setAttribute("version", "2.0test"));
|
||||||
|
assertTrue(parser.isMyType(document));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue