Skip to content

Commit

Permalink
Update kotlin-xml-builder dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinokuni committed Nov 8, 2024
1 parent 47b40ac commit 783276a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
63 changes: 33 additions & 30 deletions api/src/main/java/com/readrops/api/opml/OPMLParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,67 @@ import com.gitlab.mvysny.konsumexml.konsumeXml
import com.readrops.api.utils.exceptions.ParseException
import com.readrops.db.entities.Feed
import com.readrops.db.entities.Folder
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.redundent.kotlin.xml.xml
import java.io.InputStream
import java.io.OutputStream

object OPMLParser {

suspend fun read(stream: InputStream): Map<Folder?, List<Feed>> {
suspend fun read(stream: InputStream): Map<Folder?, List<Feed>> = withContext(Dispatchers.IO) {
try {
val adapter = OPMLAdapter()
val opml = adapter.fromXml(stream.konsumeXml())

stream.close()
return opml
opml
} catch (e: Exception) {
throw ParseException(e.message)
}
}

suspend fun write(foldersAndFeeds: Map<Folder?, List<Feed>>, outputStream: OutputStream) {
val opml = xml("opml") {
attribute("version", "2.0")
suspend fun write(foldersAndFeeds: Map<Folder?, List<Feed>>, outputStream: OutputStream) =
withContext(Dispatchers.IO) {
val opml = xml("opml") {
attribute("version", "2.0")

"head" {
-"Subscriptions"
}
"head" {
-"Subscriptions"
}

"body" {
for (folderAndFeeds in foldersAndFeeds) {
if (folderAndFeeds.key != null) { // feeds with folder
"outline" {
folderAndFeeds.key?.name?.let {
attribute("title", it)
attribute("text", it)
}
"body" {
for (folderAndFeeds in foldersAndFeeds) {
if (folderAndFeeds.key != null) { // feeds with folder
"outline" {
folderAndFeeds.key?.name?.let {
attribute("title", it)
attribute("text", it)
}

for (feed in folderAndFeeds.value) {
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) { // feeds without folder
"outline" {
feed.name?.let { attribute("title", it) }
attribute("xmlUrl", feed.url!!)
feed.siteUrl?.let { attribute("htmlUrl", it) }
}
}
}
} 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.flush()
outputStream.close()
}
outputStream.write(opml.toString().toByteArray())
outputStream.flush()
outputStream.close()
}
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ aboutlibraries = { module = "com.mikepenz.aboutlibraries.plugin:aboutlibraries-p
aboutlibraries-composem3 = { module = "com.mikepenz:aboutlibraries-compose-m3", version.ref = "about_libraries" }

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"

Expand Down

0 comments on commit 783276a

Please sign in to comment.