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

Commit 936ea48

Browse files
authored
Merge pull request #88 from readium/fixes/publication-models
Refactoring Publication models + XmlParser rewrite with namespaces handling
2 parents c6208fa + a4e5b44 commit 936ea48

File tree

90 files changed

+6841
-1484
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+6841
-1484
lines changed

r2-shared/build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,15 @@ dependencies {
5050
implementation 'nl.komponents.kovenant:kovenant-jvm:3.3.0'
5151
implementation 'nl.komponents.kovenant:kovenant-functional:3.3.0'
5252
implementation 'joda-time:joda-time:2.9.9'
53+
54+
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
5355
testImplementation 'junit:junit:4.12'
56+
testImplementation 'org.assertj:assertj-core:3.14.0'
5457
testImplementation 'org.mockito:mockito-core:2.19.0'
58+
testImplementation 'xmlpull:xmlpull:1.1.3.1'
59+
testImplementation 'net.sf.kxml:kxml2:2.3.0'
60+
testImplementation 'org.json:json:20190722'
61+
5562
androidTestImplementation 'androidx.test:runner:1.2.0'
5663
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
57-
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
5864
}

r2-shared/src/main/java/org/readium/r2/shared/Collection.kt

Lines changed: 0 additions & 49 deletions
This file was deleted.

r2-shared/src/main/java/org/readium/r2/shared/Contributor.kt

Lines changed: 0 additions & 109 deletions
This file was deleted.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Module: r2-shared-kotlin
3+
* Developers: Mickaël Menu
4+
*
5+
* Copyright (c) 2020. Readium Foundation. All rights reserved.
6+
* Use of this source code is governed by a BSD-style license which is detailed in the
7+
* LICENSE file present in the project repository where this source code is maintained.
8+
*/
9+
10+
@file:Suppress("RemoveRedundantQualifierName")
11+
12+
package org.readium.r2.shared
13+
14+
import org.json.JSONObject
15+
import org.readium.r2.shared.extensions.removeLastComponent
16+
import org.readium.r2.shared.publication.Collection
17+
import org.readium.r2.shared.publication.Contributor
18+
import org.readium.r2.shared.publication.Link
19+
import org.readium.r2.shared.publication.Metadata
20+
import org.readium.r2.shared.publication.Properties
21+
import org.readium.r2.shared.publication.Subject
22+
import org.readium.r2.shared.publication.encryption.Encryption
23+
import org.readium.r2.shared.publication.presentation.Presentation
24+
import java.net.URL
25+
26+
27+
@Deprecated("Refactored into [LocalizedString]", ReplaceWith("org.readium.r2.shared.publication.LocalizedString"))
28+
typealias MultilanguageString = org.readium.r2.shared.publication.LocalizedString
29+
30+
@Deprecated("Renamed into [ContentLayout]", ReplaceWith("org.readium.r2.shared.publication.ContentLayout"))
31+
typealias ContentLayoutStyle = org.readium.r2.shared.publication.ContentLayout
32+
33+
@Deprecated("Renamed into [ReadingProgression]", ReplaceWith("org.readium.r2.shared.publication.ReadingProgression"))
34+
typealias PageProgressionDirection = org.readium.r2.shared.publication.ReadingProgression
35+
36+
@Deprecated("Moved to another package", ReplaceWith("org.readium.r2.shared.publication.Publication"))
37+
typealias Publication = org.readium.r2.shared.publication.Publication
38+
39+
@Deprecated("Moved to another package", ReplaceWith("org.readium.r2.shared.publication.Link"))
40+
typealias Link = Link
41+
42+
@Deprecated("Moved to another package", ReplaceWith("org.readium.r2.shared.publication.Properties"))
43+
typealias Properties = Properties
44+
45+
@Deprecated("Moved to another package", ReplaceWith("org.readium.r2.shared.publication.Metadata"))
46+
typealias Metadata = Metadata
47+
48+
@Deprecated("Moved to another package", ReplaceWith("org.readium.r2.shared.publication.Contributor"))
49+
typealias Contributor = Contributor
50+
51+
@Deprecated("Moved to another package", ReplaceWith("org.readium.r2.shared.publication.Collection"))
52+
typealias Collection = Collection
53+
54+
@Deprecated("Moved to another package", ReplaceWith("org.readium.r2.shared.publication.Subject"))
55+
typealias Subject = Subject
56+
57+
@Deprecated("Moved to another package", ReplaceWith("org.readium.r2.shared.publication.encryption.Encryption"))
58+
typealias Encryption = Encryption
59+
60+
@Deprecated("Refactored into [Presentation]", ReplaceWith("org.readium.r2.shared.publication.presentation.Presentation"))
61+
typealias Rendition = Presentation
62+
63+
@Deprecated("Refactored into [EpubLayout]", ReplaceWith("org.readium.r2.shared.publication.epub.EpubLayout"))
64+
typealias RenditionLayout = org.readium.r2.shared.publication.epub.EpubLayout
65+
66+
@Deprecated("Refactored into [Presentation.Overflow]", ReplaceWith("org.readium.r2.shared.publication.presentation.Presentation.Overflow"))
67+
typealias RenditionFlow = Presentation.Overflow
68+
69+
@Deprecated("Refactored into [Presentation.Orientation]", ReplaceWith("org.readium.r2.shared.publication.presentation.Presentation.Orientation"))
70+
typealias RenditionOrientation = Presentation.Orientation
71+
72+
@Deprecated("Refactored into [Presentation.Spread]", ReplaceWith("org.readium.r2.shared.publication.presentation.Presentation.Spread"))
73+
typealias RenditionSpread = Presentation.Spread
74+
75+
@Deprecated("Use [Publication::fromJSON] instead", ReplaceWith("Publication.fromJSON(pubDict)", "org.readium.r2.shared.publication.Publication"))
76+
fun parsePublication(pubDict: JSONObject): org.readium.r2.shared.publication.Publication {
77+
return org.readium.r2.shared.publication.Publication.fromJSON(pubDict)
78+
?: throw Exception("Invalid publication")
79+
}
80+
81+
@Deprecated("Use [Link::fromJSON] instead", ReplaceWith("Link.fromJSON(linkDict)", "org.readium.r2.shared.publication.Link"))
82+
fun parseLink(linkDict: JSONObject, feedUrl: URL? = null): Link =
83+
Link.fromJSON(linkDict, normalizeHref = {
84+
if (feedUrl == null) {
85+
it
86+
} else {
87+
getAbsolute(it, feedUrl.toString())
88+
}
89+
}) ?: Link(href = "#")
90+
91+
@Deprecated("Moved to another package", ReplaceWith("removeLastComponent()", "org.readium.r2.shared.extensions.removeLastComponent"))
92+
fun URL.removeLastComponent(): URL = removeLastComponent()

r2-shared/src/main/java/org/readium/r2/shared/Encryption.kt

Lines changed: 0 additions & 27 deletions
This file was deleted.

r2-shared/src/main/java/org/readium/r2/shared/InjectableType.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
package org.readium.r2.shared
1111

12+
import org.readium.r2.shared.util.MapCompanion
1213
import java.io.Serializable
1314

1415
enum class Injectable(val rawValue: String): Serializable {
1516
Script("scripts"),
1617
Font("fonts"),
1718
Style("styles");
1819

19-
companion object {
20-
operator fun invoke(rawValue: String) = values().firstOrNull { it.rawValue == rawValue }
21-
}
20+
companion object : MapCompanion<String, Injectable>(values(), Injectable::rawValue)
21+
2222
}
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
/*
22
* Module: r2-shared-kotlin
3-
* Developers: Aferdita Muriqi, Clément Baumann
3+
* Developers: Aferdita Muriqi, Clément Baumann, Mickaël Menu
44
*
5-
* Copyright (c) 2018. Readium Foundation. All rights reserved.
5+
* Copyright (c) 2020. Readium Foundation. All rights reserved.
66
* Use of this source code is governed by a BSD-style license which is detailed in the
77
* LICENSE file present in the project repository where this source code is maintained.
88
*/
99

1010
package org.readium.r2.shared
1111

12+
import org.json.JSONArray
1213
import org.json.JSONObject
1314

1415
interface JSONable {
1516

17+
/**
18+
* Serializes the object to its JSON representation.
19+
*/
1620
fun toJSON(): JSONObject
1721

18-
}
22+
}
23+
24+
/**
25+
* Serializes a list of [JSONable] into a [JSONArray].
26+
*/
27+
fun List<JSONable>.toJSON(): JSONArray =
28+
JSONArray(map(JSONable::toJSON))

0 commit comments

Comments
 (0)