mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-22 07:58:20 -05:00
Strip out Kotlin
I just simply need DI too much, and I don't want to have a Java shell class for everything in Kotlin.
This commit is contained in:
parent
24a384d30e
commit
13417b2ad5
@ -4,7 +4,7 @@ import android.support.v4.util.LruCache;
|
||||
import android.util.Log;
|
||||
|
||||
import org.bspeice.minimalbible.Injector;
|
||||
import org.bspeice.minimalbible.service.osisparser.OsisParser;
|
||||
import org.bspeice.minimalbible.service.format.osisparser.OsisParser;
|
||||
import org.crosswire.common.xml.SAXEventProvider;
|
||||
import org.crosswire.jsword.book.Book;
|
||||
import org.crosswire.jsword.book.BookData;
|
||||
@ -73,6 +73,7 @@ public class VerseLookupService implements Action1<Verse> {
|
||||
/**
|
||||
* Perform the ugly work of getting the actual data for a verse
|
||||
* TODO: Return a verse object, JS should be left to templating.
|
||||
*
|
||||
* @param v The verse to look up
|
||||
* @return The string content of this verse
|
||||
*/
|
||||
|
@ -0,0 +1,88 @@
|
||||
package org.bspeice.minimalbible.service.format.osisparser;
|
||||
|
||||
import org.crosswire.jsword.book.OSISUtil;
|
||||
import org.crosswire.jsword.passage.Verse;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* Created by bspeice on 9/8/14.
|
||||
*/
|
||||
public class OsisParser extends DefaultHandler {
|
||||
|
||||
VerseContent verseContent;
|
||||
// ArrayDeque requires API 9
|
||||
Stack<Boolean> doWrite;
|
||||
Verse verse;
|
||||
|
||||
public OsisParser(Verse v) {
|
||||
this.verse = v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(@NotNull String uri, @NotNull String localName,
|
||||
@NotNull String qName, @NotNull Attributes attributes)
|
||||
throws SAXException {
|
||||
String name = getName(localName, qName);
|
||||
|
||||
if (name.equals(OSISUtil.OSIS_ELEMENT_VERSE)) {
|
||||
doWrite.push(true);
|
||||
verseContent.setId(getId(attributes));
|
||||
} else {
|
||||
doWrite.push(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, @NotNull String localName,
|
||||
@NotNull String qName) throws SAXException {
|
||||
doWrite.pop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||
if (ch != null && doWrite.peek()) {
|
||||
verseContent.appendContent(new String(ch));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startDocument() throws SAXException {
|
||||
super.startDocument();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endDocument() throws SAXException {
|
||||
super.endDocument();
|
||||
}
|
||||
|
||||
public String getName(String eName, String qName) {
|
||||
if (eName != null && eName.length() > 0) {
|
||||
return eName;
|
||||
} else {
|
||||
return qName;
|
||||
}
|
||||
}
|
||||
|
||||
public int getId(Attributes attributes) {
|
||||
if (attributes == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
String osisId = attributes.getValue("", OSISUtil.OSIS_ELEMENT_VERSE);
|
||||
if (osisId == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
String[] parts = osisId.split("\\.");
|
||||
return Integer.valueOf(parts[parts.length - 1]);
|
||||
}
|
||||
|
||||
public VerseContent getContent() {
|
||||
return this.verseContent;
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package org.bspeice.minimalbible.service.format.osisparser;
|
||||
|
||||
import org.apache.commons.lang3.NotImplementedException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by bspeice on 9/9/14.
|
||||
*/
|
||||
public class VerseContent {
|
||||
private int id;
|
||||
private String content;
|
||||
private String chapterTitle;
|
||||
private String paraTitle;
|
||||
private List<VerseReference> references;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getChapterTitle() {
|
||||
return chapterTitle;
|
||||
}
|
||||
|
||||
public void setChapterTitle(String chapterTitle) {
|
||||
this.chapterTitle = chapterTitle;
|
||||
}
|
||||
|
||||
public String getParaTitle() {
|
||||
return paraTitle;
|
||||
}
|
||||
|
||||
public void setParaTitle(String paraTitle) {
|
||||
this.paraTitle = paraTitle;
|
||||
}
|
||||
|
||||
public List<VerseReference> getReferences() {
|
||||
return references;
|
||||
}
|
||||
|
||||
public void setReferences(List<VerseReference> references) {
|
||||
this.references = references;
|
||||
}
|
||||
|
||||
public void appendContent(String content) {
|
||||
this.content += content;
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
throw new NotImplementedException("JSON conversion not implemented yet!");
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package org.bspeice.minimalbible.service.format.osisparser;
|
||||
|
||||
import org.crosswire.jsword.passage.Verse;
|
||||
|
||||
/**
|
||||
* Created by bspeice on 9/9/14.
|
||||
*/
|
||||
public class VerseReference {
|
||||
private Verse verse;
|
||||
private int index;
|
||||
|
||||
public Verse getVerse() {
|
||||
return verse;
|
||||
}
|
||||
|
||||
public void setVerse(Verse verse) {
|
||||
this.verse = verse;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package org.bspeice.minimalbible.service.osisparser
|
||||
|
||||
import org.crosswire.jsword.book.OSISUtil
|
||||
import org.xml.sax.Attributes
|
||||
import org.xml.sax.helpers.DefaultHandler
|
||||
import java.util.ArrayDeque
|
||||
import org.crosswire.jsword.passage.Verse
|
||||
|
||||
/**
|
||||
* Parse the OSIS SAX to an object we can actually use.
|
||||
* Technically we don't need the verse reference currently, but it will make persisting
|
||||
* everything easier later.
|
||||
*/
|
||||
|
||||
class OsisParser(verse: Verse) : DefaultHandler() {
|
||||
|
||||
var content: VerseContent = VerseContent()
|
||||
val doWrite: ArrayDeque<Boolean> = ArrayDeque()
|
||||
val verse: Verse = verse
|
||||
|
||||
// Android Studio complains, but the override below compiles since the java
|
||||
// has a @NotNull contract
|
||||
override fun startElement(uri: String, localName: String,
|
||||
qName: String, attributes: Attributes) {
|
||||
|
||||
val name = getName(localName, qName)
|
||||
|
||||
if (name.equals(OSISUtil.OSIS_ELEMENT_VERSE)) {
|
||||
doWrite.push(true)
|
||||
content.id = getId(attributes)
|
||||
} else {
|
||||
doWrite.push(false)
|
||||
}
|
||||
}
|
||||
|
||||
// Android Studio complains, but the override below compiles since the java
|
||||
// has a @NotNull contract
|
||||
override fun endElement(uri: String?, localName: String, qName: String) {
|
||||
doWrite.pop()
|
||||
}
|
||||
|
||||
override fun characters(ch: CharArray?, start: Int, length: Int) {
|
||||
if (ch != null && doWrite.peek() as Boolean)
|
||||
content.appendContent(String(ch))
|
||||
}
|
||||
|
||||
fun getName(eName: String?, qName: String): String {
|
||||
if (eName != null && eName.length > 0)
|
||||
return eName
|
||||
else
|
||||
return qName
|
||||
}
|
||||
|
||||
fun getId(attrs: Attributes?): Int {
|
||||
if (attrs == null)
|
||||
return 0
|
||||
|
||||
val osisId: String? = attrs.getValue("", OSISUtil.OSIS_ELEMENT_VERSE)
|
||||
if (osisId == null)
|
||||
return 0
|
||||
|
||||
val parts: Array<String> = osisId.split("\\.")
|
||||
return parts[parts.size - 1].toInt()
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +0,0 @@
|
||||
package org.bspeice.minimalbible.service.osisparser
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
/**
|
||||
* Created by bspeice on 9/7/14.
|
||||
*/
|
||||
|
||||
class VerseContent() {
|
||||
public var id: Int = 0
|
||||
public var content: String = ""
|
||||
public var chapterTitle: String = ""
|
||||
public var paraTitle: String = ""
|
||||
public var references: List<VerseReference> = ArrayList()
|
||||
|
||||
public fun appendContent(content: String) {
|
||||
this.content += content
|
||||
}
|
||||
|
||||
public fun toJson() {
|
||||
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package org.bspeice.minimalbible.service.osisparser
|
||||
|
||||
import org.crosswire.jsword.passage.Verse
|
||||
|
||||
/**
|
||||
* Created by bspeice on 9/7/14.
|
||||
*/
|
||||
|
||||
class VerseReference(verse: Verse, index: Int) {
|
||||
public val verse: Verse = verse
|
||||
public val index: Int = index
|
||||
}
|
Loading…
Reference in New Issue
Block a user