-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds caching of binary data and sizes
- Loading branch information
Showing
76 changed files
with
1,774 additions
and
1,729 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,3 +40,4 @@ conversion.log | |
fb2c | ||
fb2c.conf.toml | ||
fb2c_*.zip | ||
/cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} |
Oops, something went wrong.