Skip to content

Commit

Permalink
Expose Publication.manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
qnga committed Sep 23, 2023
1 parent 5477097 commit 01d6c79
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.readium.r2.opds

import java.util.*
import org.joda.time.DateTime
import org.json.JSONObject
import org.junit.Assert.*
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -223,7 +222,7 @@ class OPDS1ParserTest {
)
)
).toJSON(),
JSONObject(feed.publications[0].jsonManifest)
feed.publications[0].manifest.toJSON()
)

assertJSONEquals(
Expand Down Expand Up @@ -282,7 +281,7 @@ class OPDS1ParserTest {
)
)
).toJSON(),
JSONObject(feed.publications[1].jsonManifest)
feed.publications[1].manifest.toJSON()
)
}

Expand Down Expand Up @@ -356,7 +355,7 @@ class OPDS1ParserTest {
)
)
).toJSON(),
JSONObject(publication!!.jsonManifest)
publication!!.manifest.toJSON()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,33 +77,33 @@ public class Publication(
public var cssStyle: String? = null
) : PublicationServicesHolder {

private val _manifest: Manifest
public val manifest: Manifest

private val services = ListPublicationServicesHolder()

init {
services.services = servicesBuilder.build(Service.Context(manifest, container, services))
_manifest = manifest.copy(
this.manifest = manifest.copy(
links = manifest.links + services.services.map(Service::links).flatten()
)
}

// Shortcuts to manifest properties

public val context: List<String> get() = _manifest.context
public val metadata: Metadata get() = _manifest.metadata
public val links: List<Link> get() = _manifest.links
public val context: List<String> get() = manifest.context
public val metadata: Metadata get() = manifest.metadata
public val links: List<Link> get() = manifest.links

/** Identifies a list of resources in reading order for the publication. */
public val readingOrder: List<Link> get() = _manifest.readingOrder
public val readingOrder: List<Link> get() = manifest.readingOrder

/** Identifies resources that are necessary for rendering the publication. */
public val resources: List<Link> get() = _manifest.resources
public val resources: List<Link> get() = manifest.resources

/** Identifies the collection that contains a table of contents. */
public val tableOfContents: List<Link> get() = _manifest.tableOfContents
public val tableOfContents: List<Link> get() = manifest.tableOfContents

public val subcollections: Map<String, List<PublicationCollection>> get() = _manifest.subcollections
public val subcollections: Map<String, List<PublicationCollection>> get() = manifest.subcollections

@Deprecated(
"Use conformsTo() to check the kind of a publication.",
Expand All @@ -117,8 +117,13 @@ public class Publication(
/**
* Returns the RWPM JSON representation for this [Publication]'s manifest, as a string.
*/
@Deprecated(
"Jsonify the manifest by yourself.",
replaceWith = ReplaceWith("""manifest.toJSON().toString().replace("\\/", "/")"""),
DeprecationLevel.ERROR
)
public val jsonManifest: String
get() = _manifest.toJSON().toString().replace("\\/", "/")
get() = manifest.toJSON().toString().replace("\\/", "/")

/**
* The URL from which the publication resources are relative to, computed from the [Link] with
Expand Down Expand Up @@ -158,7 +163,7 @@ public class Publication(
* Returns whether this publication conforms to the given Readium Web Publication Profile.
*/
public fun conformsTo(profile: Profile): Boolean =
_manifest.conformsTo(profile)
manifest.conformsTo(profile)

/**
* Finds the first [Link] with the given HREF in the publication's links.
Expand All @@ -169,24 +174,24 @@ public class Publication(
* If there's no match, tries again after removing any query parameter and anchor from the
* given [href].
*/
public fun linkWithHref(href: Url): Link? = _manifest.linkWithHref(href)
public fun linkWithHref(href: Url): Link? = manifest.linkWithHref(href)

/**
* Finds the first [Link] having the given [rel] in the publications's links.
*/
public fun linkWithRel(rel: String): Link? = _manifest.linkWithRel(rel)
public fun linkWithRel(rel: String): Link? = manifest.linkWithRel(rel)

/**
* Finds all [Link]s having the given [rel] in the publications's links.
*/
public fun linksWithRel(rel: String): List<Link> = _manifest.linksWithRel(rel)
public fun linksWithRel(rel: String): List<Link> = manifest.linksWithRel(rel)

/**
* Creates a new [Locator] object from a [Link] to a resource of this publication.
*
* Returns null if the resource is not found in this publication.
*/
public fun locatorFromLink(link: Link): Locator? = _manifest.locatorFromLink(link)
public fun locatorFromLink(link: Link): Locator? = manifest.locatorFromLink(link)

/**
* Returns the resource targeted by the given non-templated [link].
Expand Down Expand Up @@ -672,11 +677,11 @@ public class Publication(
public fun link(predicate: (Link) -> Boolean): Link? = null

@Deprecated(
"Use [jsonManifest] instead",
ReplaceWith("jsonManifest"),
"Jsonify the manifest by yourself",
ReplaceWith("manifest.toJSON()"),
level = DeprecationLevel.ERROR
)
public fun toJSON(): JSONObject = JSONObject(jsonManifest)
public fun toJSON(): JSONObject = throw NotImplementedError()

@Deprecated(
"Use `metadata.effectiveReadingProgression` instead",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class PublicationAdapter(
oldItem: Publication,
newItem: Publication
): Boolean {
return oldItem.jsonManifest == newItem.jsonManifest
return oldItem.manifest == newItem.manifest
}
}
}

0 comments on commit 01d6c79

Please sign in to comment.