From 13417b2ad536c0d2c033fbfea96b76fc5ec47cdd Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Tue, 9 Sep 2014 00:10:12 -0400 Subject: [PATCH] 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. --- .../service/book/VerseLookupService.java | 3 +- .../service/format/osisparser/OsisParser.java | 88 +++++++++++++++++++ .../format/osisparser/VerseContent.java | 64 ++++++++++++++ .../format/osisparser/VerseReference.java | 27 ++++++ .../service/osisparser/OsisParser.kt | 66 -------------- .../service/osisparser/VerseContent.kt | 23 ----- .../service/osisparser/VerseReference.kt | 12 --- 7 files changed, 181 insertions(+), 102 deletions(-) create mode 100644 app/src/main/java/org/bspeice/minimalbible/service/format/osisparser/OsisParser.java create mode 100644 app/src/main/java/org/bspeice/minimalbible/service/format/osisparser/VerseContent.java create mode 100644 app/src/main/java/org/bspeice/minimalbible/service/format/osisparser/VerseReference.java delete mode 100644 app/src/main/kotlin/org/bspeice/minimalbible/service/osisparser/OsisParser.kt delete mode 100644 app/src/main/kotlin/org/bspeice/minimalbible/service/osisparser/VerseContent.kt delete mode 100644 app/src/main/kotlin/org/bspeice/minimalbible/service/osisparser/VerseReference.kt diff --git a/app/src/main/java/org/bspeice/minimalbible/service/book/VerseLookupService.java b/app/src/main/java/org/bspeice/minimalbible/service/book/VerseLookupService.java index 6a40538..c7f2f0f 100644 --- a/app/src/main/java/org/bspeice/minimalbible/service/book/VerseLookupService.java +++ b/app/src/main/java/org/bspeice/minimalbible/service/book/VerseLookupService.java @@ -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 { /** * 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 */ diff --git a/app/src/main/java/org/bspeice/minimalbible/service/format/osisparser/OsisParser.java b/app/src/main/java/org/bspeice/minimalbible/service/format/osisparser/OsisParser.java new file mode 100644 index 0000000..cbda048 --- /dev/null +++ b/app/src/main/java/org/bspeice/minimalbible/service/format/osisparser/OsisParser.java @@ -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 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; + } +} diff --git a/app/src/main/java/org/bspeice/minimalbible/service/format/osisparser/VerseContent.java b/app/src/main/java/org/bspeice/minimalbible/service/format/osisparser/VerseContent.java new file mode 100644 index 0000000..e5ed2d2 --- /dev/null +++ b/app/src/main/java/org/bspeice/minimalbible/service/format/osisparser/VerseContent.java @@ -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 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 getReferences() { + return references; + } + + public void setReferences(List references) { + this.references = references; + } + + public void appendContent(String content) { + this.content += content; + } + + public String toJson() { + throw new NotImplementedException("JSON conversion not implemented yet!"); + } +} diff --git a/app/src/main/java/org/bspeice/minimalbible/service/format/osisparser/VerseReference.java b/app/src/main/java/org/bspeice/minimalbible/service/format/osisparser/VerseReference.java new file mode 100644 index 0000000..1d74451 --- /dev/null +++ b/app/src/main/java/org/bspeice/minimalbible/service/format/osisparser/VerseReference.java @@ -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; + } +} diff --git a/app/src/main/kotlin/org/bspeice/minimalbible/service/osisparser/OsisParser.kt b/app/src/main/kotlin/org/bspeice/minimalbible/service/osisparser/OsisParser.kt deleted file mode 100644 index eb7c4ec..0000000 --- a/app/src/main/kotlin/org/bspeice/minimalbible/service/osisparser/OsisParser.kt +++ /dev/null @@ -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 = 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 = osisId.split("\\.") - return parts[parts.size - 1].toInt() - } -} - diff --git a/app/src/main/kotlin/org/bspeice/minimalbible/service/osisparser/VerseContent.kt b/app/src/main/kotlin/org/bspeice/minimalbible/service/osisparser/VerseContent.kt deleted file mode 100644 index 477df88..0000000 --- a/app/src/main/kotlin/org/bspeice/minimalbible/service/osisparser/VerseContent.kt +++ /dev/null @@ -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 = ArrayList() - - public fun appendContent(content: String) { - this.content += content - } - - public fun toJson() { - - } -} \ No newline at end of file diff --git a/app/src/main/kotlin/org/bspeice/minimalbible/service/osisparser/VerseReference.kt b/app/src/main/kotlin/org/bspeice/minimalbible/service/osisparser/VerseReference.kt deleted file mode 100644 index 6a830f0..0000000 --- a/app/src/main/kotlin/org/bspeice/minimalbible/service/osisparser/VerseReference.kt +++ /dev/null @@ -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 -} \ No newline at end of file