|
| 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() |
0 commit comments