Skip to content
This repository has been archived by the owner on Jul 29, 2022. It is now read-only.

Fix broken server if a publication file contains special characters #306

Merged
merged 1 commit into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import android.speech.tts.UtteranceProgressListener
import android.widget.Toast
import org.jsoup.Jsoup
import org.jsoup.select.Elements
import org.readium.r2.navigator.BASE_URL
import org.readium.r2.navigator.IR2TTS
import org.readium.r2.navigator.VisualNavigator
import org.readium.r2.shared.publication.Publication
Expand Down Expand Up @@ -186,10 +185,12 @@ class R2ScreenReader(var context: Context, var ttsCallbacks: IR2TTS, var navigat
private fun setUtterances(): Boolean {
//Load resource as sentences
utterances = mutableListOf()
splitResourceAndAddToUtterances("$BASE_URL:$port/$epubName${items[resourceIndex].href}")
val url = Publication.localUrlOf(filename = epubName, port = port, href = items[resourceIndex].href)
splitResourceAndAddToUtterances(url)

// while (++resourceIndex < items.size && utterances.size == 0) {
// splitResourceAndAddToUtterances("$BASE_URL:$port/$epubName${items[resourceIndex].href}")
// val url = Publication.localUrlOf(filename = epubName, port = port, href = items[resourceIndex].href)
// splitResourceAndAddToUtterances(url)
// }
//
// if (resourceIndex == items.size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ import org.json.JSONArray
import org.json.JSONObject
import org.readium.r2.shared.JSONable
import org.readium.r2.shared.publication.Link
import org.readium.r2.shared.publication.Publication
import org.readium.r2.testapp.db.PositionsDatabase
import java.net.URI
import java.net.URL


class R2SyntheticPageList(private val positionsDB: PositionsDatabase, private val bookID: Long, private val publicationIdentifier: String) : AsyncTask<Triple<String, String, List<Link>>, String, MutableList<Position>>() {
class R2SyntheticPageList(private val positionsDB: PositionsDatabase, private val bookID: Long, private val publicationIdentifier: String) : AsyncTask<Triple<Int, String, List<Link>>, String, MutableList<Position>>() {

private val syntheticPageList = mutableListOf<Position>()
private var pageNumber: Long = 0
Expand All @@ -29,7 +30,7 @@ class R2SyntheticPageList(private val positionsDB: PositionsDatabase, private va
positionsDB.positions.init(bookID)
}

override fun doInBackground(vararg p0: Triple<String, String, List<Link>>): MutableList<Position> {
override fun doInBackground(vararg p0: Triple<Int, String, List<Link>>): MutableList<Position> {

for (uri in p0) {
for (i in 0 until uri.third.size) {
Expand All @@ -49,7 +50,7 @@ class R2SyntheticPageList(private val positionsDB: PositionsDatabase, private va
positionsDB.positions.storeSyntheticPageList(bookID, jsonPageList)
}

private fun createSyntheticPages(baseURL: String, epubName: String, link: Link) {
private fun createSyntheticPages(port: Int, epubName: String, link: Link) {
val resourceURL: URL

val resourceHref = link.href
Expand All @@ -58,7 +59,7 @@ class R2SyntheticPageList(private val positionsDB: PositionsDatabase, private va
resourceURL = if (URI(resourceHref).isAbsolute) {
URL(resourceHref)
} else {
URL(baseURL + epubName + resourceHref)
URL(Publication.localUrlOf(filename = epubName, port = port, href = resourceHref))
}

val text: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ import org.readium.r2.streamer.parser.divina.DiViNaConstant
import org.readium.r2.streamer.parser.divina.DiViNaParser
import org.readium.r2.streamer.parser.epub.EPUBConstant
import org.readium.r2.streamer.parser.epub.EpubParser
import org.readium.r2.streamer.server.BASE_URL
import org.readium.r2.streamer.server.Server
import org.readium.r2.testapp.BuildConfig.DEBUG
import org.readium.r2.testapp.R
Expand Down Expand Up @@ -654,8 +653,8 @@ open class LibraryActivity : AppCompatActivity(), BooksAdapter.RecyclerViewClick
val syntheticPageList = R2SyntheticPageList(positionsDB, book.id!!, pub.metadata.identifier!!)

when (pub.type) {
Publication.TYPE.EPUB -> syntheticPageList.execute(Triple("$BASE_URL:$localPort/", book.fileName!!, pub.readingOrder))
Publication.TYPE.WEBPUB -> syntheticPageList.execute(Triple("", book.fileName!!, pub.readingOrder))
Publication.TYPE.EPUB -> syntheticPageList.execute(Triple(localPort, book.fileName!!, pub.readingOrder))
Publication.TYPE.WEBPUB -> syntheticPageList.execute(Triple(0, book.fileName!!, pub.readingOrder))
else -> {
//no page list
}
Expand Down