Add support for alternative tags author and dc:date. Fix date parsing bug
This commit is contained in:
parent
3290c55e65
commit
6a05cd6bbf
@ -181,12 +181,14 @@ public class Item {
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
newItem.setPubDate(DateUtils.stringToDateTime(item.getDate(), DateUtils.RSS_2_DATE_FORMAT));
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
newItem.setPubDate(DateUtils.stringToDateTime(item.getDate(), DateUtils.ATOM_JSON_DATE_FORMAT));
|
||||
if (newItem.getPubDate() == null) {
|
||||
try {
|
||||
newItem.setPubDate(DateUtils.stringToDateTime(item.getDate(), DateUtils.RSS_2_DATE_FORMAT));
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
newItem.setPubDate(DateUtils.stringToDateTime(item.getDate(), DateUtils.ATOM_JSON_DATE_FORMAT));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -196,7 +198,7 @@ public class Item {
|
||||
|
||||
if (item.getMediaContents() != null && item.getMediaContents().size() > 0) {
|
||||
for (RSSMediaContent mediaContent : item.getMediaContents()) {
|
||||
if (Utils.isTypeImage(mediaContent.getMedium())) {
|
||||
if (mediaContent.getMedium() != null && Utils.isTypeImage(mediaContent.getMedium())) {
|
||||
newItem.setImageLink(mediaContent.getUrl());
|
||||
break;
|
||||
}
|
||||
@ -204,7 +206,7 @@ public class Item {
|
||||
} else {
|
||||
if (item.getEnclosures() != null) {
|
||||
for (RSSEnclosure enclosure : item.getEnclosures()) {
|
||||
if (Utils.isTypeImage(enclosure.getType())) {
|
||||
if (enclosure.getType() != null && Utils.isTypeImage(enclosure.getType())) {
|
||||
newItem.setImageLink(enclosure.getUrl());
|
||||
break;
|
||||
}
|
||||
|
@ -15,26 +15,26 @@ import static org.junit.Assert.*;
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
|
||||
@Test
|
||||
public void addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2);
|
||||
public void rssDateTest() {
|
||||
try {
|
||||
LocalDateTime dateTime = new LocalDateTime(2019, 1, 4, 22, 21, 46);
|
||||
|
||||
assertEquals(0, dateTime.compareTo(DateUtils.stringToDateTime("Fri, 04 Jan 2019 22:21:46 +0000", DateUtils.RSS_2_DATE_FORMAT)));
|
||||
assertEquals(0, dateTime.compareTo(DateUtils.stringToDateTime("Fri, 04 Jan 2019 22:21:46 GMT", DateUtils.RSS_2_DATE_FORMAT_2)));
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringToDateTest() {
|
||||
LocalDateTime dateTime = new LocalDateTime(2019, 1, 4, 22, 21, 46);
|
||||
|
||||
public void atomJsonDateTest() {
|
||||
try {
|
||||
// RSS
|
||||
assertTrue(dateTime.compareTo(DateUtils.stringToDateTime("Fri, 04 Jan 2019 22:21:46 +0000", DateUtils.RSS_2_DATE_FORMAT)) == 0);
|
||||
|
||||
// ATOM
|
||||
assertTrue(dateTime.compareTo(DateUtils.stringToDateTime("2019-01-04T22:21:46+00:00", DateUtils.ATOM_JSON_DATE_FORMAT)) == 0);
|
||||
|
||||
// JSON
|
||||
assertTrue(dateTime.compareTo(DateUtils.stringToDateTime("2019-01-04T22:21:46-0000", DateUtils.ATOM_JSON_DATE_FORMAT)) == 0);
|
||||
|
||||
LocalDateTime dateTime = new LocalDateTime(2019, 1, 4, 22, 21, 46);
|
||||
|
||||
assertEquals(0, dateTime.compareTo(DateUtils.stringToDateTime("2019-01-04T22:21:46+00:00", DateUtils.ATOM_JSON_DATE_FORMAT)));
|
||||
assertEquals(0, dateTime.compareTo(DateUtils.stringToDateTime("2019-01-04T22:21:46-0000", DateUtils.ATOM_JSON_DATE_FORMAT)));
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -15,12 +15,13 @@ public class RSSItem extends AItem {
|
||||
@Element(name = "title", required = false)
|
||||
private String title;
|
||||
|
||||
@Element(name = "description", required = false, data = true)
|
||||
private String description;
|
||||
|
||||
@Element(name = "link", required = false)
|
||||
private String link;
|
||||
|
||||
@ElementList(name = "link", inline = true, required = false)
|
||||
@Namespace(prefix = "atom")
|
||||
private List<String> otherLinks;
|
||||
|
||||
@Element(name = "imageLink", required = false)
|
||||
private String imageLink;
|
||||
|
||||
@ -33,11 +34,21 @@ public class RSSItem extends AItem {
|
||||
|
||||
@Element(name = "creator", required = false)
|
||||
@Namespace(prefix = "dc", reference = "http://purl.org/dc/elements/1.1/")
|
||||
private String creator;
|
||||
|
||||
@Element(required = false)
|
||||
private String author;
|
||||
|
||||
@Element(name = "pubDate", required = false)
|
||||
private String pubDate;
|
||||
|
||||
@Element(name = "date", required = false)
|
||||
@Namespace(prefix = "dc")
|
||||
private String date;
|
||||
|
||||
@Element(name = "description", required = false)
|
||||
private String description;
|
||||
|
||||
@Element(name = "encoded", required = false)
|
||||
@Namespace(prefix = "content")
|
||||
private String content;
|
||||
@ -77,12 +88,12 @@ public class RSSItem extends AItem {
|
||||
this.imageLink = imageLink;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
public String getCreator() {
|
||||
return creator;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
public void setCreator(String creator) {
|
||||
this.creator = creator;
|
||||
}
|
||||
|
||||
public String getPubDate() {
|
||||
@ -124,4 +135,34 @@ public class RSSItem extends AItem {
|
||||
public void setEnclosures(List<RSSEnclosure> enclosures) {
|
||||
this.enclosures = enclosures;
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
if (pubDate != null)
|
||||
return pubDate;
|
||||
else
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(String date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
if (creator != null)
|
||||
return creator;
|
||||
else
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public List<String> getOtherLinks() {
|
||||
return otherLinks;
|
||||
}
|
||||
|
||||
public void setOtherLinks(List<String> otherLinks) {
|
||||
this.otherLinks = otherLinks;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user