Fixes #7 (NumberFormatException if width="" on media:thumbnail)

This commit is contained in:
Patrick Gotthard 2014-04-18 19:29:06 +02:00
parent 358c9416e6
commit 33b89336c8

View file

@ -22,7 +22,6 @@
package org.rometools.feed.module.mediarss.io; package org.rometools.feed.module.mediarss.io;
import java.net.URI; import java.net.URI;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -50,9 +49,10 @@ import org.rometools.feed.module.mediarss.types.UrlReference;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.rometools.utils.Integers;
import com.rometools.utils.Strings;
import com.sun.syndication.feed.module.Module; import com.sun.syndication.feed.module.Module;
import com.sun.syndication.io.ModuleParser; import com.sun.syndication.io.ModuleParser;
import com.sun.syndication.io.impl.NumberParser;
/** /**
* @author Nathanial X. Freitas * @author Nathanial X. Freitas
@ -347,16 +347,30 @@ public class MediaModuleParser implements ModuleParser {
} }
// thumbnails // thumbnails
{ {
final List<Element> thumbnails = e.getChildren("thumbnail", getNS());
final ArrayList<Thumbnail> values = new ArrayList<Thumbnail>(); final ArrayList<Thumbnail> values = new ArrayList<Thumbnail>();
for (int i = 0; thumbnails != null && i < thumbnails.size(); i++) { final List<Element> thumbnails = e.getChildren("thumbnail", getNS());
for (final Element thumb : thumbnails) {
try { try {
final Element thumb = thumbnails.get(i);
final Time t = thumb.getAttributeValue("time") == null ? null : new Time(thumb.getAttributeValue("time")); final String timeAttr = Strings.trimToNull(thumb.getAttributeValue("time"));
final Integer width = thumb.getAttributeValue("width") == null ? null : new Integer(thumb.getAttributeValue("width")); Time time = null;
final Integer height = thumb.getAttributeValue("height") == null ? null : new Integer(thumb.getAttributeValue("height")); if (timeAttr == null) {
values.add(new Thumbnail(new URI(thumb.getAttributeValue("url")), width, height, t)); time = new Time(timeAttr);
}
final String widthAttr = thumb.getAttributeValue("width");
final Integer width = Integers.parse(widthAttr);
final String heightAttr = thumb.getAttributeValue("height");
final Integer height = Integers.parse(heightAttr);
final String url = thumb.getAttributeValue("url");
final URI uri = new URI(url);
final Thumbnail thumbnail = new Thumbnail(uri, width, height, time);
values.add(thumbnail);
} catch (final Exception ex) { } catch (final Exception ex) {
LOG.warn("Exception parsing thumbnail tag.", ex); LOG.warn("Exception parsing thumbnail tag.", ex);
} }