Add adapter for RSS1 items

This commit is contained in:
Shinokuni 2020-09-23 22:02:41 +02:00
parent 694d684223
commit c742c4fbf2
8 changed files with 388 additions and 0 deletions

View File

@ -0,0 +1,43 @@
<rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:syn="http://purl.org/rss/1.0/modules/syndication/"
xmlns="http://purl.org/rss/1.0/">
<item
rdf:about="https://developers.slashdot.org/story/20/09/23/1616231/google-expands-its-flutter-development-kit-to-windows-apps?utm_source=rss1.0mainlinkanon&amp;utm_medium=feed">
<title>Google Expands its Flutter Development Kit To Windows Apps</title>
<link>
https://developers.slashdot.org/story/20/09/23/1616231/google-expands-its-flutter-development-kit-to-windows-apps?utm_source=rss1.0mainlinkanon&amp;utm_medium=feed
</link>
<description>Google has announced that Flutter, its open source UI development kit for
building cross-platform software from the same codebase, is finally available for
Windows apps in alpha. From a report:For the world's leading desktop operating system
with some 1 billion installations of Windows 10 alone, this has been a long time coming.
Flutter's alpha incarnation was initially launched at Google's I/O developer conference
back in 2017, before arriving in beta less than a year later. In its original guise,
Flutter was designed for Android and iOS app development, but it has since expanded to
cover the web, MacOS, and Linux, which are currently available in various alpha or beta
iterations. Developers have had to consider unique platform-specific factors when
designing for the desktop or mobile phones, such as different screen sizes and how
people interact with their devices. On smartphones, people typically use touch and
swipe-based gestures, while keyboards and mice are commonly used on PCs and laptops.
This means Flutter has had to expand its support to cover the additional inputs.&lt;p&gt;&lt;div
class="share_submission" style="position:relative;"&gt; &lt;a class="slashpop"
href="http://twitter.com/home?status=Google+Expands+its+Flutter+Development+Kit+To+Windows+Apps%3A+https%3A%2F%2Fbit.ly%2F32X36MW"&gt;&lt;img
src="https://a.fsdn.com/sd/twitter_icon_large.png"&gt;&lt;/a&gt; &lt;a class="slashpop"
href="http://www.facebook.com/sharer.php?u=https%3A%2F%2Fdevelopers.slashdot.org%2Fstory%2F20%2F09%2F23%2F1616231%2Fgoogle-expands-its-flutter-development-kit-to-windows-apps%3Futm_source%3Dslashdot%26utm_medium%3Dfacebook"&gt;&lt;img
src="https://a.fsdn.com/sd/facebook_icon_large.png"&gt;&lt;/a&gt;
&lt;/div&gt;&lt;/p&gt;&lt;p&gt;&lt;a
href="https://developers.slashdot.org/story/20/09/23/1616231/google-expands-its-flutter-development-kit-to-windows-apps?utm_source=rss1.0moreanon&amp;amp;utm_medium=feed"&gt;Read
more of this story&lt;/a&gt; at Slashdot.&lt;/p&gt;&lt;iframe
src="https://slashdot.org/slashdot-it.pl?op=discuss&amp;amp;id=17251868&amp;amp;smallembed=1"
style="height: 300px; width: 100%; border: none;"&gt;&lt;/iframe&gt;
</description>
<dc:creator>msmash</dc:creator>
<dc:subject>programming</dc:subject>
<slash:department>how-about-that</slash:department>
<slash:section>developers</slash:section>
<slash:comments>1</slash:comments>
<slash:hit_parade>1,1,1,1,0,0,0</slash:hit_parade>
</item>
</rdf:RDF>

View File

@ -0,0 +1,40 @@
<rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:syn="http://purl.org/rss/1.0/modules/syndication/"
xmlns="http://purl.org/rss/1.0/">
<item>
<title>Google Expands its Flutter Development Kit To Windows Apps</title>
<description>Google has announced that Flutter, its open source UI development kit for
building cross-platform software from the same codebase, is finally available for
Windows apps in alpha. From a report:For the world's leading desktop operating system
with some 1 billion installations of Windows 10 alone, this has been a long time coming.
Flutter's alpha incarnation was initially launched at Google's I/O developer conference
back in 2017, before arriving in beta less than a year later. In its original guise,
Flutter was designed for Android and iOS app development, but it has since expanded to
cover the web, MacOS, and Linux, which are currently available in various alpha or beta
iterations. Developers have had to consider unique platform-specific factors when
designing for the desktop or mobile phones, such as different screen sizes and how
people interact with their devices. On smartphones, people typically use touch and
swipe-based gestures, while keyboards and mice are commonly used on PCs and laptops.
This means Flutter has had to expand its support to cover the additional inputs.&lt;p&gt;&lt;div
class="share_submission" style="position:relative;"&gt; &lt;a class="slashpop"
href="http://twitter.com/home?status=Google+Expands+its+Flutter+Development+Kit+To+Windows+Apps%3A+https%3A%2F%2Fbit.ly%2F32X36MW"&gt;&lt;img
src="https://a.fsdn.com/sd/twitter_icon_large.png"&gt;&lt;/a&gt; &lt;a class="slashpop"
href="http://www.facebook.com/sharer.php?u=https%3A%2F%2Fdevelopers.slashdot.org%2Fstory%2F20%2F09%2F23%2F1616231%2Fgoogle-expands-its-flutter-development-kit-to-windows-apps%3Futm_source%3Dslashdot%26utm_medium%3Dfacebook"&gt;&lt;img
src="https://a.fsdn.com/sd/facebook_icon_large.png"&gt;&lt;/a&gt;
&lt;/div&gt;&lt;/p&gt;&lt;p&gt;&lt;a
href="https://developers.slashdot.org/story/20/09/23/1616231/google-expands-its-flutter-development-kit-to-windows-apps?utm_source=rss1.0moreanon&amp;amp;utm_medium=feed"&gt;Read
more of this story&lt;/a&gt; at Slashdot.&lt;/p&gt;&lt;iframe
src="https://slashdot.org/slashdot-it.pl?op=discuss&amp;amp;id=17251868&amp;amp;smallembed=1"
style="height: 300px; width: 100%; border: none;"&gt;&lt;/iframe&gt;
</description>
<dc:creator>msmash</dc:creator>
<dc:date>2020-09-23T16:15:00+00:00</dc:date>
<dc:subject>programming</dc:subject>
<slash:department>how-about-that</slash:department>
<slash:section>developers</slash:section>
<slash:comments>1</slash:comments>
<slash:hit_parade>1,1,1,1,0,0,0</slash:hit_parade>
</item>
</rdf:RDF>

View File

@ -0,0 +1,43 @@
<rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:syn="http://purl.org/rss/1.0/modules/syndication/"
xmlns="http://purl.org/rss/1.0/">
<item
rdf:about="https://developers.slashdot.org/story/20/09/23/1616231/google-expands-its-flutter-development-kit-to-windows-apps?utm_source=rss1.0mainlinkanon&amp;utm_medium=feed">
<link>
https://developers.slashdot.org/story/20/09/23/1616231/google-expands-its-flutter-development-kit-to-windows-apps?utm_source=rss1.0mainlinkanon&amp;utm_medium=feed
</link>
<description>Google has announced that Flutter, its open source UI development kit for
building cross-platform software from the same codebase, is finally available for
Windows apps in alpha. From a report:For the world's leading desktop operating system
with some 1 billion installations of Windows 10 alone, this has been a long time coming.
Flutter's alpha incarnation was initially launched at Google's I/O developer conference
back in 2017, before arriving in beta less than a year later. In its original guise,
Flutter was designed for Android and iOS app development, but it has since expanded to
cover the web, MacOS, and Linux, which are currently available in various alpha or beta
iterations. Developers have had to consider unique platform-specific factors when
designing for the desktop or mobile phones, such as different screen sizes and how
people interact with their devices. On smartphones, people typically use touch and
swipe-based gestures, while keyboards and mice are commonly used on PCs and laptops.
This means Flutter has had to expand its support to cover the additional inputs.&lt;p&gt;&lt;div
class="share_submission" style="position:relative;"&gt; &lt;a class="slashpop"
href="http://twitter.com/home?status=Google+Expands+its+Flutter+Development+Kit+To+Windows+Apps%3A+https%3A%2F%2Fbit.ly%2F32X36MW"&gt;&lt;img
src="https://a.fsdn.com/sd/twitter_icon_large.png"&gt;&lt;/a&gt; &lt;a class="slashpop"
href="http://www.facebook.com/sharer.php?u=https%3A%2F%2Fdevelopers.slashdot.org%2Fstory%2F20%2F09%2F23%2F1616231%2Fgoogle-expands-its-flutter-development-kit-to-windows-apps%3Futm_source%3Dslashdot%26utm_medium%3Dfacebook"&gt;&lt;img
src="https://a.fsdn.com/sd/facebook_icon_large.png"&gt;&lt;/a&gt;
&lt;/div&gt;&lt;/p&gt;&lt;p&gt;&lt;a
href="https://developers.slashdot.org/story/20/09/23/1616231/google-expands-its-flutter-development-kit-to-windows-apps?utm_source=rss1.0moreanon&amp;amp;utm_medium=feed"&gt;Read
more of this story&lt;/a&gt; at Slashdot.&lt;/p&gt;&lt;iframe
src="https://slashdot.org/slashdot-it.pl?op=discuss&amp;amp;id=17251868&amp;amp;smallembed=1"
style="height: 300px; width: 100%; border: none;"&gt;&lt;/iframe&gt;
</description>
<dc:creator>msmash</dc:creator>
<dc:date>2020-09-23T16:15:00+00:00</dc:date>
<dc:subject>programming</dc:subject>
<slash:department>how-about-that</slash:department>
<slash:section>developers</slash:section>
<slash:comments>1</slash:comments>
<slash:hit_parade>1,1,1,1,0,0,0</slash:hit_parade>
</item>
</rdf:RDF>

View File

@ -0,0 +1,120 @@
<rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:syn="http://purl.org/rss/1.0/modules/syndication/"
xmlns="http://purl.org/rss/1.0/">
<channel rdf:about="https://slashdot.org/">
<title>Slashdot</title>
<link>https://slashdot.org/</link>
<description>News for nerds, stuff that matters</description>
<dc:language>en-us</dc:language>
<dc:rights>Copyright 1997-2016, SlashdotMedia. All Rights Reserved.</dc:rights>
<dc:date>2020-09-23T16:20:20+00:00</dc:date>
<dc:publisher>Dice</dc:publisher>
<dc:creator>help@slashdot.org</dc:creator>
<dc:subject>Technology</dc:subject>
<syn:updateBase>1970-01-01T00:00+00:00</syn:updateBase>
<syn:updateFrequency>1</syn:updateFrequency>
<syn:updatePeriod>hourly</syn:updatePeriod>
<items>
<rdf:Seq>
<rdf:li
rdf:resource="https://developers.slashdot.org/story/20/09/23/1616231/google-expands-its-flutter-development-kit-to-windows-apps?utm_source=rss1.0mainlinkanon&amp;utm_medium=feed" />
<rdf:li
rdf:resource="https://news.slashdot.org/story/20/09/23/1528219/firefox-usage-is-down-85-despite-mozillas-top-exec-pay-going-up-400?utm_source=rss1.0mainlinkanon&amp;utm_medium=feed" />
<rdf:li
rdf:resource="https://news.slashdot.org/story/20/09/23/1451213/climate-disruption-is-now-locked-in-the-next-moves-will-be-crucial?utm_source=rss1.0mainlinkanon&amp;utm_medium=feed" />
<rdf:li
rdf:resource="https://news.slashdot.org/story/20/09/23/1420240/a-new-york-clock-that-told-time-now-tells-the-time-remaining?utm_source=rss1.0mainlinkanon&amp;utm_medium=feed" />
<rdf:li
rdf:resource="https://news.slashdot.org/story/20/09/23/0057256/jeff-bezos-is-opening-his-first-tuition-free-bezos-academy-preschool-where-each-child-will-be-the-customer?utm_source=rss1.0mainlinkanon&amp;utm_medium=feed" />
<rdf:li
rdf:resource="https://news.slashdot.org/story/20/09/23/0050249/google-is-pulling-the-plug-on-paid-chrome-extensions-over-the-next-year?utm_source=rss1.0mainlinkanon&amp;utm_medium=feed" />
<rdf:li
rdf:resource="https://entertainment.slashdot.org/story/20/09/22/2147243/old-tv-caused-village-broadband-outages-for-18-months?utm_source=rss1.0mainlinkanon&amp;utm_medium=feed" />
<rdf:li
rdf:resource="https://mobile.slashdot.org/story/20/09/22/2316256/t-mobile-amassed-unprecedented-concentration-of-spectrum-att-complains?utm_source=rss1.0mainlinkanon&amp;utm_medium=feed" />
<rdf:li
rdf:resource="https://yro.slashdot.org/story/20/09/22/2030223/dark-web-drugs-raid-leads-to-179-arrests?utm_source=rss1.0mainlinkanon&amp;utm_medium=feed" />
<rdf:li
rdf:resource="https://hardware.slashdot.org/story/20/09/22/2055203/the-fairphone-3-is-a-repairable-dream-that-takes-beautiful-photos?utm_source=rss1.0mainlinkanon&amp;utm_medium=feed" />
<rdf:li
rdf:resource="https://tech.slashdot.org/story/20/09/23/0039222/tesla-unveils-model-s-plaid-520-miles-200-mph-and-0-60-mph-in-less-than-2s?utm_source=rss1.0mainlinkanon&amp;utm_medium=feed" />
<rdf:li
rdf:resource="https://apple.slashdot.org/story/20/09/22/211222/apple-ceo-impressed-by-remote-work-sees-permanent-changes?utm_source=rss1.0mainlinkanon&amp;utm_medium=feed" />
<rdf:li
rdf:resource="https://hardware.slashdot.org/story/20/09/22/236228/tesla-announces-tabless-battery-cells-that-will-improve-range-of-its-electric-cars?utm_source=rss1.0mainlinkanon&amp;utm_medium=feed" />
<rdf:li
rdf:resource="https://linux.slashdot.org/story/20/09/22/2243209/linux-journal-is-back?utm_source=rss1.0mainlinkanon&amp;utm_medium=feed" />
<rdf:li
rdf:resource="https://hardware.slashdot.org/story/20/09/22/2026238/shell-reportedly-to-slash-oil-and-gas-production-costs-to-focus-more-on-renewables?utm_source=rss1.0mainlinkanon&amp;utm_medium=feed" />
</rdf:Seq>
</items>
<image rdf:resource="https://a.fsdn.com/sd/topics/topicslashdot.gif" />
<textinput rdf:resource="https://slashdot.org/search.pl" />
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" href="http://rss.slashdot.org/slashdot/slashdotMain"
rel="self" type="application/rdf+xml" />
<feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0"
uri="slashdot/slashdotmain" />
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" href="http://pubsubhubbub.appspot.com/"
rel="hub" />
</channel>
<image rdf:about="https://a.fsdn.com/sd/topics/topicslashdot.gif">
<title>Slashdot</title>
<url>https://a.fsdn.com/sd/topics/topicslashdot.gif</url>
<link>https://slashdot.org/</link>
</image>
<item
rdf:about="https://news.slashdot.org/story/20/09/23/1420240/a-new-york-clock-that-told-time-now-tells-the-time-remaining?utm_source=rss1.0mainlinkanon&amp;utm_medium=feed">
<title>A New York Clock That Told Time Now Tells the Time Remaining</title>
<description>For more than 20 years, Metronome, which includes a 62-foot-wide 15-digit
electronic clock that faces Union Square in Manhattan, has been one of the city's most
prominent and baffling public art projects. Its digital display once told the time in
its own unique way, counting the hours, minutes and seconds (and fractions thereof) to
and from midnight. But for years observers who did not understand how it worked
suggested that it was measuring the acres of rainforest destroyed each year, tracking
the world population or even that it had something to do with pi. On Saturday Metronome
adopted a new ecologically sensitive mission. From a report: Now, instead of measuring
24-hour cycles, it is measuring what two artists, Gan Golan and Andrew Boyd, present as
a critical window for action to prevent the effects of global warming from becoming
irreversible. On Saturday at 3:20 p.m., messages including "The Earth has a deadline"
began to appear on the display. Then numbers -- 7:103:15:40:07 -- showed up,
representing the years, days, hours, minutes and seconds until that deadline. As a
handful of supporters watched, the number -- which the artists said was based on
calculations by the Mercator Research Institute on Global Commons and Climate Change in
Berlin -- began ticking down, second by second.
"This is our way to shout that number from the rooftops." Mr. Golan said just before the
countdown began. "The world is literally counting on us." The Climate Clock, as the two
artists call their project, will be displayed on the 14th Street building, One Union
Square South, through Sept. 27, the end of Climate Week. The creators say their aim is
to arrange for the clock to be permanently displayed, there or elsewhere. Mr. Golan said
he came up with the idea to publicly illustrate the urgency of combating climate change
about two years ago, shortly after his daughter was born. He asked Mr. Boyd, an activist
from the Lower East Side, to work with him on the project.&lt;p&gt;&lt;div
class="share_submission" style="position:relative;"&gt; &lt;a class="slashpop"
href="http://twitter.com/home?status=A+New+York+Clock+That+Told+Time+Now+Tells+the+Time+Remaining%3A+https%3A%2F%2Fbit.ly%2F2HrAt2b"&gt;&lt;img
src="https://a.fsdn.com/sd/twitter_icon_large.png"&gt;&lt;/a&gt; &lt;a class="slashpop"
href="http://www.facebook.com/sharer.php?u=https%3A%2F%2Fnews.slashdot.org%2Fstory%2F20%2F09%2F23%2F1420240%2Fa-new-york-clock-that-told-time-now-tells-the-time-remaining%3Futm_source%3Dslashdot%26utm_medium%3Dfacebook"&gt;&lt;img
src="https://a.fsdn.com/sd/facebook_icon_large.png"&gt;&lt;/a&gt;
&lt;/div&gt;&lt;/p&gt;&lt;p&gt;&lt;a
href="https://news.slashdot.org/story/20/09/23/1420240/a-new-york-clock-that-told-time-now-tells-the-time-remaining?utm_source=rss1.0moreanon&amp;amp;utm_medium=feed"&gt;Read
more of this story&lt;/a&gt; at Slashdot.&lt;/p&gt;&lt;iframe
src="https://slashdot.org/slashdot-it.pl?op=discuss&amp;amp;id=17251272&amp;amp;smallembed=1"
style="height: 300px; width: 100%; border: none;"&gt;&lt;/iframe&gt;
</description>
<dc:creator>msmash</dc:creator>
<dc:creator></dc:creator>
<dc:creator>creator 2</dc:creator>
<dc:creator>creator 3</dc:creator>
<dc:creator>creator 4</dc:creator>
<dc:creator>creator 5</dc:creator>
<dc:date>2020-09-23T14:10:00+00:00</dc:date>
<dc:subject>news</dc:subject>
<slash:department>how-about-that</slash:department>
<slash:section>news</slash:section>
<slash:comments>43</slash:comments>
<slash:hit_parade>43,38,33,27,6,1,0</slash:hit_parade>
</item>
</rdf:RDF>

View File

@ -0,0 +1,70 @@
package com.readrops.api.localfeed.rss1
import android.content.Context
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.readrops.api.utils.DateUtils
import com.readrops.api.utils.ParseException
import junit.framework.TestCase.assertEquals
import junit.framework.TestCase.assertNotNull
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class RSS1ItemsAdapterTest {
private val context: Context = InstrumentationRegistry.getInstrumentation().context
private val adapter = RSS1ItemsAdapter()
@Test
fun normalCasesTest() {
val stream = context.resources.assets.open("localfeed/rss1/rss1_feed.xml")
val items = adapter.fromXml(stream)
val item = items.first()
assertEquals(items.size, 4)
assertEquals(item.title, "Google Expands its Flutter Development Kit To Windows Apps")
assertEquals(item.link.trim(), "https://developers.slashdot.org/story/20/09/23/1616231/google-expands-" +
"its-flutter-development-kit-to-windows-apps?utm_source=rss1.0mainlinkanon&utm_medium=feed")
assertEquals(item.guid.trim(), "https://developers.slashdot.org/story/20/09/23/1616231/google-expands-" +
"its-flutter-development-kit-to-windows-apps?utm_source=rss1.0mainlinkanon&utm_medium=feed")
assertEquals(item.pubDate, DateUtils.stringToLocalDateTime("2020-09-23T16:15:00+00:00"))
assertEquals(item.author, "msmash")
assertNotNull(item.description)
}
@Test
fun specialCasesTest() {
val stream = context.resources.assets.open("localfeed/rss1/rss1_items_special_cases.xml")
val item = adapter.fromXml(stream).first()
assertEquals(item.author, "msmash, creator 2, creator 3, creator 4, ...")
assertEquals(item.link, "https://news.slashdot.org/story/20/09/23/1420240/a-new-york-clock-" +
"that-told-time-now-tells-the-time-remaining?utm_source=rss1.0mainlinkanon&utm_medium=feed")
}
@Test
fun nullTitleTest() {
val stream = context.resources.assets.open("localfeed/rss1/rss1_items_no_title.xml")
Assert.assertThrows(ParseException::class.java) { adapter.fromXml(stream) }
}
@Test
fun nullLinkTest() {
val stream = context.resources.assets.open("localfeed/rss1/rss1_items_no_link.xml")
Assert.assertThrows(ParseException::class.java) { adapter.fromXml(stream) }
}
@Test
fun nullDateTest() {
val stream = context.resources.assets.open("localfeed/rss1/rss1_items_no_date.xml")
Assert.assertThrows(ParseException::class.java) { adapter.fromXml(stream) }
}
}

View File

@ -3,6 +3,7 @@ package com.readrops.api.localfeed
import com.readrops.api.localfeed.atom.ATOMFeedAdapter
import com.readrops.api.localfeed.atom.ATOMItemsAdapter
import com.readrops.api.localfeed.rss1.RSS1FeedAdapter
import com.readrops.api.localfeed.rss1.RSS1ItemsAdapter
import com.readrops.api.localfeed.rss2.RSS2FeedAdapter
import com.readrops.api.localfeed.rss2.RSS2ItemsAdapter
import com.readrops.db.entities.Feed
@ -25,6 +26,7 @@ interface XmlAdapter<T> {
fun xmlItemsAdapterFactory(type: LocalRSSHelper.RSSType): XmlAdapter<List<Item>> {
return when (type) {
LocalRSSHelper.RSSType.RSS_1 -> RSS1ItemsAdapter()
LocalRSSHelper.RSSType.RSS_2 -> RSS2ItemsAdapter()
LocalRSSHelper.RSSType.ATOM -> ATOMItemsAdapter()
else -> throw IllegalArgumentException("Unknown RSS type : $type")

View File

@ -0,0 +1,68 @@
package com.readrops.api.localfeed.rss1
import com.gitlab.mvysny.konsumexml.Names
import com.gitlab.mvysny.konsumexml.allChildrenAutoIgnore
import com.gitlab.mvysny.konsumexml.konsumeXml
import com.readrops.api.localfeed.XmlAdapter
import com.readrops.api.utils.DateUtils
import com.readrops.api.utils.ParseException
import com.readrops.api.utils.nonNullText
import com.readrops.api.utils.nullableText
import com.readrops.db.entities.Item
import java.io.InputStream
class RSS1ItemsAdapter : XmlAdapter<List<Item>> {
override fun fromXml(inputStream: InputStream): List<Item> {
val konsume = inputStream.konsumeXml()
val items = arrayListOf<Item>()
return try {
konsume.child("RDF") {
allChildrenAutoIgnore("item") {
val authors = arrayListOf<String?>()
val about = attributes.getValueOpt("about",
namespace = "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
val item = Item().apply {
allChildrenAutoIgnore(names) {
when (tagName) {
"title" -> title = nonNullText()
"link" -> link = nullableText()
"dc:date" -> pubDate = DateUtils.stringToLocalDateTime(nonNullText())
"dc:creator" -> authors += nullableText()
"description" -> description = nullableText(failOnElement = false)
else -> skipContents()
}
}
}
item.guid = item.link
if (authors.filterNotNull().isNotEmpty()) item.author = authors.filterNotNull().joinToString(limit = 4)
if (item.link == null) item.link = about
validateItem(item)
items += item
}
}
konsume.close()
items
} catch (e: Exception) {
throw ParseException(e.message)
}
}
private fun validateItem(item: Item) {
when {
item.title == null -> throw ParseException("Item title is required")
item.link == null -> throw ParseException("Item link is required")
item.pubDate == null -> throw ParseException("Item date is required")
}
}
companion object {
val names = Names.of("title", "description", "date", "link", "creator")
}
}

View File

@ -3,6 +3,7 @@ package com.readrops.api.localfeed
import com.readrops.api.localfeed.atom.ATOMFeedAdapter
import com.readrops.api.localfeed.atom.ATOMItemsAdapter
import com.readrops.api.localfeed.rss1.RSS1FeedAdapter
import com.readrops.api.localfeed.rss1.RSS1ItemsAdapter
import com.readrops.api.localfeed.rss2.RSS2FeedAdapter
import com.readrops.api.localfeed.rss2.RSS2ItemsAdapter
import junit.framework.TestCase.assertTrue
@ -22,6 +23,7 @@ class XmlAdapterTest {
@Test
fun xmlItemsAdapterFactoryTest() {
assertTrue(XmlAdapter.xmlItemsAdapterFactory(LocalRSSHelper.RSSType.RSS_1) is RSS1ItemsAdapter)
assertTrue(XmlAdapter.xmlItemsAdapterFactory(LocalRSSHelper.RSSType.RSS_2) is RSS2ItemsAdapter)
assertTrue(XmlAdapter.xmlItemsAdapterFactory(LocalRSSHelper.RSSType.ATOM) is ATOMItemsAdapter)