Fixes #12 (NullPointerException in MediaRSS module: Scheme and value
cannot be null)
This commit is contained in:
parent
98a364431e
commit
8608efd489
3 changed files with 38 additions and 5 deletions
|
@ -313,19 +313,25 @@ public class MediaModuleParser implements ModuleParser {
|
|||
}
|
||||
// ratings
|
||||
{
|
||||
final List<Element> ratings = e.getChildren("rating", getNS());
|
||||
final ArrayList<Rating> values = new ArrayList<Rating>();
|
||||
|
||||
for (int i = 0; ratings != null && i < ratings.size(); i++) {
|
||||
final List<Element> ratings = e.getChildren("rating", getNS());
|
||||
for (final Element ratingElement : ratings) {
|
||||
try {
|
||||
final Element rat = ratings.get(i);
|
||||
values.add(new Rating(rat.getAttributeValue("scheme"), rat.getText()));
|
||||
final String ratingText = ratingElement.getText();
|
||||
String ratingScheme = Strings.trimToNull(ratingElement.getAttributeValue("scheme"));
|
||||
if (ratingScheme == null) {
|
||||
ratingScheme = "urn:simple";
|
||||
}
|
||||
final Rating rating = new Rating(ratingScheme, ratingText);
|
||||
values.add(rating);
|
||||
} catch (final Exception ex) {
|
||||
LOG.warn("Exception parsing rating tag.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
md.setRatings(values.toArray(new Rating[values.size()]));
|
||||
|
||||
}
|
||||
// text
|
||||
{
|
||||
|
|
|
@ -22,6 +22,7 @@ import junit.framework.TestSuite;
|
|||
|
||||
import org.rometools.feed.module.AbstractTestCase;
|
||||
import org.rometools.feed.module.mediarss.types.MediaContent;
|
||||
import org.rometools.feed.module.mediarss.types.Rating;
|
||||
import org.rometools.feed.module.mediarss.types.Thumbnail;
|
||||
|
||||
import com.sun.syndication.feed.synd.SyndEntry;
|
||||
|
@ -90,7 +91,7 @@ public class MediaModuleTest extends AbstractTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* test url with whitespace in media element
|
||||
* tests parsing thubnails with empty dimensions
|
||||
* (https://github.com/rometools/rome-modules/issues/7).
|
||||
*
|
||||
* @throws IOException if file not found or not accessible
|
||||
|
@ -108,6 +109,24 @@ public class MediaModuleTest extends AbstractTestCase {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* tests parsing rating without scheme (https://github.com/rometools/rome-modules/issues/12).
|
||||
*
|
||||
* @throws IOException if file not found or not accessible
|
||||
* @throws FeedException when the feed can't be parsed
|
||||
*
|
||||
*/
|
||||
public void testParseRatingWithoutScheme() throws FeedException, IOException {
|
||||
|
||||
final SyndFeed feed = getSyndFeed("org/rometools/feed/module/mediarss/issue-12.xml");
|
||||
final SyndEntry entry = feed.getEntries().get(0);
|
||||
final MediaEntryModule module = (MediaEntryModule) entry.getModule(MediaEntryModule.URI);
|
||||
final Rating[] ratings = module.getMetadata().getRatings();
|
||||
|
||||
assertThat(ratings, is(notNullValue()));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* test url with whitespace in media element
|
||||
* (https://github.com/rometools/rome-modules/issues/20).
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
|
||||
<channel>
|
||||
<item>
|
||||
<media:rating>adult</media:rating>
|
||||
</item>
|
||||
</channel>
|
||||
</rss>
|
Loading…
Reference in a new issue