Fixes #8 (NumberFormatException if duration is has decimals on
media:content)
This commit is contained in:
parent
8608efd489
commit
60a61b926a
3 changed files with 29 additions and 1 deletions
|
@ -50,6 +50,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.rometools.utils.Integers;
|
||||
import com.rometools.utils.Longs;
|
||||
import com.rometools.utils.Strings;
|
||||
import com.sun.syndication.feed.module.Module;
|
||||
import com.sun.syndication.io.ModuleParser;
|
||||
|
@ -129,7 +130,7 @@ public class MediaModuleParser implements ModuleParser {
|
|||
}
|
||||
try {
|
||||
if (content.getAttributeValue("duration") != null) {
|
||||
mc.setDuration(Long.valueOf(content.getAttributeValue("duration")));
|
||||
mc.setDuration(Longs.parseDecimal(content.getAttributeValue("duration")));
|
||||
}
|
||||
} catch (final Exception ex) {
|
||||
LOG.warn("Exception parsing content tag.", ex);
|
||||
|
|
|
@ -109,6 +109,24 @@ public class MediaModuleTest extends AbstractTestCase {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* tests parsing a decimal duration (https://github.com/rometools/rome-modules/issues/8).
|
||||
*
|
||||
* @throws IOException if file not found or not accessible
|
||||
* @throws FeedException when the feed can't be parsed
|
||||
*
|
||||
*/
|
||||
public void testParseDecimalDuration() throws FeedException, IOException {
|
||||
|
||||
final SyndFeed feed = getSyndFeed("org/rometools/feed/module/mediarss/issue-08.xml");
|
||||
final SyndEntry entry = feed.getEntries().get(0);
|
||||
final MediaEntryModule module = (MediaEntryModule) entry.getModule(MediaEntryModule.URI);
|
||||
final Thumbnail[] thumbnails = module.getMetadata().getThumbnail();
|
||||
|
||||
assertThat(thumbnails, is(notNullValue()));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* tests parsing rating without scheme (https://github.com/rometools/rome-modules/issues/12).
|
||||
*
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
|
||||
<channel>
|
||||
<item>
|
||||
<media:content url="http://someurl/somevideo.wmv" fileSize="21592869" bitrate="496024"
|
||||
duration="174.42" type="video/x-ms-wmv" isDefault="false" />
|
||||
</item>
|
||||
</channel>
|
||||
</rss>
|
Loading…
Reference in a new issue