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

Commit

Permalink
Merge pull request #87 from readium/fixes/debug
Browse files Browse the repository at this point in the history
wrap timber logs to only show in debug builds and source formatting
  • Loading branch information
aferditamuriqi committed Dec 28, 2019
2 parents 8335631 + 606c207 commit e02fe3a
Show file tree
Hide file tree
Showing 17 changed files with 78 additions and 72 deletions.
3 changes: 2 additions & 1 deletion r2-streamer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies {
if (findProject(':r2-shared')) {
implementation project(':r2-shared')
} else {
implementation "com.github.readium:r2-shared-kotlin:1.1.4"
implementation "com.github.readium:r2-shared-kotlin:1.1.5"
}

//TODO conflicting support libraries, excluding these
Expand Down Expand Up @@ -70,6 +70,7 @@ dependencies {
implementation "com.fasterxml.jackson.core:jackson-core:$JACKSON_VERSION"
implementation "com.fasterxml.jackson.core:jackson-annotations:$JACKSON_VERSION"
implementation "com.fasterxml.jackson.core:jackson-databind:$JACKSON_VERSION"
//noinspection GradleDependency
implementation 'org.jsoup:jsoup:1.10.3'

testImplementation 'junit:junit:4.12'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface ContentFilters {
}
}

class ContentFiltersEpub(private val userPropertiesPath: String?, var customResources: Resources?) : ContentFilters {
class ContentFiltersEpub(private val userPropertiesPath: String?, private var customResources: Resources?) : ContentFilters {

override fun apply(input: InputStream, publication: Publication, container: Container, path: String): InputStream {
publication.linkWithHref(path)?.let { resourceLink ->
Expand Down Expand Up @@ -125,7 +125,7 @@ class ContentFiltersEpub(private val userPropertiesPath: String?, var customReso
html?.let {
val match = Regex("""(style=("([^"]*)"[ >]))|(style='([^']*)'[ >])""").find(html.value, 0)
if (match != null) {
val beginStyle = match.range.start + 7
val beginStyle = match.range.first + 7
var newHtml = html.value
newHtml = StringBuilder(newHtml).insert(beginStyle, "${buildStringProperties(propertyPair)} ").toString()
resourceHtml = StringBuilder(resourceHtml).replace(Regex("""<html.*>"""), newHtml)
Expand Down Expand Up @@ -319,5 +319,5 @@ class ContentFiltersEpub(private val userPropertiesPath: String?, var customReso
}


class ContentFiltersCbz : ContentFilters {}
class ContentFiltersCbz : ContentFilters

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package org.readium.r2.streamer.fetcher

import org.readium.r2.shared.Link
import org.readium.r2.shared.drm.DRM
import org.readium.r2.streamer.BuildConfig.DEBUG
import timber.log.Timber
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
Expand Down Expand Up @@ -48,13 +49,13 @@ class DrmDecoder {
val count = inflater.inflate(buf)
output.write(buf, 0, count)
} catch (e: Exception) {
Timber.e(e)
if (DEBUG) Timber.e(e)
}
}
try {
output.close()
} catch (e: Exception) {
Timber.e(e)
if (DEBUG) Timber.e(e)
}
data = output.toByteArray()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package org.readium.r2.streamer.fetcher
import com.mcxiaoke.koi.HASH
import com.mcxiaoke.koi.ext.toHexBytes
import org.readium.r2.shared.Publication
import org.readium.r2.streamer.BuildConfig.DEBUG
import timber.log.Timber
import java.io.ByteArrayInputStream
import java.io.InputStream
Expand Down Expand Up @@ -39,7 +40,7 @@ class FontDecoder {
val algorithm = encryption.algorithm ?: return input
val type = decoders[link.properties.encryption?.algorithm] ?: return input
if (!decodableAlgorithms.values.contains(algorithm)) {
Timber.e("Error $path is encrypted, but can't handle it")
if (DEBUG) Timber.e("Error $path is encrypted, but can't handle it")
return input
}
return decodingFont(input, publicationIdentifier, type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package org.readium.r2.streamer.parser.audio
import org.json.JSONObject
import org.readium.r2.shared.Publication
import org.readium.r2.shared.parsePublication
import org.readium.r2.streamer.BuildConfig.DEBUG
import org.readium.r2.streamer.container.ContainerError
import org.readium.r2.streamer.parser.PubBox
import org.readium.r2.streamer.parser.PublicationParser
Expand Down Expand Up @@ -60,13 +61,13 @@ class AudioBookParser : PublicationParser {
val container = try {
generateContainerFrom(fileAtPath)
} catch (e: Exception) {
Timber.e(e, "Could not generate container")
if (DEBUG) Timber.e(e, "Could not generate container")
return null
}
val data = try {
container.data(AudioBookConstant.manifestPath)
} catch (e: Exception) {
Timber.e(e, "Missing File : ${AudioBookConstant.manifestPath}")
if (DEBUG) Timber.e(e, "Missing File : ${AudioBookConstant.manifestPath}")
return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ package org.readium.r2.streamer.parser.audio
import org.readium.r2.streamer.container.Container
import org.readium.r2.streamer.container.DirectoryContainer

interface AudioBookContainer : Container {
interface AudioBookContainer : Container

}

class AudioBookDirectoryContainer(path: String) : AudioBookContainer, DirectoryContainer(path, AudioBookConstant.mimetype) {

}
class AudioBookDirectoryContainer(path: String) : AudioBookContainer, DirectoryContainer(path, AudioBookConstant.mimetype)
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import android.text.TextUtils
import android.webkit.MimeTypeMap
import org.readium.r2.shared.Link
import org.readium.r2.shared.Publication
import org.readium.r2.streamer.BuildConfig.DEBUG
import org.readium.r2.streamer.container.ContainerError
import org.readium.r2.streamer.parser.PubBox
import org.readium.r2.streamer.parser.PublicationParser
Expand Down Expand Up @@ -87,13 +88,13 @@ class CBZParser : PublicationParser {
val container = try {
generateContainerFrom(fileAtPath)
} catch (e: Exception) {
Timber.e(e, "Could not generate container")
if (DEBUG) Timber.e(e, "Could not generate container")
return null
}
val listFiles = try {
container.files
} catch (e: Exception) {
Timber.e(e, "Missing File : META-INF/container.xml")
if (DEBUG) Timber.e(e, "Missing File : META-INF/container.xml")
return null
}

Expand All @@ -118,7 +119,7 @@ class CBZParser : PublicationParser {
publication.images.first().rel.add("cover")

// Add href as title if title is missing (this is used to display the TOC)
for ((index, link) in publication.images.withIndex()) {
for (link in publication.images) {
if (link.title == null || link.title!!.isEmpty()) {
link.title = link.href
}
Expand All @@ -137,7 +138,7 @@ class CBZParser : PublicationParser {
val path = Paths.get(file)
path.fileName.toString()
} else {
val uri = Uri.parse(file);
val uri = Uri.parse(file)
uri.lastPathSegment
}
var type: String? = null
Expand All @@ -153,7 +154,7 @@ class CBZParser : PublicationParser {
}
type
} catch (e: Exception) {
Timber.e(e)
if (DEBUG) Timber.e(e)
null
}
}
Expand Down Expand Up @@ -188,7 +189,7 @@ class CBZParser : PublicationParser {
private fun convertHashToString(md5Bytes: ByteArray): String {
var returnVal = ""
for (i in md5Bytes.indices) {
returnVal += Integer.toString((md5Bytes[i] and 0xff.toByte()) + 0x100, 16).substring(1)
returnVal += ((md5Bytes[i] and 0xff.toByte()) + 0x100).toString(16).substring(1)
}
return returnVal
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ package org.readium.r2.streamer.parser.divina
import org.readium.r2.streamer.container.Container
import org.readium.r2.streamer.container.DirectoryContainer

interface DiViNaContainer: Container {
interface DiViNaContainer: Container

}


class ContainerDiViNa(path: String) : DiViNaContainer, DirectoryContainer(path, DiViNaConstant.mimetype) {

}
class ContainerDiViNa(path: String) : DiViNaContainer, DirectoryContainer(path, DiViNaConstant.mimetype)
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package org.readium.r2.streamer.parser.divina
import org.json.JSONObject
import org.readium.r2.shared.Publication
import org.readium.r2.shared.parsePublication
import org.readium.r2.streamer.BuildConfig.DEBUG
import org.readium.r2.streamer.container.ContainerError
import org.readium.r2.streamer.parser.PubBox
import org.readium.r2.streamer.parser.PublicationParser
Expand Down Expand Up @@ -60,25 +61,25 @@ class DiViNaParser : PublicationParser {
val container = try {
generateContainerFrom(fileAtPath)
} catch (e: Exception) {
Timber.e(e,"Could not generate container")
if (DEBUG) Timber.e(e,"Could not generate container")
return null
}

val data = try {
container.data(DiViNaConstant.manifestPath)
} catch (e: Exception) {
Timber.e(e, "Missing File : ${DiViNaConstant.manifestPath}")
if (DEBUG) Timber.e(e, "Missing File : ${DiViNaConstant.manifestPath}")
try {
val publication = container.data(DiViNaConstant.publicationPath)
container.rootFile
val inputStream = ByteArrayInputStream(publication)
inputStream.toFile("${container.rootFile.rootPath}/${DiViNaConstant.manifestPath}")
publication
} catch (e: FileNotFoundException) {
Timber.e(e, "Missing File : ${DiViNaConstant.publicationPath}")
if (DEBUG) Timber.e(e, "Missing File : ${DiViNaConstant.publicationPath}")
return null
} catch (e: Exception) {
Timber.e(e, "${container.rootFile.rootPath}/${DiViNaConstant.manifestPath}")
if (DEBUG) Timber.e(e, "${container.rootFile.rootPath}/${DiViNaConstant.manifestPath}")
return null
}
}
Expand All @@ -93,7 +94,7 @@ class DiViNaParser : PublicationParser {
publication.type = Publication.TYPE.DiViNa

// Add href as title if title is missing (this is used to display the TOC)
for ((index, link) in publication.readingOrder.withIndex()) {
for (link in publication.readingOrder) {
if (link.title == null || link.title!!.isEmpty()) {
link.title = link.href
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package org.readium.r2.streamer.parser.epub
import org.readium.r2.shared.*
import org.readium.r2.shared.drm.DRM
import org.readium.r2.shared.parser.xml.XmlParser
import org.readium.r2.streamer.BuildConfig.DEBUG
import org.readium.r2.streamer.container.ArchiveContainer
import org.readium.r2.streamer.container.Container
import org.readium.r2.streamer.container.ContainerError
Expand All @@ -29,27 +30,27 @@ class EPUBConstant {
const val mediaOverlayURL: String = "media-overlay?resource="
const val containerDotXmlPath = "META-INF/container.xml"
const val encryptionDotXmlPath = "META-INF/encryption.xml"
val ltrPreset: MutableMap<ReadiumCSSName, Boolean> = mutableMapOf(
private val ltrPreset: MutableMap<ReadiumCSSName, Boolean> = mutableMapOf(
ReadiumCSSName.ref("hyphens") to false,
ReadiumCSSName.ref("ligatures") to false
)

val rtlPreset: MutableMap<ReadiumCSSName, Boolean> = mutableMapOf(
private val rtlPreset: MutableMap<ReadiumCSSName, Boolean> = mutableMapOf(
ReadiumCSSName.ref("hyphens") to false,
ReadiumCSSName.ref("wordSpacing") to false,
ReadiumCSSName.ref("letterSpacing") to false,
ReadiumCSSName.ref("ligatures") to true
)

val cjkHorizontalPreset: MutableMap<ReadiumCSSName, Boolean> = mutableMapOf(
private val cjkHorizontalPreset: MutableMap<ReadiumCSSName, Boolean> = mutableMapOf(
ReadiumCSSName.ref("textAlignment") to false,
ReadiumCSSName.ref("hyphens") to false,
ReadiumCSSName.ref("paraIndent") to false,
ReadiumCSSName.ref("wordSpacing") to false,
ReadiumCSSName.ref("letterSpacing") to false
)

val cjkVerticalPreset: MutableMap<ReadiumCSSName, Boolean> = mutableMapOf(
private val cjkVerticalPreset: MutableMap<ReadiumCSSName, Boolean> = mutableMapOf(
ReadiumCSSName.ref("scroll") to true,
ReadiumCSSName.ref("columnCount") to false,
ReadiumCSSName.ref("textAlignment") to false,
Expand Down Expand Up @@ -112,13 +113,13 @@ class EpubParser : PublicationParser {
val container = try {
generateContainerFrom(fileAtPath)
} catch (e: Exception) {
Timber.e(e, "Could not generate container")
if (DEBUG) Timber.e(e, "Could not generate container")
return null
}
val data = try {
container.data(EPUBConstant.containerDotXmlPath)
} catch (e: Exception) {
Timber.e(e, "Missing File : ${EPUBConstant.containerDotXmlPath}")
if (DEBUG) Timber.e(e, "Missing File : ${EPUBConstant.containerDotXmlPath}")
return null
}

Expand All @@ -130,7 +131,7 @@ class EpubParser : PublicationParser {
val documentData = try {
container.data(container.rootFile.rootFilePath)
} catch (e: Exception) {
Timber.e(e, "Missing File : ${container.rootFile.rootFilePath}")
if (DEBUG) Timber.e(e, "Missing File : ${container.rootFile.rootFilePath}")
return null
}

Expand Down Expand Up @@ -258,14 +259,14 @@ class EpubParser : PublicationParser {
val navDocument = try {
xmlDocumentForResource(navLink, container)
} catch (e: Exception) {
Timber.e(e)
if (DEBUG) Timber.e(e)
return
}

val navByteArray = try {
xmlAsByteArray(navLink, container)
} catch (e: Exception) {
Timber.e(e)
if (DEBUG) Timber.e(e)
return
}

Expand All @@ -285,7 +286,7 @@ class EpubParser : PublicationParser {
val ncxDocument = try {
xmlDocumentForResource(ncxLink, container)
} catch (e: Exception) {
Timber.e(e)
if (DEBUG) Timber.e(e)
return
}
ncxp.ncxDocumentPath = ncxLink.href ?: return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@

package org.readium.r2.streamer.parser.epub

import android.annotation.SuppressLint
import org.joda.time.DateTime
import org.readium.r2.shared.Link
import org.readium.r2.shared.Metadata
import org.readium.r2.shared.Properties
import org.readium.r2.shared.Publication
import org.readium.r2.shared.parser.xml.Node
import org.readium.r2.shared.parser.xml.XmlParser
import org.readium.r2.streamer.BuildConfig.DEBUG
import org.readium.r2.streamer.parser.normalize
import timber.log.Timber

Expand Down Expand Up @@ -99,10 +101,11 @@ class OPFParser {
coverLink?.rel?.add("cover")
}

@SuppressLint("DefaultLocale")
private fun parseSpine(spine: Node, publication: Publication) {
val spineItems = spine.get("itemref")!!
if (spineItems.isEmpty()) {
Timber.tag("Warning").d("Spine has no children elements")
if (DEBUG) Timber.tag("Warning").d("Spine has no children elements")
return
}
for (item in spineItems) {
Expand Down
Loading

0 comments on commit e02fe3a

Please sign in to comment.