fix NPE in location search on missing/empty PubDate in underlaying rss data

pull/1/head
reger 10 years ago
parent c1dcc8c456
commit b1ec0644e5

@ -113,7 +113,7 @@ public class yacysearch_location {
prop.put("kml_placemark_" + placemarkCounter + "_copyright", message.getCopyright()); prop.put("kml_placemark_" + placemarkCounter + "_copyright", message.getCopyright());
prop.put("kml_placemark_" + placemarkCounter + "_subject", message.getSubject()); prop.put("kml_placemark_" + placemarkCounter + "_subject", message.getSubject());
prop.put("kml_placemark_" + placemarkCounter + "_description", message.getDescriptions().size() > 0 ? message.getDescriptions().get(0) : ""); prop.put("kml_placemark_" + placemarkCounter + "_description", message.getDescriptions().size() > 0 ? message.getDescriptions().get(0) : "");
prop.put("kml_placemark_" + placemarkCounter + "_date", message.getPubDate()); prop.put("kml_placemark_" + placemarkCounter + "_date", (message.getPubDate() != null) ? message.getPubDate() : new Date());
prop.putXML("kml_placemark_" + placemarkCounter + "_url", message.getLink()); prop.putXML("kml_placemark_" + placemarkCounter + "_url", message.getLink());
prop.put("kml_placemark_" + placemarkCounter + "_pointname", message.getTitle()); prop.put("kml_placemark_" + placemarkCounter + "_pointname", message.getTitle());
prop.put("kml_placemark_" + placemarkCounter + "_lon", lo); prop.put("kml_placemark_" + placemarkCounter + "_lon", lo);

@ -212,20 +212,26 @@ public class RSSMessage implements Hit, Comparable<RSSMessage>, Comparator<RSSMe
return Token.language.valueFrom(this.map, ""); return Token.language.valueFrom(this.map, "");
} }
/**
* @return publishDate or null
*/
@Override @Override
public Date getPubDate() { public Date getPubDate() {
final String dateString = Token.pubDate.valueFrom(this.map, ""); final String dateString = Token.pubDate.valueFrom(this.map, "");
Date date; if (!dateString.isEmpty()) { // skip parse exception on empty string
try { Date date;
date = HeaderFramework.FORMAT_RFC1123.parse(dateString);
} catch (final ParseException e) {
try { try {
date = GenericFormatter.SHORT_SECOND_FORMATTER.parse(dateString); date = HeaderFramework.FORMAT_RFC1123.parse(dateString);
} catch (final ParseException e1) { } catch (final ParseException e) {
date = HeaderFramework.parseHTTPDate(dateString); try {
date = GenericFormatter.SHORT_SECOND_FORMATTER.parse(dateString);
} catch (final ParseException e1) {
date = HeaderFramework.parseHTTPDate(dateString); // returns null on parse error
}
} }
return date;
} }
return date; return null;
} }
@Override @Override

Loading…
Cancel
Save