MinimalBible/app/src/main/kotlin/org/bspeice/minimalbible/service/format/osisparser/OsisParser.kt

38 lines
1.1 KiB
Kotlin
Raw Normal View History

2014-09-10 22:41:34 -04:00
package org.bspeice.minimalbible.service.format.osisparser
import org.xml.sax.helpers.DefaultHandler
import org.crosswire.jsword.passage.Verse
import java.util.ArrayDeque
import org.xml.sax.Attributes
import org.crosswire.jsword.book.OSISUtil
/**
* Created by bspeice on 9/10/14.
*/
class OsisParser(v: Verse?) : DefaultHandler() {
2014-09-10 22:41:34 -04:00
val verseContent: VerseContent? = when (v) {
is Verse -> VerseContent(v) // not null
else -> null
}
// TODO: Implement a stack to keep min API 8
2014-09-10 22:41:34 -04:00
val doWrite = ArrayDeque<Boolean>()
override fun startElement(uri: String, localName: String,
qName: String, attributes: Attributes) {
when (localName) {
OSISUtil.OSIS_ELEMENT_VERSE -> doWrite.push(true)
else -> doWrite.push(false)
}
2014-09-10 22:41:34 -04:00
}
override fun endElement(uri: String, localName: String, qName: String) {
2014-09-10 22:41:34 -04:00
doWrite.pop()
}
override fun characters(ch: CharArray, start: Int, length: Int) {
2014-10-22 22:21:42 -04:00
if (doWrite.peek())
verseContent?.appendContent(String(ch))
2014-09-10 22:41:34 -04:00
}
}