Skip to content

Commit 52934c3

Browse files
authored
Add content and search services for RWP with HTML resources (#682)
1 parent 38b1a81 commit 52934c3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

readium/streamer/src/main/java/org/readium/r2/streamer/parser/readium/ReadiumWebPubParser.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@ package org.readium.r2.streamer.parser.readium
1010

1111
import android.content.Context
1212
import org.readium.r2.shared.DelicateReadiumApi
13+
import org.readium.r2.shared.ExperimentalReadiumApi
1314
import org.readium.r2.shared.InternalReadiumApi
1415
import org.readium.r2.shared.publication.Manifest
1516
import org.readium.r2.shared.publication.Publication
1617
import org.readium.r2.shared.publication.services.InMemoryCacheService
1718
import org.readium.r2.shared.publication.services.PerResourcePositionsService
1819
import org.readium.r2.shared.publication.services.WebPositionsService
1920
import org.readium.r2.shared.publication.services.cacheServiceFactory
21+
import org.readium.r2.shared.publication.services.content.DefaultContentService
22+
import org.readium.r2.shared.publication.services.content.contentServiceFactory
23+
import org.readium.r2.shared.publication.services.content.iterators.HtmlResourceContentIterator
2024
import org.readium.r2.shared.publication.services.locatorServiceFactory
2125
import org.readium.r2.shared.publication.services.positionsServiceFactory
26+
import org.readium.r2.shared.publication.services.search.StringSearchService
27+
import org.readium.r2.shared.publication.services.search.searchServiceFactory
2228
import org.readium.r2.shared.util.AbsoluteUrl
2329
import org.readium.r2.shared.util.DebugError
2430
import org.readium.r2.shared.util.Try
@@ -52,6 +58,7 @@ import timber.log.Timber
5258
* of positions in a reflowable resource of a web publication conforming to the
5359
* EPUB profile.
5460
*/
61+
@OptIn(ExperimentalReadiumApi::class)
5562
public class ReadiumWebPubParser(
5663
private val context: Context? = null,
5764
private val httpClient: HttpClient,
@@ -115,6 +122,16 @@ public class ReadiumWebPubParser(
115122
else ->
116123
null
117124
}
125+
126+
// Add content- and search-service for WebPubs with HTML contents.
127+
if (manifest.readingOrder.any { it.mediaType?.isHtml == true }) {
128+
contentServiceFactory = DefaultContentService.createFactory(
129+
resourceContentIteratorFactories = listOf(
130+
HtmlResourceContentIterator.Factory()
131+
)
132+
)
133+
searchServiceFactory = StringSearchService.createDefaultFactory()
134+
}
118135
}
119136

120137
val publicationBuilder = Publication.Builder(manifest, container, servicesBuilder)

0 commit comments

Comments
 (0)