Update kotlin-xml-builder dependency

This commit is contained in:
Shinokuni 2024-11-08 17:19:06 +01:00
parent 47b40ac0eb
commit 783276a27b
2 changed files with 34 additions and 31 deletions

View File

@ -4,42 +4,54 @@ import com.gitlab.mvysny.konsumexml.konsumeXml
import com.readrops.api.utils.exceptions.ParseException import com.readrops.api.utils.exceptions.ParseException
import com.readrops.db.entities.Feed import com.readrops.db.entities.Feed
import com.readrops.db.entities.Folder import com.readrops.db.entities.Folder
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.redundent.kotlin.xml.xml import org.redundent.kotlin.xml.xml
import java.io.InputStream import java.io.InputStream
import java.io.OutputStream import java.io.OutputStream
object OPMLParser { object OPMLParser {
suspend fun read(stream: InputStream): Map<Folder?, List<Feed>> { suspend fun read(stream: InputStream): Map<Folder?, List<Feed>> = withContext(Dispatchers.IO) {
try { try {
val adapter = OPMLAdapter() val adapter = OPMLAdapter()
val opml = adapter.fromXml(stream.konsumeXml()) val opml = adapter.fromXml(stream.konsumeXml())
stream.close() stream.close()
return opml opml
} catch (e: Exception) { } catch (e: Exception) {
throw ParseException(e.message) throw ParseException(e.message)
} }
} }
suspend fun write(foldersAndFeeds: Map<Folder?, List<Feed>>, outputStream: OutputStream) { suspend fun write(foldersAndFeeds: Map<Folder?, List<Feed>>, outputStream: OutputStream) =
val opml = xml("opml") { withContext(Dispatchers.IO) {
attribute("version", "2.0") val opml = xml("opml") {
attribute("version", "2.0")
"head" { "head" {
-"Subscriptions" -"Subscriptions"
} }
"body" { "body" {
for (folderAndFeeds in foldersAndFeeds) { for (folderAndFeeds in foldersAndFeeds) {
if (folderAndFeeds.key != null) { // feeds with folder if (folderAndFeeds.key != null) { // feeds with folder
"outline" { "outline" {
folderAndFeeds.key?.name?.let { folderAndFeeds.key?.name?.let {
attribute("title", it) attribute("title", it)
attribute("text", it) attribute("text", it)
}
for (feed in folderAndFeeds.value) {
"outline" {
feed.name?.let { attribute("title", it) }
attribute("xmlUrl", feed.url!!)
feed.siteUrl?.let { attribute("htmlUrl", it) }
}
}
} }
} else {
for (feed in folderAndFeeds.value) { for (feed in folderAndFeeds.value) { // feeds without folder
"outline" { "outline" {
feed.name?.let { attribute("title", it) } feed.name?.let { attribute("title", it) }
attribute("xmlUrl", feed.url!!) attribute("xmlUrl", feed.url!!)
@ -47,21 +59,12 @@ object OPMLParser {
} }
} }
} }
} else {
for (feed in folderAndFeeds.value) { // feeds without folder
"outline" {
feed.name?.let { attribute("title", it) }
attribute("xmlUrl", feed.url!!)
feed.siteUrl?.let { attribute("htmlUrl", it) }
}
}
} }
} }
} }
}
outputStream.write(opml.toString().toByteArray()) outputStream.write(opml.toString().toByteArray())
outputStream.flush() outputStream.flush()
outputStream.close() outputStream.close()
} }
} }

View File

@ -80,7 +80,7 @@ aboutlibraries = { module = "com.mikepenz.aboutlibraries.plugin:aboutlibraries-p
aboutlibraries-composem3 = { module = "com.mikepenz:aboutlibraries-compose-m3", version.ref = "about_libraries" } aboutlibraries-composem3 = { module = "com.mikepenz:aboutlibraries-compose-m3", version.ref = "about_libraries" }
konsumexml = "com.gitlab.mvysny.konsume-xml:konsume-xml:1.1" konsumexml = "com.gitlab.mvysny.konsume-xml:konsume-xml:1.1"
kotlinxmlbuilder = "org.redundent:kotlin-xml-builder:1.7.3" #TODO update this kotlinxmlbuilder = "org.redundent:kotlin-xml-builder:1.9.1"
jdk-desugar = "com.android.tools:desugar_jdk_libs_nio:2.1.2" jdk-desugar = "com.android.tools:desugar_jdk_libs_nio:2.1.2"