Skip to content

Commit

Permalink
Adds caching of binary data and sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
asm0dey committed Jul 26, 2023
1 parent 9c73011 commit 8293259
Show file tree
Hide file tree
Showing 76 changed files with 1,774 additions and 1,729 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ conversion.log
fb2c
fb2c.conf.toml
fb2c_*.zip
/cache/
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {
}

group = "io.github.asm0dey"
version = "0.0.18"
version = "0.0.19"
application {
mainClass.set("io.github.asm0dey.ApplicationKt")

Expand Down Expand Up @@ -68,13 +68,15 @@ dependencies {
// utils
implementation(libs.commons.codec)
implementation(libs.kotlin.process)
implementation(libs.ehcache)
// xml
implementation(libs.jsoup)
implementation(libs.jaxb.runtime)
implementation(libs.xmlutil.serialization.jvm)
implementation(libs.xmlutil.ktor)
implementation(libs.kotlin.xml.builder)
implementation(libs.kotlinx.serialization.json)
implementation(libs.kotlinx.serialization.cbor)
// logging
implementation(libs.tinylog.api.kotlin)
implementation(libs.slf4j.tinylog)
Expand Down
6 changes: 4 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ktor = "2.3.2"

kodein-di = "7.20.2"

kotlinx-coroutines = "1.7.2"
kotlinx-coroutines = "1.7.3"

netty-tcnative = "2.0.61.Final"

Expand Down Expand Up @@ -71,7 +71,7 @@ slf4j-tinylog = { group = "org.tinylog", name = "slf4j-tinylog", version.ref = "

tinylog-impl = { group = "org.tinylog", name = "tinylog-impl", version.ref = "tinylog" }

htmx-org = "org.webjars.npm:htmx.org:1.9.3"
htmx-org = "org.webjars.npm:htmx.org:1.9.4"

hyperscript-org = "org.webjars.npm:hyperscript.org:0.9.9"

Expand Down Expand Up @@ -116,7 +116,9 @@ ktor-server-netty-jvm = { group = "io.ktor", name = "ktor-server-netty-jvm", ver
kotlin-process = "com.github.pgreze:kotlin-process:1.4.1"

kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinx-serialization" }
kotlinx-serialization-cbor = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-cbor", version.ref = "kotlinx-serialization" }

kotlin-serialization = { group = "org.jetbrains.kotlin", name = "kotlin-serialization", version.ref = "kotlin" }

zip4j = { group = "net.lingala.zip4j", name = "zip4j", version = "2.11.5" }
ehcache = "org.ehcache:ehcache:3.10.8"
96 changes: 0 additions & 96 deletions src/main/kotlin/com/kursx/parser/fb2/Annotation.java

This file was deleted.

75 changes: 75 additions & 0 deletions src/main/kotlin/com/kursx/parser/fb2/Annotation.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.kursx.parser.fb2

import kotlinx.serialization.Serializable
import org.jsoup.Jsoup
import org.w3c.dom.Node
import java.io.StringWriter
import javax.xml.transform.TransformerException
import javax.xml.transform.TransformerFactory
import javax.xml.transform.dom.DOMSource
import javax.xml.transform.stream.StreamResult

//http://www.fictionbook.org/index.php/Элемент_annotation
@Suppress("unused")
@Serializable
open class Annotation : IdElement {
var text = ""
private set
var lang: String? = null
var elements: ArrayList<Element>? = null

constructor()
internal constructor(node: Node) : super(node) {
try {
val writer = StringWriter()
TransformerFactory.newInstance().newTransformer().transform(DOMSource(node), StreamResult(writer))
val xml = writer.toString()
text = Jsoup.parseBodyFragment(xml).body().text()
} catch (ignored: TransformerException) {
}
val map = node.attributes
for (index in 0 until map.length) {
val attr = map.item(index)
if (attr.nodeName == "xml:lang") {
lang = attr.nodeValue
}
}
val nodeList = node.childNodes
for (i in 0 until nodeList.length) {
val paragraph = nodeList.item(i)
if (elements == null) elements = ArrayList()
when (paragraph.nodeName) {
"p" -> elements!!.add(P(paragraph))
"poem" -> elements!!.add(Poem(paragraph))
"cite" -> elements!!.add(Cite(paragraph))
"subtitle" -> elements!!.add(Subtitle(paragraph))
"empty-line" -> elements!!.add(EmptyLine())
"table" -> elements!!.add(Table())
}
}
}

val annotations: ArrayList<Element>
get() = if (elements == null) ArrayList() else elements!!

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as Annotation

if (text != other.text) return false
if (lang != other.lang) return false
if (elements != other.elements) return false

return true
}

override fun hashCode(): Int {
var result = text.hashCode()
result = 31 * result + (lang?.hashCode() ?: 0)
result = 31 * result + (elements?.hashCode() ?: 0)
return result
}

}
61 changes: 0 additions & 61 deletions src/main/kotlin/com/kursx/parser/fb2/Binary.java

This file was deleted.

53 changes: 53 additions & 0 deletions src/main/kotlin/com/kursx/parser/fb2/Binary.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.kursx.parser.fb2

import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.Serializable
import kotlinx.serialization.cbor.ByteString
import org.w3c.dom.Node

//http://www.fictionbook.org/index.php/Элемент_binary
@Suppress("unused")
@Serializable
class Binary : IdElement {
var contentType: String? = null
lateinit var binary: String

constructor()
internal constructor(node: Node) : super(node) {
binary = node.textContent
val map = node.attributes
for (index in 0 until map.length) {
val attr = map.item(index)
if ("content-type" == attr.nodeName) {
contentType = attr.nodeValue
}
}
}

override fun toString(): String {
return "Binary{" +
"contentType='" + contentType + '\'' +
", binary='" + binary + '\'' +
", id='" + id + '\'' +
'}'
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as Binary

if (contentType != other.contentType) return false
if (binary != other.binary) return false

return true
}

override fun hashCode(): Int {
var result = contentType?.hashCode() ?: 0
result = 31 * result + binary.hashCode()
return result
}

}
Loading

0 comments on commit 8293259

Please sign in to comment.