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

refactored bookmarks and added locators #28

Merged
merged 26 commits into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
43423b1
Creation of the Locator model
IdMostapha Jul 30, 2018
7a993d0
Making Locator and Location an JSONable class + Turning LocatorText i…
IdMostapha Jul 30, 2018
f143841
Commenting the Locator and Location
IdMostapha Jul 30, 2018
3b87314
Changing the toJsonString() methods to toString() methods
IdMostapha Aug 3, 2018
4d223c0
updating the comments + fixing Location.toString()
IdMostapha Aug 3, 2018
55c913d
Changing id for pubId for more perspicacity
IdMostapha Aug 3, 2018
4ab35f7
Merge branch 'develop' of github.com:readium/r2-shared-kotlin into fe…
IdMostapha Aug 9, 2018
45684dd
Adding of spineHref to Locator + verification on the position / progr…
IdMostapha Aug 9, 2018
2450b4d
Timestamp is now handled by Locator directly
IdMostapha Aug 9, 2018
7748456
Add of xpath variable to Location
IdMostapha Aug 9, 2018
50eb04b
as publicationId is inferred, it has been removed from the JSONObject…
pavelric Aug 9, 2018
d83e479
Draft of locators unit test
IdMostapha Aug 9, 2018
f3fe178
Use of Gson library to turn the object into a Json
IdMostapha Aug 10, 2018
22731bc
Introducing to LocatorUtils, meant to hold all the functions related …
IdMostapha Aug 10, 2018
a9ccae0
Update of the copyright
IdMostapha Aug 10, 2018
7ea59e1
inverted parameters in locators constructor
pavelric Aug 17, 2018
500f9ed
change 'timestamp' parameter to 'created'
pavelric Aug 22, 2018
12bc7b0
moved file to testapp
pavelric Aug 22, 2018
7c16dce
refactored spineHref into resourceHref
pavelric Aug 27, 2018
8f09ef1
Merge branch 'develop' into feature/locators
aferditamuriqi Sep 1, 2018
5076d4b
renamed json function
aferditamuriqi Sep 1, 2018
6a135cc
refactored Locator Model
aferditamuriqi Sep 1, 2018
42474a8
moved test into test package
aferditamuriqi Sep 1, 2018
aae3f40
Merge branch 'develop' into feature/locators
aferditamuriqi Sep 25, 2018
ce2260f
renamed function
aferditamuriqi Sep 25, 2018
0af775d
refactored locators
aferditamuriqi Sep 25, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions r2-shared/r2-shared.iml
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,19 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/attr" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/check-manifest" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/extractedTypedefs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/intermediate-jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/library_and_local_jars_jni" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/packaged-aidl" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/packaged-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/packagedAssets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/packaged_res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/public_res" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Contributor : JSONable, Serializable {
var name: String? = null
get() = multilanguageName.singleString

override fun getJSON(): JSONObject {
override fun toJSON(): JSONObject {
val obj = JSONObject()
obj.put("name", name)
if (roles.isNotEmpty()) {
Expand Down
2 changes: 1 addition & 1 deletion r2-shared/src/main/java/org/readium/r2/shared/JSONable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ import org.json.JSONObject

interface JSONable {

fun getJSON(): JSONObject
fun toJSON(): JSONObject

}
2 changes: 1 addition & 1 deletion r2-shared/src/main/java/org/readium/r2/shared/Link.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Link : JSONable, Serializable {
return properties.encryption != null
}

override fun getJSON(): JSONObject {
override fun toJSON(): JSONObject {
val json = JSONObject()
json.putOpt("title", title)
json.putOpt("type", typeLink)
Expand Down
186 changes: 186 additions & 0 deletions r2-shared/src/main/java/org/readium/r2/shared/Locator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/*
* Module: r2-shared-kotlin
* Developers: Aferdita Muriqi, Mostapha Idoubihi, Paul Stoica
*
* Copyright (c) 2018. Readium Foundation. All rights reserved.
* Use of this source code is governed by a BSD-style license which is detailed in the
* LICENSE file present in the project repository where this source code is maintained.
*/

package org.readium.r2.shared

import org.joda.time.DateTime
import org.json.JSONObject



/**
* Locator model
*
* @var bookId: Long? - Book index in the database
* @val publicationID: String - Publication identifier
* @val resourceIndex: Long - Index to the spine element of the book
* @val resourceHref: String - Reference to the spine element
* @val resourceTitle: String - Title to the spine element of the book
* @val location: Location - Location in the spine element
* @val creationDate: Long - Datetime when the bookmark has been created
* @var id: Long? - ID of the bookmark in database
*
* @fun toString(): String - Return a String description of the Locator
*/


open class Locator(val href:String,
val created:Long,
val title:String,
val locations:Locations,
val text:LocatorText?) {}

class LocatorText(var after:String? = null,
var before:String? = null,
var hightlight:String? = null)
: JSONable {

companion object {
fun fromJSON(json: JSONObject): LocatorText {

val location = LocatorText()
if (json.has("before")) {
location.before = json.getString("before")
}
if (json.has("hightlight")) {
location.hightlight = json.getString("hightlight")
}
if (json.has("after")) {
location.after = json.getString("after")
}

return location
}
}

override fun toJSON(): JSONObject {
val json = JSONObject()

before?.let {
json.putOpt("before", before)
}
hightlight?.let {
json.putOpt("hightlight", hightlight)
}
after?.let {
json.putOpt("after", after)
}

return json
}

override fun toString(): String {
var jsonString = """{"""

if (before != null) {
before.let { jsonString += """ "before": "$before" ,""" }
}
if (hightlight != null) {
hightlight.let { jsonString += """ "before": "$hightlight" ,""" }
}
if (after != null) {
after.let { jsonString += """ "after": "$after" ,""" }
}
jsonString += """}"""
return jsonString
}
}


/**
* Location : Class that contain the different variables needed to localize a particular position
*
* @var id: Long? - Identifier of a specific fragment in the publication
* @var cfi: String? - String formatted to designed a particular place in an Publication
* @var cssSelector: String? - Css selector
* @var xpath: String? - An xpath in the resource
* @var progression: Double - A percentage ( between 0 and 1 ) of the progression in a Publication
* @var position: Long - Index of a segment in the resource / synthetic page number!!??
*
*/
class Locations(var id: Long? = null,
var cfi: String? = null, // 1 = highlight, annotation etc = priority 3
var cssSelector: String? = null, // 2 =
var xpath: String? = null, // 2 =
var progression: Double? = null, // 3 = bookmark = priority 1 (done)
var position: Long? = null // 4 = got page = priority 2
) : JSONable {

companion object {
fun fromJSON(json: JSONObject): Locations {

val location = Locations()
if (json.has("id")) {
location.id = json.getLong("id")
}
if (json.has("cfi")) {
location.cfi = json.getString("cfi")
}
if (json.has("cssSelector")) {
location.cssSelector = json.getString("cssSelector")
}
if (json.has("xpath")) {
location.xpath = json.getString("xpath")
}
if (json.has("progression")) {
location.progression = json.getDouble("progression")
}
if (json.has("position")) {
location.position = json.getLong("position")
}

return location
}
}

override fun toJSON(): JSONObject {
val json = JSONObject()

id?.let {
json.putOpt("id", id)
}
cfi?.let {
json.putOpt("cfi", cfi)
}
cssSelector?.let {
json.putOpt("cssSelector", cssSelector)
}
xpath?.let {
json.putOpt("xpath", xpath)
}
progression?.let {
json.putOpt("progression", progression)
}
position?.let {
json.putOpt("position", position)
}

return json
}

override fun toString(): String {
var jsonString = """{"""
if (id != null) {
id.let { jsonString += """ "id": "$id" ,""" }
}
if (cfi != null) {
cfi.let { jsonString += """ "cfi": "$cfi" ,""" }
}
if (cssSelector != null) {
cssSelector.let { jsonString += """ "cssSelector": "$cssSelector" ,""" }
}
if (xpath != null) {
xpath.let { jsonString += """ "xpath": "$xpath" ,""" }
}
progression.let { jsonString += """ "progression": "$progression" ,""" }
position.let { jsonString += """ "position": "$position" """ }
jsonString += """}"""
return jsonString
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Properties : JSONable, Serializable {
///
var indirectAcquisition: MutableList<IndirectAcquisition> = mutableListOf()

override fun getJSON(): JSONObject {
override fun toJSON(): JSONObject {
val json = JSONObject()
if (contains.isNotEmpty()) json.put("contains", getStringArray(contains))
json.putOpt("mediaOverlay", mediaOverlay)
Expand Down
8 changes: 4 additions & 4 deletions r2-shared/src/main/java/org/readium/r2/shared/Publication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fun URL.removeLastComponent(): URL {
fun getJSONArray(list: List<JSONable>): JSONArray {
val array = JSONArray()
for (i in list) {
array.put(i.getJSON())
array.put(i.toJSON())
}
return array
}
Expand All @@ -46,15 +46,15 @@ fun tryPut(obj: JSONObject, list: List<JSONable>, tag: String) {

// Try to put class which implements JSONable only if not empty
fun tryPut(jsonObject: JSONObject, jsonable: JSONable, tag: String) {
val tempJsonObject = jsonable.getJSON()
val tempJsonObject = jsonable.toJSON()
if (tempJsonObject.length() != 0)
jsonObject.put(tag, tempJsonObject)
}

class TocElement(val link: Link, val children: List<TocElement>) : JSONable {

override fun getJSON(): JSONObject {
val json = link.getJSON()
override fun toJSON(): JSONObject {
val json = link.toJSON()
tryPut(json, children, "children")
return json
}
Expand Down
2 changes: 1 addition & 1 deletion r2-shared/src/main/java/org/readium/r2/shared/Subject.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Subject : JSONable, Serializable {
// Epub 3.1 "code" (opf:term)
var code: String? = null

override fun getJSON(): JSONObject {
override fun toJSON(): JSONObject {
val json = JSONObject()
json.putOpt("name", name)
json.putOpt("sortAs", sortAs)
Expand Down
36 changes: 36 additions & 0 deletions r2-shared/src/test/java/org/readium/r2/LocatorsUnitTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Module: r2-shared-kotlin
* Developers: Aferdita Muriqi, Mostapha Idoubihi, Paul Stoica
*
* Copyright (c) 2018. Readium Foundation. All rights reserved.
* Use of this source code is governed by a BSD-style license which is detailed in the
* LICENSE file present in the project repository where this source code is maintained.
*/

package org.readium.r2

import java.net.URI

/*
class LocatorsUnitTest {

lateinit var locatorList: MutableList<Locator>

init {
locatorList.add(Locator("FirstPublication", 1, null, URI("FirstPublication"), Location("FirstPublication", null, null, 0.0f, 0)))
locatorList.add(Locator("FirstPublication", 1, null, URI("FirstPublication"), Location("FirstPublication", null, null, 0.0f, 0)))
locatorList.add(Locator("SecondPublication", 2, null, URI("SecondPublication"), Location("SecondPublication", null, null, 0.23931f, 3)))
locatorList.add(Locator("SixthPublication", 6, null, URI("SixthPublication"), Location("SixthPublication", null, null, 0.5f, 6)))
locatorList.add(Locator("ThirteenthPublication", 13, null, URI("ThirteenthPublication"), Location("ThirteenthPublication", null, null, 0.1578f, 13)))
locatorList.add(Locator("IsThatEvenAPub?!", -2, null, URI("IsThatEvenAPub?!"), Location("IsThatEvenAPub?!", null, null, 0.9239f, -2)))
locatorList.add(Locator("ComeOn..", 8, null, URI("ComeOn.."), Location("ComeOn..", null, null, -0.323f, 8)))
}

fun addToList(newElem: Locator){
locatorList.add(newElem)
}

fun test(){

}
}*/