4
4
5
5
Readium requires you to instantiate a few components before you can actually open a publication.
6
6
7
- ## Constructing an ` AssetOpener `
7
+ ## Constructing an ` AssetRetriever `
8
8
9
9
First, you need to instantiate an ` HttpClient ` to provide the toolkit the ability to do HTTP requests.
10
10
You can use the Readium ` DefaultHttpClient ` or a custom implementation. In the former case, its callback will
11
11
enable you to perform authentication when required.
12
- Then, you can create an ` AssetOpener ` which will enable you to read content through different schemes and guessing its format.
13
- In addition to an ` HttpClient ` , the ` AssetOpener ` constructor takes a ` ContentResolver ` to support data access through the ` content ` scheme.
12
+ Then, you can create an ` AssetRetriever ` which will enable you to read content through different schemes and guess its format.
13
+ In addition to an ` HttpClient ` , the ` AssetRetriever ` constructor takes a ` ContentResolver ` to support data access through the ` content ` scheme.
14
14
15
15
``` kotlin
16
16
val httpClient = DefaultHttpClient ()
17
17
18
- val assetOpener = AssetOpener (context.contentResolver, httpClient)
18
+ val assetRetriever = AssetRetriever (context.contentResolver, httpClient)
19
19
```
20
20
21
21
## Constructing a ` PublicationOpener `
22
22
23
- The component which can parse an ` Asset ` giving access to a publication to build a proper ` Publication `
23
+ The component which can parse an ` Asset ` giving access to a publication to build a ` Publication `
24
24
object is the ` PublicationOpener ` . Its constructor requires you to pass in:
25
25
26
26
* a ` PublicationParser ` it delegates the parsing work to.
@@ -32,38 +32,39 @@ The easiest way to get a `PublicationParser` is to use the `DefaultPublicationPa
32
32
``` kotlin
33
33
val contentProtections = listOf (lcpService.contentProtection(authentication))
34
34
35
- val publicationParser = DefaultPublicationParser (context, httpClient, assetOpener , pdfFactory)
35
+ val publicationParser = DefaultPublicationParser (context, httpClient, assetRetriever , pdfFactory)
36
36
37
37
val publicationOpener = PublicationOpener (publicationParser, contentProtections)
38
38
```
39
39
40
40
## Bringing the pieces together
41
41
42
- Once you have got an ` AssetOpener ` and a ` PublicationOpener ` , you can eventually open a publication as follows:
42
+ Once you have got an ` AssetRetriever ` and a ` PublicationOpener ` , you can eventually open a publication as follows:
43
43
``` kotlin
44
- val asset = assetOpener .open(url, mediaType)
44
+ val asset = assetRetriever .open(url, mediaType)
45
45
.getOrElse { return error }
46
46
47
47
val publication = publicationOpener.open(asset)
48
48
.getOrElse { return error }
49
49
```
50
50
51
- Persisting the asset media type on the device can significantly improve performance as it is valuable hint
51
+ Persisting the asset media type on the device can significantly improve performance as it is strong hint
52
52
for the content format, especially in case of remote publications.
53
53
54
- ## Extensibility`
54
+ ## Supporting additional formats or URL schemes
55
55
56
56
` DefaultPublicationParser ` accepts additional parsers. You can also use your own parser list
57
57
with ` CompositePublicationParser ` or implement [ PublicationParser] in the way you like.
58
58
59
- ` AssetOpener ` offers an alternative constructor providing better extensibility in a similar way.
59
+ ` AssetRetriever ` offers an alternative constructor providing better extensibility in a similar way.
60
60
This constructor takes several parameters with different responsibilities.
61
61
62
62
* ` ResourceFactory ` determines which schemes you will be able to access content through.
63
- * ` ArchiveOpener ` which kinds of archives your ` AssetOpener ` will be able to open.
64
- * ` FormatSniffer ` which file formats your ` AssetOpener ` will be able to identify.
63
+ * ` ArchiveOpener ` which kinds of archives your ` AssetRetriever ` will be able to open.
64
+ * ` FormatSniffer ` which file formats your ` AssetRetriever ` will be able to identify.
65
65
66
66
For each of these components, you can either use the default implementations or implement yours
67
67
with the composite pattern. ` CompositeResourceFactory ` , ` CompositeArchiveOpener ` and ` CompositeFormatSniffer `
68
68
provide simple implementations trying every item of a list in turns.
69
69
70
+
0 commit comments