Skip to content

Commit

Permalink
Fix #3191 (Crash: NoSuchKeyException: No entry for '06635 ' in Strong…
Browse files Browse the repository at this point in the history
…sHebrewRU)
  • Loading branch information
tuomas2 committed Feb 1, 2024
1 parent a22f885 commit e699403
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class LinkControl @Inject constructor(

enum class StrongsKeyType {HEBREW, GREEK}

private fun getStrongsKey(book: Book, key: String): BookAndKey? {
fun getStrongsKey(book: Book, key: String): BookAndKey? {
val match = Regex("^([GH])(0*)([0-9]+).*").find(key)
val category = match?.groups?.get(1)?.value
?: if(book.isHebrewDef) "H"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import org.crosswire.jsword.book.Books
import org.crosswire.jsword.book.sword.SwordBook
import org.crosswire.jsword.book.sword.SwordGenBook
import org.crosswire.jsword.passage.KeyUtil
import org.crosswire.jsword.passage.NoSuchKeyException
import org.crosswire.jsword.passage.RangedPassage
import org.crosswire.jsword.passage.Verse
import org.crosswire.jsword.passage.VerseFactory
Expand All @@ -82,6 +83,7 @@ class BibleJavascriptInterface(
private val bibleView: BibleView
) {
private val currentPageManager: CurrentPageManager get() = bibleView.window.pageManager
val linkControl get() = bibleView.linkControl
val bookmarkControl get() = bibleView.bookmarkControl
val downloadControl get() = bibleView.downloadControl

Expand Down Expand Up @@ -223,7 +225,7 @@ class BibleJavascriptInterface(
val backend = book.backend as EpubBackend
val key = backend.getKey(toKeyStr, toId) ?: return
scope.launch(Dispatchers.Main) {
bibleView.linkControl.showLink(book, BookAndKey(key, book, htmlId = toId))
linkControl.showLink(book, BookAndKey(key, book, htmlId = toId))
}
}

Expand All @@ -238,15 +240,15 @@ class BibleJavascriptInterface(
val lnk = "${bibleBook.osis} $rest"
val bibleLink = BibleView.BibleLink("content", target=lnk)
scope.launch(Dispatchers.Main) {
bibleView.linkControl.loadApplicationUrl(bibleLink)
linkControl.loadApplicationUrl(bibleLink)
}
}
link.startsWith("S:") -> {
// MyBible strongs
val (prefix, rest) = link.split(":", limit=2)
val bibleLink = BibleView.BibleLink("strong", target=rest)
scope.launch(Dispatchers.Main) {
bibleView.linkControl.loadApplicationUrl(bibleLink)
linkControl.loadApplicationUrl(bibleLink)
}
}
link.startsWith("#b") -> {
Expand All @@ -257,15 +259,15 @@ class BibleJavascriptInterface(
val lnk = "${bibleBook.osis}.$chapInt.$verInt"
val bibleLink = BibleView.BibleLink("content", target=lnk)
scope.launch(Dispatchers.Main) {
bibleView.linkControl.loadApplicationUrl(bibleLink)
linkControl.loadApplicationUrl(bibleLink)
}
}
link.startsWith("#s") || link.startsWith("#d") -> {
// MySword strongs links
val rest = link.substring(2)
val bibleLink = BibleView.BibleLink("strong", target=rest)
scope.launch(Dispatchers.Main) {
bibleView.linkControl.loadApplicationUrl(bibleLink)
linkControl.loadApplicationUrl(bibleLink)
}
}
else -> {
Expand Down Expand Up @@ -401,14 +403,14 @@ class BibleJavascriptInterface(
@JavascriptInterface
fun openStudyPad(labelId: String, bookmarkId: String) {
scope.launch(Dispatchers.Main) {
bibleView.linkControl.openStudyPad(IdType(labelId), IdType(bookmarkId))
linkControl.openStudyPad(IdType(labelId), IdType(bookmarkId))
}
}

@JavascriptInterface
fun openMyNotes(v11n: String, ordinal: Int) {
scope.launch(Dispatchers.Main) {
bibleView.linkControl.openMyNotes(v11n, ordinal)
linkControl.openMyNotes(v11n, ordinal)
}
}

Expand All @@ -429,7 +431,12 @@ class BibleJavascriptInterface(
fun speakGeneric(bookInitials: String, osisRef: String, ordinal: Int, endOrdinal: Int) {
scope.launch(Dispatchers.Main) {
val book = Books.installed().getBook(bookInitials)
val origKey = book.getKey(osisRef)
val origKey = try {
book.getKey(osisRef)
} catch (e: NoSuchKeyException) {
val bookAndKey = linkControl.getStrongsKey(book, osisRef)
bookAndKey?.key ?: return@launch
}
val key = (origKey as? RangedPassage)?.toVerseRange ?: try {KeyUtil.getVerse(origKey)} catch (e: ClassCastException) {origKey}
val ordinalRange = OrdinalRange(ordinal, positiveOrNull(endOrdinal))
val bookAndKey = BookAndKey(key, book, ordinalRange)
Expand Down

0 comments on commit e699403

Please sign in to comment.