parsing of description for RSS 0.92+ enhanced, so some invalid html

content is handled (fixes #137)
This commit is contained in:
Martin Kurz 2013-10-09 17:07:43 +02:00
parent c164882a12
commit 42a9f870dc
5 changed files with 148 additions and 16 deletions

View file

@ -19,7 +19,9 @@ package com.sun.syndication.io.impl;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.jdom2.Content;
import org.jdom2.Element; import org.jdom2.Element;
import org.jdom2.output.XMLOutputter;
import com.sun.syndication.feed.WireFeed; import com.sun.syndication.feed.WireFeed;
import com.sun.syndication.feed.rss.Category; import com.sun.syndication.feed.rss.Category;
@ -166,8 +168,33 @@ public class RSS092Parser extends RSS091UserlandParser {
@Override @Override
protected Description parseItemDescription(final Element rssRoot, final Element eDesc) { protected Description parseItemDescription(final Element rssRoot, final Element eDesc) {
final Description desc = super.parseItemDescription(rssRoot, eDesc); final Description desc = new Description();
desc.setType("text/html"); final StringBuilder sb = new StringBuilder();
final XMLOutputter xmlOut = new XMLOutputter();
for (final Content c : eDesc.getContent()) {
switch (c.getCType()) {
case Text:
case CDATA:
sb.append(c.getValue());
break;
case EntityRef:
System.out.println("entity: " + c.getValue());
sb.append(c.getValue());
break;
case Element:
sb.append(xmlOut.outputString((Element) c));
break;
default:
// ignore
break;
}
}
desc.setValue(sb.toString());
String att = eDesc.getAttributeValue("type");
if (att == null) {
att = "text/html";
}
desc.setType(att);
return desc; return desc;
} }

View file

@ -98,16 +98,4 @@ public class RSS094Parser extends RSS093Parser {
return item; return item;
} }
@Override
protected Description parseItemDescription(final Element rssRoot, final Element eDesc) {
final Description desc = super.parseItemDescription(rssRoot, eDesc);
String att = eDesc.getAttributeValue("type");// getRSSNamespace()); DONT
// KNOW WHY DOESN'T WORK
if (att == null) {
att = "text/html";
}
desc.setType(att);
return desc;
}
} }

View file

@ -47,8 +47,6 @@ public class RSS20Parser extends RSS094Parser {
@Override @Override
protected Description parseItemDescription(final Element rssRoot, final Element eDesc) { protected Description parseItemDescription(final Element rssRoot, final Element eDesc) {
final Description desc = super.parseItemDescription(rssRoot, eDesc); final Description desc = super.parseItemDescription(rssRoot, eDesc);
desc.setType("text/html"); // change as per
// https://rome.dev.java.net/issues/show_bug.cgi?id=26
return desc; return desc;
} }

View file

@ -0,0 +1,39 @@
package com.sun.syndication.unittest.issues;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.unittest.FeedTest;
/**
* Test for #137: RSS item description is not complete.
* @author Martin Kurz
*
*/
public class Issue137Test extends FeedTest {
public Issue137Test() {
super("issue137-rss.xml");
}
public void testDescription() throws Exception {
final SyndFeed feed = this.getCachedSyndFeed();
assertEquals("<img src=\"http://www.moe.gov.sg/media/spotlight/assets_c/2009/09/spotlight-single-session-thumb-120x80-282.jpg\"" +
" alt=\"Teacher and his students tossing frisbees into the air\" /><p>MOE will be <a href\n"+
"=\"http://www.moe.gov.sg/media/press/2009/09/moe-to-build-new-primary-schoo.php\">building 11 new primary\n"+
" schools and upgrading another 28 existing schools from November 2009</a>. This is the first phase of\n"+
" MOE's plans to enhance primary school infrastructure to facilitate the transition of all primary schools\n"+
" to a single-session model to support a higher quality primary education.</p>", feed.getEntries().get(0).getDescription().getValue());
assertEquals("<img src=\"http://www.moe.gov.sg/media/spotlight/assets_c/2009/09/spotlight-wps-thumb-120x80-280\n"+
".jpg\" alt=\"Minister speaking at WPS 2009\" /><p>At the Work Plan Seminar 2009, Minister for Education\n"+
" Dr Ng Eng Hen <a href=\"http://www.moe.gov.sg/media/speeches/2009/09/17/work-plan-seminar.php\">talked\n"+
" about the importance of language &#38; communication skills and growing a world-class education service\n"+
"</a>. He spoke of <a href=\"http://www.moe.gov.sg/media/press/2009/09/teachers-the-heart-of-quality.php\"\n"+
">strengthening the teaching track and of a teacher-driven culture of professional excellence</a>.</p\n"+
">", feed.getEntries().get(1).getDescription().getValue());
assertEquals("<img src=\"http://www.moe.gov.sg/media/spotlight/assets_c/2009/09/spotlight-moa-2009-thumb-120x80-278"+
".jpg\" alt=\"Students at a podcast session\" />\n <p>A total of 275 schools will <a href=\"http:/"+
"/www.moe.gov.sg/media/press/2009/09/recognising-school-achievement.php\">receive 580 Special and Level\n"+
" Two Awards this year under the MOE Masterplan of Awards</a>. These awards will be presented at the 2009\n"+
" MOE Work Plan Seminar on 17 Sep 09 by the Minister for Education, Dr Ng Eng Hen.</p>", feed.getEntries().get(2).getDescription().getValue());
}
}

View file

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type
="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:feedburner
="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
<channel>
<title>Spotlight</title>
<link>http://www.moe.gov.sg/media/spotlight/</link>
<description />
<language>en</language>
<copyright>Copyright 2009</copyright>
<lastBuildDate>Fri, 25 Sep 2009 10:00:00 +0800</lastBuildDate>
<docs>http://www.rssboard.org/rss-specification</docs>
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner
.com/singapore-education/spotlight" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www
.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
<title>Single-Session Primary Schools</title>
<description><img src="http://www.moe.gov.sg/media/spotlight/assets_c/2009/09/spotlight-single-session-thumb-120x80-282.jpg" alt="Teacher and his students tossing frisbees into the air" /><![CDATA[<p>MOE will be <a href
="http://www.moe.gov.sg/media/press/2009/09/moe-to-build-new-primary-schoo.php">building 11 new primary
schools and upgrading another 28 existing schools from November 2009</a>. This is the first phase of
MOE's plans to enhance primary school infrastructure to facilitate the transition of all primary schools
to a single-session model to support a higher quality primary education.</p>]]></description>
<link>http://feedproxy.google.com/~r/singapore-education/spotlight/~3/vnNsA4Hdk6U/</link
>
<guid isPermaLink="false">http://www.moe.gov.sg/media/spotlight/</guid>
<pubDate>Fri, 25 Sep 2009 10:00:00 +0800</pubDate>
<feedburner:origLink>http://www.moe.gov.sg/media/spotlight/</feedburner:origLink></item>
<item>
<title>Work Plan Seminar 2009</title>
<description><![CDATA[<img src="http://www.moe.gov.sg/media/spotlight/assets_c/2009/09/spotlight-wps-thumb-120x80-280
.jpg" alt="Minister speaking at WPS 2009" />]]><![CDATA[<p>At the Work Plan Seminar 2009, Minister for Education
Dr Ng Eng Hen <a href="http://www.moe.gov.sg/media/speeches/2009/09/17/work-plan-seminar.php">talked
about the importance of language &amp; communication skills and growing a world-class education service
</a>. He spoke of <a href="http://www.moe.gov.sg/media/press/2009/09/teachers-the-heart-of-quality.php"
>strengthening the teaching track and of a teacher-driven culture of professional excellence</a>.</p
>]]></description>
<link>http://feedproxy.google.com/~r/singapore-education/spotlight/~3/vnNsA4Hdk6U/</link
>
<guid isPermaLink="false">http://www.moe.gov.sg/media/spotlight/</guid>
<pubDate>Thu, 17 Sep 2009 15:33:15 +0800</pubDate>
<feedburner:origLink>http://www.moe.gov.sg/media/spotlight/</feedburner:origLink></item>
<item>
<title>Recognising School Achievements in 2009</title>
<description>&lt;img src="http://www.moe.gov.sg/media/spotlight/assets_c/2009/09/spotlight-moa-2009-thumb-120x80-278.jpg" alt="Students at a podcast session" />
<![CDATA[<p>A total of 275 schools will <a href="http://www.moe.gov.sg/media/press/2009/09/recognising-school-achievement.php">receive 580 Special and Level
Two Awards this year under the MOE Masterplan of Awards</a>. These awards will be presented at the 2009
MOE Work Plan Seminar on 17 Sep 09 by the Minister for Education, Dr Ng Eng Hen.</p>]]></description
>
<link>http://feedproxy.google.com/~r/singapore-education/spotlight/~3/vnNsA4Hdk6U/</link
>
<guid isPermaLink="false">http://www.moe.gov.sg/media/spotlight/</guid>
<pubDate>Thu, 10 Sep 2009 17:00:00 +0800</pubDate>
<feedburner:origLink>http://www.moe.gov.sg/media/spotlight/</feedburner:origLink></item>
<item>
<title>New Programmes in Special Assistance Plan (SAP) Schools</title>
<description><img src="http://www.moe.gov.sg/media/spotlight/assets_c/2009/09/spotlight-sap-thumb-120x80-257
.jpg" alt="Students engaged in discussion" /><![CDATA[<p>At the Special Assistance Plan (SAP) Seminar
2009 on 4 Sep 09, Ms Grace Fu,
Senior Minister of State for Education, shared on the <a href="http://www.moe.gov.sg/media/press/2009
/09/new-programmes-in-special-assistance-plan-sap-schools.php">new initiatives
rolled out in <abbr title="Special Assistance Plan">SAP</abbr> schools</a>.</p>]]></description>
<link>http://feedproxy.google.com/~r/singapore-education/spotlight/~3/vnNsA4Hdk6U/</link
>
<guid isPermaLink="false">http://www.moe.gov.sg/media/spotlight/</guid>
<pubDate>Fri, 04 Sep 2009 09:30:00 +0800</pubDate>
<feedburner:origLink>http://www.moe.gov.sg/media/spotlight/</feedburner:origLink></item>
</channel>
</rss>