Simplify ATOMItemsAdapter fromXml method
This commit is contained in:
parent
2bbc8c3e10
commit
d958dcbf04
@ -1,5 +1,6 @@
|
||||
package com.readrops.api.localfeed.atom
|
||||
|
||||
import com.gitlab.mvysny.konsumexml.Konsumer
|
||||
import com.gitlab.mvysny.konsumexml.Names
|
||||
import com.gitlab.mvysny.konsumexml.allChildrenAutoIgnore
|
||||
import com.gitlab.mvysny.konsumexml.konsumeXml
|
||||
@ -23,12 +24,8 @@ class ATOMItemsAdapter : XmlAdapter<List<Item>> {
|
||||
"title" -> title = nonNullText()
|
||||
"id" -> guid = nullableText()
|
||||
"updated" -> pubDate = DateUtils.stringToLocalDateTime(nonNullText())
|
||||
"link" -> {
|
||||
if (attributes.getValueOpt("rel") == null ||
|
||||
attributes["rel"] == "alternate")
|
||||
link = attributes["href"]
|
||||
}
|
||||
"author" -> allChildrenAutoIgnore("name") { author = text() }
|
||||
"link" -> parseLink(this, this@apply)
|
||||
"author" -> allChildrenAutoIgnore("name") { author = nullableText() }
|
||||
"summary" -> description = nullableTextRecursively()
|
||||
"content" -> content = nullableTextRecursively()
|
||||
}
|
||||
@ -49,6 +46,15 @@ class ATOMItemsAdapter : XmlAdapter<List<Item>> {
|
||||
}
|
||||
}
|
||||
|
||||
private fun parseLink(konsume: Konsumer, item: Item) {
|
||||
konsume.apply {
|
||||
if (attributes.getValueOpt("rel") == null ||
|
||||
attributes["rel"] == "alternate")
|
||||
item.link = attributes["href"]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun validateItem(item: Item) {
|
||||
when {
|
||||
item.title == null -> throw ParseException("Item title is required")
|
||||
|
Loading…
x
Reference in New Issue
Block a user