Support multiple creator elements in RSS items

This commit is contained in:
Shinokuni 2020-09-13 12:28:33 +02:00
parent 20e814f36d
commit 8e5900833b
3 changed files with 11 additions and 3 deletions

View File

@ -6,7 +6,12 @@
<title>title</title>
<link>link</link>
<guid>guid</guid>
<dc:creator><![CDATA[creator]]></dc:creator>
<dc:creator><![CDATA[creator 1]]></dc:creator>
<dc:creator><![CDATA[creator 2]]></dc:creator>
<dc:creator><![CDATA[creator 3]]></dc:creator>
<dc:creator><![CDATA[creator 4]]></dc:creator>
<dc:date>2020-08-05T14:03:48Z</dc:date>
<category><![CDATA[Category 1]]></category>
<category><![CDATA[Category 2]]></category>

View File

@ -41,7 +41,7 @@ class RSSItemsAdapterTest {
val item = adapter.fromXml(stream)[0]
assertEquals(item.guid, "guid")
assertEquals(item.author, "creator")
assertEquals(item.author, "creator 1")
assertEquals(item.pubDate, DateUtils.stringToLocalDateTime("2020-08-05T14:03:48Z"))
assertEquals(item.content, "content:encoded")
}

View File

@ -18,6 +18,7 @@ class RSSItemsAdapter : XmlAdapter<List<Item>> {
allChildrenAutoIgnore("item") {
val enclosures = arrayListOf<String>()
val mediaContents = arrayListOf<String>()
val creators = arrayListOf<String?>()
val item = Item().apply {
allChildrenAutoIgnore(names) {
@ -25,7 +26,7 @@ class RSSItemsAdapter : XmlAdapter<List<Item>> {
"title" -> title = nonNullText()
"link" -> link = nonNullText()
"author" -> author = nullableText()
"dc:creator" -> author = nullableText()
"dc:creator" -> creators += nullableText()
"pubDate" -> pubDate = DateUtils.stringToLocalDateTime(nonNullText())
"dc:date" -> pubDate = DateUtils.stringToLocalDateTime(nonNullText())
"guid" -> guid = nullableText()
@ -39,6 +40,8 @@ class RSSItemsAdapter : XmlAdapter<List<Item>> {
validateItem(item)
if (item.guid == null) item.guid = item.link
if (item.author == null && creators.filterNotNull().isNotEmpty())
item.author = creators.filterNotNull().first()
if (enclosures.isNotEmpty()) item.imageLink = enclosures.first()
else if (mediaContents.isNotEmpty()) item.imageLink = mediaContents.first()