mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-12-22 22:58:16 -05:00
Begin parsing OSIS on my own
Also add Kotlin, since I'd like to do what I can to get away from Java.
This commit is contained in:
parent
80238f3cf2
commit
20e4dfe4c4
@ -1,14 +1,17 @@
|
||||
buildscript {
|
||||
ext.kotlin_version = '0.8.11'
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'android-sdk-manager'
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
|
||||
android {
|
||||
compileSdkVersion 20
|
||||
@ -50,6 +53,9 @@ android {
|
||||
targetSdkVersion 20
|
||||
}
|
||||
}
|
||||
sourceSets {
|
||||
main.java.srcDirs += 'src/main/kotlin'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@ -68,9 +74,14 @@ dependencies {
|
||||
compile 'com.android.support:appcompat-v7:20.+'
|
||||
compile 'org.apache.commons:commons-lang3:+'
|
||||
compile 'com.google.code.gson:gson:+'
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
|
||||
androidTestCompile 'com.jayway.awaitility:awaitility:+'
|
||||
androidTestCompile 'org.mockito:mockito-core:+'
|
||||
androidTestCompile 'com.google.dexmaker:dexmaker:+'
|
||||
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:+'
|
||||
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
8
app/src/main/assets/dist/book-bundle.js
vendored
8
app/src/main/assets/dist/book-bundle.js
vendored
@ -9,11 +9,7 @@ app = angular.module('bookApp', []);
|
||||
|
||||
app.controller('BookCtrl', [
|
||||
'$scope', function($scope) {
|
||||
$scope.verses = [
|
||||
{
|
||||
'text': 'hello.'
|
||||
}
|
||||
];
|
||||
$scope.verses = [];
|
||||
return $scope.appendVerse = function(text) {
|
||||
return $scope.verses.push({
|
||||
'text': text
|
||||
@ -31,8 +27,6 @@ window.appendVerse = function(text) {
|
||||
return scope.$apply();
|
||||
};
|
||||
|
||||
console.log(Android.testReturn("Good morning."));
|
||||
|
||||
|
||||
/*
|
||||
Future reference: Get the controller scope like so:
|
||||
|
@ -4,9 +4,7 @@ require 'angular'
|
||||
app = angular.module('bookApp', [])
|
||||
|
||||
app.controller 'BookCtrl', ['$scope', ($scope) ->
|
||||
$scope.verses = [
|
||||
{'text': 'hello.'}
|
||||
];
|
||||
$scope.verses = []
|
||||
|
||||
$scope.appendVerse = (text) ->
|
||||
$scope.verses.push {'text': text}
|
||||
@ -23,8 +21,6 @@ window.appendVerse = (text) ->
|
||||
# Since we're calling outside of angular, we need to manually apply
|
||||
scope.$apply()
|
||||
|
||||
console.log Android.testReturn "Good morning."
|
||||
|
||||
###
|
||||
Future reference: Get the controller scope like so:
|
||||
angular.element($("<controller-element>")).scope().<function>
|
||||
|
@ -92,6 +92,12 @@ public class BibleViewerModules {
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
BookManager bookManager() {
|
||||
return new BookManager();
|
||||
}
|
||||
|
||||
@Provides
|
||||
VersificationUtil provideVersificationUtil() {
|
||||
return new VersificationUtil();
|
||||
|
@ -114,8 +114,7 @@ public class BookFragment extends BaseFragment {
|
||||
Verse initial = new Verse(vUtil.getVersification(mBook.get()),
|
||||
BibleBook.GEN, 1, 1);
|
||||
super.onPageFinished(view, url);
|
||||
// invokeJavascript("appendVerse", lookupService.getHTMLVerse(initial));
|
||||
invokeJavascript("appendVerse", "Testing string...");
|
||||
invokeJavascript("appendVerse", lookupService.getHTMLVerse(initial));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4,8 +4,7 @@ import android.support.v4.util.LruCache;
|
||||
import android.util.Log;
|
||||
|
||||
import org.bspeice.minimalbible.Injector;
|
||||
import org.bspeice.minimalbible.service.format.osistohtml.OsisToHtmlParameters;
|
||||
import org.bspeice.minimalbible.service.format.osistohtml.OsisToHtmlSaxHandler;
|
||||
import org.bspeice.minimalbible.service.osisparser.OsisParser;
|
||||
import org.crosswire.common.xml.SAXEventProvider;
|
||||
import org.crosswire.jsword.book.Book;
|
||||
import org.crosswire.jsword.book.BookData;
|
||||
@ -81,10 +80,11 @@ public class VerseLookupService implements Action1<Verse> {
|
||||
BookData bookData = new BookData(book, v);
|
||||
try {
|
||||
SAXEventProvider provider = bookData.getSAXEventProvider();
|
||||
OsisToHtmlSaxHandler handler = new OsisToHtmlSaxHandler(new OsisToHtmlParameters());
|
||||
// OsisToHtmlSaxHandler handler = new OsisToHtmlSaxHandler(new OsisToHtmlParameters());
|
||||
OsisParser handler = new OsisParser(v);
|
||||
provider.provideSAXEvents(handler);
|
||||
Log.e(this.getClass().getName(), handler.toString());
|
||||
return handler.toString();
|
||||
return handler.getContent().getContent();
|
||||
} catch (BookException e) {
|
||||
e.printStackTrace();
|
||||
return "Unable to locate " + v.toString() + "!";
|
||||
|
@ -0,0 +1,66 @@
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
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() {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
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