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:
Bradlee Speice
2014-09-09 00:10:12 -04:00
parent 24a384d30e
commit 13417b2ad5
7 changed files with 181 additions and 102 deletions

View File

@ -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
*/

View File

@ -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;
}
}

View File

@ -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!");
}
}

View File

@ -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;
}
}