From 8f62c1ab5e33e727c236bef167eaee9803b1895c Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 30 Mar 2023 08:40:58 +0800 Subject: [PATCH] =?UTF-8?q?lollipop=E7=89=88=E6=9C=AC=E5=88=86=E5=BC=80,?= =?UTF-8?q?=E6=9C=89=E4=BA=9B=E6=96=B0=E7=89=B9=E6=80=A7android5.0?= =?UTF-8?q?=E5=92=8C6.0=E4=B8=8D=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 13 +- .../main/java/me/ag2s/epublib/Constants.java | 13 - .../browsersupport/NavigationEvent.java | 158 --- .../browsersupport/NavigationHistory.java | 207 --- .../epublib/browsersupport/Navigator.java | 220 --- .../epublib/domain/EpubResourceProvider.java | 37 - .../java/me/ag2s/epublib/domain/Guide.java | 128 -- .../ag2s/epublib/domain/GuideReference.java | 103 -- .../me/ag2s/epublib/domain/Identifier.java | 131 -- .../me/ag2s/epublib/domain/LazyResource.java | 144 -- .../domain/ManifestItemProperties.java | 21 - .../domain/ManifestItemRefProperties.java | 16 - .../me/ag2s/epublib/domain/MediaType.java | 73 - .../me/ag2s/epublib/domain/MediaTypes.java | 95 -- .../java/me/ag2s/epublib/domain/Relator.java | 1144 ---------------- .../java/me/ag2s/epublib/domain/Resource.java | 340 ----- .../epublib/domain/ResourceReference.java | 43 - .../java/me/ag2s/epublib/domain/Spine.java | 192 --- .../me/ag2s/epublib/domain/TOCReference.java | 56 - .../epublib/epub/BookProcessorPipeline.java | 73 - .../java/me/ag2s/epublib/epub/EpubWriter.java | 190 --- .../epublib/epub/PackageDocumentBase.java | 97 -- .../epub/PackageDocumentMetadataWriter.java | 187 --- .../me/ag2s/epublib/util/CollectionUtil.java | 71 - .../epublib/util/zip/AndroidZipEntry.java | 363 ----- .../ag2s/epublib/util/zip/ZipConstants.java | 61 - .../me/ag2s/umdlib/domain/UmdChapters.java | 207 --- .../java/me/ag2s/umdlib/domain/UmdHeader.java | 165 --- .../java/me/ag2s/umdlib/tool/UmdUtils.java | 153 --- .../me/ag2s/umdlib/tool/WrapOutputStream.java | 91 -- .../openebook.org/dtds/oeb-1.2/oebpkg12.dtd | 390 ------ .../www.daisy.org/z3986/2005/ncx-2005-1.dtd | 269 ---- .../dtd/www.w3.org/TR/ruby/xhtml-ruby-1.mod | 242 ---- .../xhtml-modularization/DTD/xhtml-arch-1.mod | 51 - .../DTD/xhtml-attribs-1.mod | 142 -- .../xhtml-modularization/DTD/xhtml-base-1.mod | 53 - .../xhtml-modularization/DTD/xhtml-bdo-1.mod | 47 - .../DTD/xhtml-blkphras-1.mod | 164 --- .../DTD/xhtml-blkpres-1.mod | 40 - .../DTD/xhtml-blkstruct-1.mod | 57 - .../DTD/xhtml-charent-1.mod | 39 - .../DTD/xhtml-csismap-1.mod | 114 -- .../DTD/xhtml-datatypes-1.mod | 103 -- .../xhtml-modularization/DTD/xhtml-edit-1.mod | 66 - .../DTD/xhtml-events-1.mod | 135 -- .../xhtml-modularization/DTD/xhtml-form-1.mod | 292 ---- .../DTD/xhtml-framework-1.mod | 97 -- .../DTD/xhtml-hypertext-1.mod | 54 - .../DTD/xhtml-image-1.mod | 51 - .../DTD/xhtml-inlphras-1.mod | 203 --- .../DTD/xhtml-inlpres-1.mod | 138 -- .../DTD/xhtml-inlstruct-1.mod | 62 - .../DTD/xhtml-inlstyle-1.mod | 34 - .../xhtml-modularization/DTD/xhtml-lat1.ent | 196 --- .../xhtml-modularization/DTD/xhtml-link-1.mod | 59 - .../xhtml-modularization/DTD/xhtml-list-1.mod | 129 -- .../xhtml-modularization/DTD/xhtml-meta-1.mod | 47 - .../DTD/xhtml-notations-1.mod | 114 -- .../DTD/xhtml-object-1.mod | 60 - .../DTD/xhtml-param-1.mod | 48 - .../xhtml-modularization/DTD/xhtml-pres-1.mod | 38 - .../DTD/xhtml-qname-1.mod | 318 ----- .../DTD/xhtml-script-1.mod | 67 - .../DTD/xhtml-special.ent | 80 -- .../DTD/xhtml-ssismap-1.mod | 32 - .../DTD/xhtml-struct-1.mod | 136 -- .../DTD/xhtml-style-1.mod | 48 - .../xhtml-modularization/DTD/xhtml-symbol.ent | 237 ---- .../DTD/xhtml-table-1.mod | 333 ----- .../xhtml-modularization/DTD/xhtml-text-1.mod | 52 - .../DTD/xhtml11-model-1.mod | 252 ---- .../www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent | 196 --- .../TR/xhtml1/DTD/xhtml-special.ent | 80 -- .../www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent | 237 ---- .../TR/xhtml1/DTD/xhtml1-strict.dtd | 978 -------------- .../TR/xhtml1/DTD/xhtml1-transitional.dtd | 1201 ----------------- .../dtd/www.w3.org/TR/xhtml11/DTD/xhtml11.dtd | 294 ---- {book => modules/book}/.gitignore | 0 {book => modules/book}/build.gradle | 7 - {book => modules/book}/consumer-rules.pro | 0 .../book}/src/main/AndroidManifest.xml | 0 .../src/main/java/me/ag2s/base/PfdHelper.java | 0 .../java/me/ag2s/base/ThrowableUtils.java | 3 +- .../main/java/me/ag2s/epublib/Constants.java | 13 + .../browsersupport/NavigationEvent.java | 157 +++ .../NavigationEventListener.java | 13 +- .../browsersupport/NavigationHistory.java | 207 +++ .../epublib/browsersupport/Navigator.java | 219 +++ .../epublib/browsersupport/package-info.java | 2 +- .../java/me/ag2s/epublib/domain/Author.java | 0 .../java/me/ag2s/epublib/domain/Date.java | 0 .../java/me/ag2s/epublib/domain/EpubBook.java | 0 .../epublib/domain/EpubResourceProvider.java | 37 + .../epublib/domain/FileResourceProvider.java | 4 +- .../java/me/ag2s/epublib/domain/Guide.java | 128 ++ .../ag2s/epublib/domain/GuideReference.java | 100 ++ .../me/ag2s/epublib/domain/Identifier.java | 133 ++ .../me/ag2s/epublib/domain/LazyResource.java | 145 ++ .../epublib/domain/LazyResourceProvider.java | 2 +- .../domain/ManifestItemProperties.java | 22 + .../domain/ManifestItemRefProperties.java | 17 + .../epublib/domain/ManifestProperties.java | 2 +- .../me/ag2s/epublib/domain/MediaType.java | 73 + .../me/ag2s/epublib/domain/MediaTypes.java | 95 ++ .../java/me/ag2s/epublib/domain/Metadata.java | 0 .../java/me/ag2s/epublib/domain/Relator.java | 1143 ++++++++++++++++ .../java/me/ag2s/epublib/domain/Resource.java | 336 +++++ .../epublib/domain/ResourceInputStream.java | 10 +- .../epublib/domain/ResourceReference.java | 43 + .../me/ag2s/epublib/domain/Resources.java | 1 + .../java/me/ag2s/epublib/domain/Spine.java | 190 +++ .../ag2s/epublib/domain/SpineReference.java | 0 .../me/ag2s/epublib/domain/TOCReference.java | 57 + .../ag2s/epublib/domain/TableOfContents.java | 0 .../domain/TitledResourceReference.java | 2 +- .../me/ag2s/epublib/epub/BookProcessor.java | 10 +- .../epublib/epub/BookProcessorPipeline.java | 73 + .../java/me/ag2s/epublib/epub/DOMUtil.java | 1 + .../epublib/epub/EpubProcessorSupport.java | 0 .../java/me/ag2s/epublib/epub/EpubReader.java | 0 .../java/me/ag2s/epublib/epub/EpubWriter.java | 190 +++ .../me/ag2s/epublib/epub/HtmlProcessor.java | 3 +- .../me/ag2s/epublib/epub/NCXDocumentV2.java | 1 + .../me/ag2s/epublib/epub/NCXDocumentV3.java | 8 +- .../epublib/epub/PackageDocumentBase.java | 96 ++ .../epub/PackageDocumentMetadataReader.java | 0 .../epub/PackageDocumentMetadataWriter.java | 187 +++ .../epublib/epub/PackageDocumentReader.java | 25 +- .../epublib/epub/PackageDocumentWriter.java | 0 .../me/ag2s/epublib/epub/ResourcesLoader.java | 0 .../me/ag2s/epublib/util/CollectionUtil.java | 72 + .../java/me/ag2s/epublib/util/IOUtil.java | 2 +- .../epublib/util/NoCloseOutputStream.java | 26 +- .../me/ag2s/epublib/util/NoCloseWriter.java | 30 +- .../me/ag2s/epublib/util/ResourceUtil.java | 0 .../java/me/ag2s/epublib/util/StringUtil.java | 0 .../util/commons/io/BOMInputStream.java | 90 +- .../util/commons/io/ByteOrderMark.java | 29 +- .../epublib/util/commons/io/IOConsumer.java | 2 +- .../util/commons/io/ProxyInputStream.java | 0 .../util/commons/io/XmlStreamReader.java | 108 +- .../commons/io/XmlStreamReaderException.java | 22 +- .../epublib/util/zip/AndroidZipEntry.java | 363 +++++ .../ag2s/epublib/util/zip/AndroidZipFile.java | 4 +- .../ag2s/epublib/util/zip/ZipConstants.java | 61 + .../epublib/util/zip/ZipEntryWrapper.java | 0 .../ag2s/epublib/util/zip/ZipException.java | 0 .../ag2s/epublib/util/zip/ZipFileWrapper.java | 0 .../java/me/ag2s/umdlib/domain/UmdBook.java | 17 +- .../me/ag2s/umdlib/domain/UmdChapters.java | 212 +++ .../java/me/ag2s/umdlib/domain/UmdCover.java | 81 +- .../java/me/ag2s/umdlib/domain/UmdEnd.java | 12 +- .../java/me/ag2s/umdlib/domain/UmdHeader.java | 164 +++ .../me/ag2s/umdlib/tool/StreamReader.java | 41 +- .../java/me/ag2s/umdlib/tool/UmdUtils.java | 155 +++ .../me/ag2s/umdlib/tool/WrapOutputStream.java | 91 ++ .../java/me/ag2s/umdlib/umd/UmdReader.java | 7 +- .../dtd/openebook.org/dtds/oeb-1.2/oeb12.ent | 722 +++++----- .../openebook.org/dtds/oeb-1.2/oebpkg12.dtd | 277 ++++ .../www.daisy.org/z3986/2005/ncx-2005-1.dtd | 187 +++ .../dtd/www.w3.org/TR/ruby/xhtml-ruby-1.mod | 142 ++ .../xhtml-modularization/DTD/xhtml-arch-1.mod | 36 + .../DTD/xhtml-attribs-1.mod | 96 ++ .../xhtml-modularization/DTD/xhtml-base-1.mod | 40 + .../xhtml-modularization/DTD/xhtml-bdo-1.mod | 33 + .../DTD/xhtml-blkphras-1.mod | 74 + .../DTD/xhtml-blkpres-1.mod | 30 + .../DTD/xhtml-blkstruct-1.mod | 34 + .../DTD/xhtml-charent-1.mod | 30 + .../DTD/xhtml-csismap-1.mod | 69 + .../DTD/xhtml-datatypes-1.mod | 97 ++ .../DTD/xhtml-datatypes-1.mod.1 | 0 .../xhtml-modularization/DTD/xhtml-edit-1.mod | 38 + .../DTD/xhtml-events-1.mod | 97 ++ .../xhtml-modularization/DTD/xhtml-form-1.mod | 130 ++ .../DTD/xhtml-framework-1.mod | 58 + .../DTD/xhtml-hypertext-1.mod | 34 + .../DTD/xhtml-image-1.mod | 35 + .../DTD/xhtml-inlphras-1.mod | 70 + .../DTD/xhtml-inlpres-1.mod | 54 + .../DTD/xhtml-inlstruct-1.mod | 42 + .../DTD/xhtml-inlstyle-1.mod | 30 + .../xhtml-modularization/DTD/xhtml-lat1.ent | 196 +++ .../xhtml-modularization/DTD/xhtml-link-1.mod | 42 + .../xhtml-modularization/DTD/xhtml-list-1.mod | 64 + .../xhtml-modularization/DTD/xhtml-meta-1.mod | 32 + .../DTD/xhtml-notations-1.mod | 94 ++ .../DTD/xhtml-object-1.mod | 36 + .../DTD/xhtml-param-1.mod | 33 + .../xhtml-modularization/DTD/xhtml-pres-1.mod | 28 + .../DTD/xhtml-qname-1.mod | 224 +++ .../DTD/xhtml-script-1.mod | 39 + .../DTD/xhtml-special.ent | 80 ++ .../DTD/xhtml-ssismap-1.mod | 28 + .../DTD/xhtml-struct-1.mod | 75 + .../DTD/xhtml-style-1.mod | 32 + .../xhtml-modularization/DTD/xhtml-symbol.ent | 237 ++++ .../DTD/xhtml-symbol.ent.1 | 0 .../DTD/xhtml-table-1.mod | 177 +++ .../xhtml-modularization/DTD/xhtml-text-1.mod | 32 + .../DTD/xhtml11-model-1.mod | 222 +++ .../www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent | 196 +++ .../TR/xhtml1/DTD/xhtml-special.ent | 80 ++ .../www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent | 237 ++++ .../TR/xhtml1/DTD/xhtml1-strict.dtd | 580 ++++++++ .../TR/xhtml1/DTD/xhtml1-transitional.dtd | 685 ++++++++++ .../dtd/www.w3.org/TR/xhtml11/DTD/xhtml11.dtd | 167 +++ .../book}/src/main/resources/log4j.properties | 31 +- {rhino => modules/rhino1.3}/.gitignore | 0 modules/rhino1.3/build.gradle | 31 + .../rhino1.3/consumer-rules.pro | 0 .../rhino1.3}/lib/rhino-1.7.13-2.jar | Bin .../rhino1.3}/src/main/AndroidManifest.xml | 0 .../java/com/script/AbstractScriptEngine.kt | 0 .../src/main/java/com/script/Bindings.kt | 0 .../src/main/java/com/script/Compilable.kt | 0 .../main/java/com/script/CompiledScript.kt | 0 .../src/main/java/com/script/Invocable.kt | 0 .../src/main/java/com/script/ScriptContext.kt | 0 .../src/main/java/com/script/ScriptEngine.kt | 0 .../main/java/com/script/ScriptException.kt | 0 .../main/java/com/script/SimpleBindings.kt | 0 .../java/com/script/SimpleScriptContext.kt | 0 .../com/script/rhino/ExternalScriptable.kt | 0 .../com/script/rhino/InterfaceImplementor.kt | 0 .../main/java/com/script/rhino/JSAdapter.kt | 0 .../main/java/com/script/rhino/JavaAdapter.kt | 0 .../com/script/rhino/RhinoClassShutter.kt | 0 .../com/script/rhino/RhinoCompiledScript.kt | 0 .../com/script/rhino/RhinoScriptEngine.kt | 315 +++++ .../java/com/script/rhino/RhinoTopLevel.kt | 0 .../java/com/script/rhino/RhinoWrapFactory.kt | 0 modules/rhino1.4/.gitignore | 1 + {rhino => modules/rhino1.4}/build.gradle | 7 - .../rhino1.4/consumer-rules.pro | 10 +- .../rhino1.4}/lib/rhino-1.7.14-2.jar | Bin modules/rhino1.4/src/main/AndroidManifest.xml | 4 + .../java/com/script/AbstractScriptEngine.kt | 98 ++ .../src/main/java/com/script/Bindings.kt | 18 + .../src/main/java/com/script/Compilable.kt | 15 + .../main/java/com/script/CompiledScript.kt | 32 + .../src/main/java/com/script/Invocable.kt | 16 + .../src/main/java/com/script/ScriptContext.kt | 37 + .../src/main/java/com/script/ScriptEngine.kt | 53 + .../main/java/com/script/ScriptException.kt | 54 + .../main/java/com/script/SimpleBindings.kt | 54 + .../java/com/script/SimpleScriptContext.kt | 113 ++ .../com/script/rhino/ExternalScriptable.kt | 305 +++++ .../com/script/rhino/InterfaceImplementor.kt | 95 ++ .../main/java/com/script/rhino/JSAdapter.kt | 307 +++++ .../main/java/com/script/rhino/JavaAdapter.kt | 104 ++ .../com/script/rhino/RhinoClassShutter.kt | 62 + .../com/script/rhino/RhinoCompiledScript.kt | 72 + .../com/script/rhino/RhinoScriptEngine.kt | 0 .../java/com/script/rhino/RhinoTopLevel.kt | 107 ++ .../java/com/script/rhino/RhinoWrapFactory.kt | 118 ++ rhino/consumer-rules.pro | 0 settings.gradle | 5 +- 258 files changed, 12817 insertions(+), 13529 deletions(-) delete mode 100644 book/src/main/java/me/ag2s/epublib/Constants.java delete mode 100644 book/src/main/java/me/ag2s/epublib/browsersupport/NavigationEvent.java delete mode 100644 book/src/main/java/me/ag2s/epublib/browsersupport/NavigationHistory.java delete mode 100644 book/src/main/java/me/ag2s/epublib/browsersupport/Navigator.java delete mode 100644 book/src/main/java/me/ag2s/epublib/domain/EpubResourceProvider.java delete mode 100644 book/src/main/java/me/ag2s/epublib/domain/Guide.java delete mode 100644 book/src/main/java/me/ag2s/epublib/domain/GuideReference.java delete mode 100644 book/src/main/java/me/ag2s/epublib/domain/Identifier.java delete mode 100644 book/src/main/java/me/ag2s/epublib/domain/LazyResource.java delete mode 100644 book/src/main/java/me/ag2s/epublib/domain/ManifestItemProperties.java delete mode 100644 book/src/main/java/me/ag2s/epublib/domain/ManifestItemRefProperties.java delete mode 100644 book/src/main/java/me/ag2s/epublib/domain/MediaType.java delete mode 100644 book/src/main/java/me/ag2s/epublib/domain/MediaTypes.java delete mode 100644 book/src/main/java/me/ag2s/epublib/domain/Relator.java delete mode 100644 book/src/main/java/me/ag2s/epublib/domain/Resource.java delete mode 100644 book/src/main/java/me/ag2s/epublib/domain/ResourceReference.java delete mode 100644 book/src/main/java/me/ag2s/epublib/domain/Spine.java delete mode 100644 book/src/main/java/me/ag2s/epublib/domain/TOCReference.java delete mode 100644 book/src/main/java/me/ag2s/epublib/epub/BookProcessorPipeline.java delete mode 100644 book/src/main/java/me/ag2s/epublib/epub/EpubWriter.java delete mode 100644 book/src/main/java/me/ag2s/epublib/epub/PackageDocumentBase.java delete mode 100644 book/src/main/java/me/ag2s/epublib/epub/PackageDocumentMetadataWriter.java delete mode 100644 book/src/main/java/me/ag2s/epublib/util/CollectionUtil.java delete mode 100644 book/src/main/java/me/ag2s/epublib/util/zip/AndroidZipEntry.java delete mode 100644 book/src/main/java/me/ag2s/epublib/util/zip/ZipConstants.java delete mode 100644 book/src/main/java/me/ag2s/umdlib/domain/UmdChapters.java delete mode 100644 book/src/main/java/me/ag2s/umdlib/domain/UmdHeader.java delete mode 100644 book/src/main/java/me/ag2s/umdlib/tool/UmdUtils.java delete mode 100644 book/src/main/java/me/ag2s/umdlib/tool/WrapOutputStream.java delete mode 100644 book/src/main/resources/dtd/openebook.org/dtds/oeb-1.2/oebpkg12.dtd delete mode 100644 book/src/main/resources/dtd/www.daisy.org/z3986/2005/ncx-2005-1.dtd delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/ruby/xhtml-ruby-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-arch-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-attribs-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-base-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-bdo-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-blkphras-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-blkpres-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-blkstruct-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-charent-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-csismap-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-datatypes-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-edit-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-events-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-form-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-framework-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-hypertext-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-image-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlphras-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlpres-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlstruct-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlstyle-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-lat1.ent delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-link-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-list-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-meta-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-notations-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-object-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-param-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-pres-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-qname-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-script-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-special.ent delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-ssismap-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-struct-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-style-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-symbol.ent delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-table-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-text-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml11-model-1.mod delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml1/DTD/xhtml-special.ent delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd delete mode 100644 book/src/main/resources/dtd/www.w3.org/TR/xhtml11/DTD/xhtml11.dtd rename {book => modules/book}/.gitignore (100%) rename {book => modules/book}/build.gradle (78%) rename {book => modules/book}/consumer-rules.pro (100%) rename {book => modules/book}/src/main/AndroidManifest.xml (100%) rename {book => modules/book}/src/main/java/me/ag2s/base/PfdHelper.java (100%) rename {book => modules/book}/src/main/java/me/ag2s/base/ThrowableUtils.java (85%) create mode 100644 modules/book/src/main/java/me/ag2s/epublib/Constants.java create mode 100644 modules/book/src/main/java/me/ag2s/epublib/browsersupport/NavigationEvent.java rename {book => modules/book}/src/main/java/me/ag2s/epublib/browsersupport/NavigationEventListener.java (53%) create mode 100644 modules/book/src/main/java/me/ag2s/epublib/browsersupport/NavigationHistory.java create mode 100644 modules/book/src/main/java/me/ag2s/epublib/browsersupport/Navigator.java rename {book => modules/book}/src/main/java/me/ag2s/epublib/browsersupport/package-info.java (97%) rename {book => modules/book}/src/main/java/me/ag2s/epublib/domain/Author.java (100%) rename {book => modules/book}/src/main/java/me/ag2s/epublib/domain/Date.java (100%) rename {book => modules/book}/src/main/java/me/ag2s/epublib/domain/EpubBook.java (100%) create mode 100644 modules/book/src/main/java/me/ag2s/epublib/domain/EpubResourceProvider.java rename {book => modules/book}/src/main/java/me/ag2s/epublib/domain/FileResourceProvider.java (98%) create mode 100644 modules/book/src/main/java/me/ag2s/epublib/domain/Guide.java create mode 100644 modules/book/src/main/java/me/ag2s/epublib/domain/GuideReference.java create mode 100644 modules/book/src/main/java/me/ag2s/epublib/domain/Identifier.java create mode 100644 modules/book/src/main/java/me/ag2s/epublib/domain/LazyResource.java rename {book => modules/book}/src/main/java/me/ag2s/epublib/domain/LazyResourceProvider.java (70%) create mode 100644 modules/book/src/main/java/me/ag2s/epublib/domain/ManifestItemProperties.java create mode 100644 modules/book/src/main/java/me/ag2s/epublib/domain/ManifestItemRefProperties.java rename {book => modules/book}/src/main/java/me/ag2s/epublib/domain/ManifestProperties.java (77%) create mode 100644 modules/book/src/main/java/me/ag2s/epublib/domain/MediaType.java create mode 100644 modules/book/src/main/java/me/ag2s/epublib/domain/MediaTypes.java rename {book => modules/book}/src/main/java/me/ag2s/epublib/domain/Metadata.java (100%) create mode 100644 modules/book/src/main/java/me/ag2s/epublib/domain/Relator.java create mode 100644 modules/book/src/main/java/me/ag2s/epublib/domain/Resource.java rename {book => modules/book}/src/main/java/me/ag2s/epublib/domain/ResourceInputStream.java (82%) create mode 100644 modules/book/src/main/java/me/ag2s/epublib/domain/ResourceReference.java rename {book => modules/book}/src/main/java/me/ag2s/epublib/domain/Resources.java (99%) create mode 100644 modules/book/src/main/java/me/ag2s/epublib/domain/Spine.java rename {book => modules/book}/src/main/java/me/ag2s/epublib/domain/SpineReference.java (100%) create mode 100644 modules/book/src/main/java/me/ag2s/epublib/domain/TOCReference.java rename {book => modules/book}/src/main/java/me/ag2s/epublib/domain/TableOfContents.java (100%) rename {book => modules/book}/src/main/java/me/ag2s/epublib/domain/TitledResourceReference.java (97%) rename {book => modules/book}/src/main/java/me/ag2s/epublib/epub/BookProcessor.java (65%) create mode 100644 modules/book/src/main/java/me/ag2s/epublib/epub/BookProcessorPipeline.java rename {book => modules/book}/src/main/java/me/ag2s/epublib/epub/DOMUtil.java (99%) rename {book => modules/book}/src/main/java/me/ag2s/epublib/epub/EpubProcessorSupport.java (100%) rename {book => modules/book}/src/main/java/me/ag2s/epublib/epub/EpubReader.java (100%) create mode 100644 modules/book/src/main/java/me/ag2s/epublib/epub/EpubWriter.java rename {book => modules/book}/src/main/java/me/ag2s/epublib/epub/HtmlProcessor.java (71%) rename {book => modules/book}/src/main/java/me/ag2s/epublib/epub/NCXDocumentV2.java (99%) rename {book => modules/book}/src/main/java/me/ag2s/epublib/epub/NCXDocumentV3.java (98%) create mode 100644 modules/book/src/main/java/me/ag2s/epublib/epub/PackageDocumentBase.java rename {book => modules/book}/src/main/java/me/ag2s/epublib/epub/PackageDocumentMetadataReader.java (100%) create mode 100644 modules/book/src/main/java/me/ag2s/epublib/epub/PackageDocumentMetadataWriter.java rename {book => modules/book}/src/main/java/me/ag2s/epublib/epub/PackageDocumentReader.java (97%) rename {book => modules/book}/src/main/java/me/ag2s/epublib/epub/PackageDocumentWriter.java (100%) rename {book => modules/book}/src/main/java/me/ag2s/epublib/epub/ResourcesLoader.java (100%) create mode 100644 modules/book/src/main/java/me/ag2s/epublib/util/CollectionUtil.java rename {book => modules/book}/src/main/java/me/ag2s/epublib/util/IOUtil.java (99%) rename {book => modules/book}/src/main/java/me/ag2s/epublib/util/NoCloseOutputStream.java (56%) rename {book => modules/book}/src/main/java/me/ag2s/epublib/util/NoCloseWriter.java (53%) rename {book => modules/book}/src/main/java/me/ag2s/epublib/util/ResourceUtil.java (100%) rename {book => modules/book}/src/main/java/me/ag2s/epublib/util/StringUtil.java (100%) rename {book => modules/book}/src/main/java/me/ag2s/epublib/util/commons/io/BOMInputStream.java (84%) rename {book => modules/book}/src/main/java/me/ag2s/epublib/util/commons/io/ByteOrderMark.java (91%) rename {book => modules/book}/src/main/java/me/ag2s/epublib/util/commons/io/IOConsumer.java (98%) rename {book => modules/book}/src/main/java/me/ag2s/epublib/util/commons/io/ProxyInputStream.java (100%) rename {book => modules/book}/src/main/java/me/ag2s/epublib/util/commons/io/XmlStreamReader.java (90%) rename {book => modules/book}/src/main/java/me/ag2s/epublib/util/commons/io/XmlStreamReaderException.java (87%) create mode 100644 modules/book/src/main/java/me/ag2s/epublib/util/zip/AndroidZipEntry.java rename {book => modules/book}/src/main/java/me/ag2s/epublib/util/zip/AndroidZipFile.java (99%) create mode 100644 modules/book/src/main/java/me/ag2s/epublib/util/zip/ZipConstants.java rename {book => modules/book}/src/main/java/me/ag2s/epublib/util/zip/ZipEntryWrapper.java (100%) rename {book => modules/book}/src/main/java/me/ag2s/epublib/util/zip/ZipException.java (100%) rename {book => modules/book}/src/main/java/me/ag2s/epublib/util/zip/ZipFileWrapper.java (100%) rename {book => modules/book}/src/main/java/me/ag2s/umdlib/domain/UmdBook.java (86%) create mode 100644 modules/book/src/main/java/me/ag2s/umdlib/domain/UmdChapters.java rename {book => modules/book}/src/main/java/me/ag2s/umdlib/domain/UmdCover.java (58%) rename {book => modules/book}/src/main/java/me/ag2s/umdlib/domain/UmdEnd.java (58%) create mode 100644 modules/book/src/main/java/me/ag2s/umdlib/domain/UmdHeader.java rename {book => modules/book}/src/main/java/me/ag2s/umdlib/tool/StreamReader.java (78%) create mode 100644 modules/book/src/main/java/me/ag2s/umdlib/tool/UmdUtils.java create mode 100644 modules/book/src/main/java/me/ag2s/umdlib/tool/WrapOutputStream.java rename {book => modules/book}/src/main/java/me/ag2s/umdlib/umd/UmdReader.java (98%) rename {book => modules/book}/src/main/resources/dtd/openebook.org/dtds/oeb-1.2/oeb12.ent (57%) create mode 100644 modules/book/src/main/resources/dtd/openebook.org/dtds/oeb-1.2/oebpkg12.dtd create mode 100644 modules/book/src/main/resources/dtd/www.daisy.org/z3986/2005/ncx-2005-1.dtd create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/ruby/xhtml-ruby-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-arch-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-attribs-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-base-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-bdo-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-blkphras-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-blkpres-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-blkstruct-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-charent-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-csismap-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-datatypes-1.mod rename {book => modules/book}/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-datatypes-1.mod.1 (100%) create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-edit-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-events-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-form-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-framework-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-hypertext-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-image-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlphras-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlpres-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlstruct-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlstyle-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-lat1.ent create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-link-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-list-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-meta-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-notations-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-object-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-param-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-pres-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-qname-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-script-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-special.ent create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-ssismap-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-struct-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-style-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-symbol.ent rename {book => modules/book}/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-symbol.ent.1 (100%) create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-table-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-text-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml11-model-1.mod create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml1/DTD/xhtml-special.ent create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd create mode 100644 modules/book/src/main/resources/dtd/www.w3.org/TR/xhtml11/DTD/xhtml11.dtd rename {book => modules/book}/src/main/resources/log4j.properties (69%) rename {rhino => modules/rhino1.3}/.gitignore (100%) create mode 100644 modules/rhino1.3/build.gradle rename rhino/proguard-rules.pro => modules/rhino1.3/consumer-rules.pro (100%) rename {rhino => modules/rhino1.3}/lib/rhino-1.7.13-2.jar (100%) rename {rhino => modules/rhino1.3}/src/main/AndroidManifest.xml (100%) rename {rhino => modules/rhino1.3}/src/main/java/com/script/AbstractScriptEngine.kt (100%) rename {rhino => modules/rhino1.3}/src/main/java/com/script/Bindings.kt (100%) rename {rhino => modules/rhino1.3}/src/main/java/com/script/Compilable.kt (100%) rename {rhino => modules/rhino1.3}/src/main/java/com/script/CompiledScript.kt (100%) rename {rhino => modules/rhino1.3}/src/main/java/com/script/Invocable.kt (100%) rename {rhino => modules/rhino1.3}/src/main/java/com/script/ScriptContext.kt (100%) rename {rhino => modules/rhino1.3}/src/main/java/com/script/ScriptEngine.kt (100%) rename {rhino => modules/rhino1.3}/src/main/java/com/script/ScriptException.kt (100%) rename {rhino => modules/rhino1.3}/src/main/java/com/script/SimpleBindings.kt (100%) rename {rhino => modules/rhino1.3}/src/main/java/com/script/SimpleScriptContext.kt (100%) rename {rhino => modules/rhino1.3}/src/main/java/com/script/rhino/ExternalScriptable.kt (100%) rename {rhino => modules/rhino1.3}/src/main/java/com/script/rhino/InterfaceImplementor.kt (100%) rename {rhino => modules/rhino1.3}/src/main/java/com/script/rhino/JSAdapter.kt (100%) rename {rhino => modules/rhino1.3}/src/main/java/com/script/rhino/JavaAdapter.kt (100%) rename {rhino => modules/rhino1.3}/src/main/java/com/script/rhino/RhinoClassShutter.kt (100%) rename {rhino => modules/rhino1.3}/src/main/java/com/script/rhino/RhinoCompiledScript.kt (100%) create mode 100644 modules/rhino1.3/src/main/java/com/script/rhino/RhinoScriptEngine.kt rename {rhino => modules/rhino1.3}/src/main/java/com/script/rhino/RhinoTopLevel.kt (100%) rename {rhino => modules/rhino1.3}/src/main/java/com/script/rhino/RhinoWrapFactory.kt (100%) create mode 100644 modules/rhino1.4/.gitignore rename {rhino => modules/rhino1.4}/build.gradle (78%) rename book/proguard-rules.pro => modules/rhino1.4/consumer-rules.pro (72%) rename {rhino => modules/rhino1.4}/lib/rhino-1.7.14-2.jar (100%) create mode 100644 modules/rhino1.4/src/main/AndroidManifest.xml create mode 100644 modules/rhino1.4/src/main/java/com/script/AbstractScriptEngine.kt create mode 100644 modules/rhino1.4/src/main/java/com/script/Bindings.kt create mode 100644 modules/rhino1.4/src/main/java/com/script/Compilable.kt create mode 100644 modules/rhino1.4/src/main/java/com/script/CompiledScript.kt create mode 100644 modules/rhino1.4/src/main/java/com/script/Invocable.kt create mode 100644 modules/rhino1.4/src/main/java/com/script/ScriptContext.kt create mode 100644 modules/rhino1.4/src/main/java/com/script/ScriptEngine.kt create mode 100644 modules/rhino1.4/src/main/java/com/script/ScriptException.kt create mode 100644 modules/rhino1.4/src/main/java/com/script/SimpleBindings.kt create mode 100644 modules/rhino1.4/src/main/java/com/script/SimpleScriptContext.kt create mode 100644 modules/rhino1.4/src/main/java/com/script/rhino/ExternalScriptable.kt create mode 100644 modules/rhino1.4/src/main/java/com/script/rhino/InterfaceImplementor.kt create mode 100644 modules/rhino1.4/src/main/java/com/script/rhino/JSAdapter.kt create mode 100644 modules/rhino1.4/src/main/java/com/script/rhino/JavaAdapter.kt create mode 100644 modules/rhino1.4/src/main/java/com/script/rhino/RhinoClassShutter.kt create mode 100644 modules/rhino1.4/src/main/java/com/script/rhino/RhinoCompiledScript.kt rename {rhino => modules/rhino1.4}/src/main/java/com/script/rhino/RhinoScriptEngine.kt (100%) create mode 100644 modules/rhino1.4/src/main/java/com/script/rhino/RhinoTopLevel.kt create mode 100644 modules/rhino1.4/src/main/java/com/script/rhino/RhinoWrapFactory.kt delete mode 100644 rhino/consumer-rules.pro diff --git a/app/build.gradle b/app/build.gradle index b3aaececb..70f568645 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -41,7 +41,7 @@ android { } defaultConfig { applicationId "io.legado.app" - minSdk 21 + minSdk 24 targetSdk 33 versionCode 10000 + gitCommits versionName version @@ -107,6 +107,11 @@ android { applicationId "io.legado.play" manifestPlaceholders.put("APP_CHANNEL_VALUE", "google") } + lollipop { + dimension "mode" + minSdk 21 + manifestPlaceholders.put("APP_CHANNEL_VALUE", "lollipop") + } } compileOptions { @@ -198,10 +203,12 @@ dependencies { implementation('org.jsoup:jsoup:1.15.4') implementation('com.jayway.jsonpath:json-path:2.8.0') implementation('cn.wanghaomiao:JsoupXpath:2.5.3') - implementation(project(path: ':book')) + implementation(project(path: ':modules:book')) //JS rhino - implementation(project(path: ':rhino')) + appImplementation(project(path: ':modules:rhino1.4')) + googleImplementation(project(path: ':modules:rhino1.4')) + lollipopImplementation(project(path: ':modules:rhino1.3')) //网络 implementation('com.squareup.okhttp3:okhttp:4.10.0') diff --git a/book/src/main/java/me/ag2s/epublib/Constants.java b/book/src/main/java/me/ag2s/epublib/Constants.java deleted file mode 100644 index d9f873e41..000000000 --- a/book/src/main/java/me/ag2s/epublib/Constants.java +++ /dev/null @@ -1,13 +0,0 @@ -package me.ag2s.epublib; - - -public interface Constants { - - String CHARACTER_ENCODING = "UTF-8"; - String DOCTYPE_XHTML = ""; - String NAMESPACE_XHTML = "http://www.w3.org/1999/xhtml"; - String EPUB_GENERATOR_NAME = "Ag2S EpubLib"; - String EPUB_DUOKAN_NAME = "DK-SONGTI"; - char FRAGMENT_SEPARATOR_CHAR = '#'; - String DEFAULT_TOC_ID = "toc"; -} diff --git a/book/src/main/java/me/ag2s/epublib/browsersupport/NavigationEvent.java b/book/src/main/java/me/ag2s/epublib/browsersupport/NavigationEvent.java deleted file mode 100644 index 9b52e01cb..000000000 --- a/book/src/main/java/me/ag2s/epublib/browsersupport/NavigationEvent.java +++ /dev/null @@ -1,158 +0,0 @@ -package me.ag2s.epublib.browsersupport; - -import java.util.EventObject; - -import me.ag2s.epublib.domain.EpubBook; -import me.ag2s.epublib.domain.Resource; -import me.ag2s.epublib.util.StringUtil; - -/** - * Used to tell NavigationEventListener just what kind of navigation action - * the user just did. - * - * @author paul - * - */ -@SuppressWarnings("unused") -public class NavigationEvent extends EventObject { - - private static final long serialVersionUID = -6346750144308952762L; - - private Resource oldResource; - private int oldSpinePos; - private Navigator navigator; - private EpubBook oldBook; - private int oldSectionPos; - private String oldFragmentId; - - public NavigationEvent(Object source) { - super(source); - } - - public NavigationEvent(Object source, Navigator navigator) { - super(source); - this.navigator = navigator; - this.oldBook = navigator.getBook(); - this.oldFragmentId = navigator.getCurrentFragmentId(); - this.oldSectionPos = navigator.getCurrentSectionPos(); - this.oldResource = navigator.getCurrentResource(); - this.oldSpinePos = navigator.getCurrentSpinePos(); - } - - /** - * The previous position within the section. - * - * @return The previous position within the section. - */ - public int getOldSectionPos() { - return oldSectionPos; - } - - public Navigator getNavigator() { - return navigator; - } - - public String getOldFragmentId() { - return oldFragmentId; - } - - // package - void setOldFragmentId(String oldFragmentId) { - this.oldFragmentId = oldFragmentId; - } - - public EpubBook getOldBook() { - return oldBook; - } - - // package - void setOldPagePos(int oldPagePos) { - this.oldSectionPos = oldPagePos; - } - - public int getCurrentSectionPos() { - return navigator.getCurrentSectionPos(); - } - - public int getOldSpinePos() { - return oldSpinePos; - } - - public int getCurrentSpinePos() { - return navigator.getCurrentSpinePos(); - } - - public String getCurrentFragmentId() { - return navigator.getCurrentFragmentId(); - } - - public boolean isBookChanged() { - if (oldBook == null) { - return true; - } - return oldBook != navigator.getBook(); - } - - public boolean isSpinePosChanged() { - return getOldSpinePos() != getCurrentSpinePos(); - } - - public boolean isFragmentChanged() { - return StringUtil.equals(getOldFragmentId(), getCurrentFragmentId()); - } - - public Resource getOldResource() { - return oldResource; - } - - public Resource getCurrentResource() { - return navigator.getCurrentResource(); - } - - public void setOldResource(Resource oldResource) { - this.oldResource = oldResource; - } - - - public void setOldSpinePos(int oldSpinePos) { - this.oldSpinePos = oldSpinePos; - } - - - public void setNavigator(Navigator navigator) { - this.navigator = navigator; - } - - - public void setOldBook(EpubBook oldBook) { - this.oldBook = oldBook; - } - - public EpubBook getCurrentBook() { - return getNavigator().getBook(); - } - - public boolean isResourceChanged() { - return oldResource != getCurrentResource(); - } - - @SuppressWarnings("NullableProblems") - public String toString() { - return StringUtil.toString( - "oldSectionPos", oldSectionPos, - "oldResource", oldResource, - "oldBook", oldBook, - "oldFragmentId", oldFragmentId, - "oldSpinePos", oldSpinePos, - "currentPagePos", getCurrentSectionPos(), - "currentResource", getCurrentResource(), - "currentBook", getCurrentBook(), - "currentFragmentId", getCurrentFragmentId(), - "currentSpinePos", getCurrentSpinePos() - ); - } - - public boolean isSectionPosChanged() { - return oldSectionPos != getCurrentSectionPos(); - } -} diff --git a/book/src/main/java/me/ag2s/epublib/browsersupport/NavigationHistory.java b/book/src/main/java/me/ag2s/epublib/browsersupport/NavigationHistory.java deleted file mode 100644 index 710f0240c..000000000 --- a/book/src/main/java/me/ag2s/epublib/browsersupport/NavigationHistory.java +++ /dev/null @@ -1,207 +0,0 @@ -package me.ag2s.epublib.browsersupport; - -import java.util.ArrayList; -import java.util.List; - -import me.ag2s.epublib.domain.EpubBook; -import me.ag2s.epublib.domain.Resource; - -/** - * A history of the user's locations with the epub. - * - * @author paul.siegmann - */ -public class NavigationHistory implements NavigationEventListener { - - public static final int DEFAULT_MAX_HISTORY_SIZE = 1000; - private static final long DEFAULT_HISTORY_WAIT_TIME = 1000; - - private static class Location { - - private String href; - - public Location(String href) { - super(); - this.href = href; - } - - @SuppressWarnings("unused") - public void setHref(String href) { - this.href = href; - } - - public String getHref() { - return href; - } - } - - private long lastUpdateTime = 0; - private List locations = new ArrayList<>(); - private final Navigator navigator; - private int currentPos = -1; - private int currentSize = 0; - private int maxHistorySize = DEFAULT_MAX_HISTORY_SIZE; - private long historyWaitTime = DEFAULT_HISTORY_WAIT_TIME; - - public NavigationHistory(Navigator navigator) { - this.navigator = navigator; - navigator.addNavigationEventListener(this); - initBook(navigator.getBook()); - } - - public int getCurrentPos() { - return currentPos; - } - - - public int getCurrentSize() { - return currentSize; - } - - public void initBook(EpubBook book) { - if (book == null) { - return; - } - locations = new ArrayList<>(); - currentPos = -1; - currentSize = 0; - if (navigator.getCurrentResource() != null) { - addLocation(navigator.getCurrentResource().getHref()); - } - } - - /** - * If the time between a navigation event is less than the historyWaitTime - * then the new location is not added to the history. - * - * When a user is rapidly viewing many pages using the slider we do not - * want all of them to be added to the history. - * - * @return the time we wait before adding the page to the history - */ - public long getHistoryWaitTime() { - return historyWaitTime; - } - - public void setHistoryWaitTime(long historyWaitTime) { - this.historyWaitTime = historyWaitTime; - } - - public void addLocation(Resource resource) { - if (resource == null) { - return; - } - addLocation(resource.getHref()); - } - - /** - * Adds the location after the current position. - * If the currentposition is not the end of the list then the elements - * between the current element and the end of the list will be discarded. - * - * Does nothing if the new location matches the current location. - *
- * If this nr of locations becomes larger then the historySize then the - * first item(s) will be removed. - *v - * @param location d - */ - public void addLocation(Location location) { - // do nothing if the new location matches the current location - if (!(locations.isEmpty()) && - location.getHref().equals(locations.get(currentPos).getHref())) { - return; - } - currentPos++; - if (currentPos != currentSize) { - locations.set(currentPos, location); - } else { - locations.add(location); - checkHistorySize(); - } - currentSize = currentPos + 1; - } - - /** - * Removes all elements that are too much for the maxHistorySize - * out of the history. - */ - private void checkHistorySize() { - while (locations.size() > maxHistorySize) { - locations.remove(0); - currentSize--; - currentPos--; - } - } - - public void addLocation(String href) { - addLocation(new Location(href)); - } - - private String getLocationHref(int pos) { - if (pos < 0 || pos >= locations.size()) { - return null; - } - return locations.get(currentPos).getHref(); - } - - /** - * Moves the current positions delta positions. - * - * move(-1) to go one position back in history.
- * move(1) to go one position forward.
发 - * - * @param delta f - * - * @return Whether we actually moved. If the requested value is illegal - * it will return false, true otherwise. - */ - public boolean move(int delta) { - if (((currentPos + delta) < 0) - || ((currentPos + delta) >= currentSize)) { - return false; - } - currentPos += delta; - navigator.gotoResource(getLocationHref(currentPos), this); - return true; - } - - - /** - * If this is not the source of the navigationEvent then the addLocation - * will be called with the href of the currentResource in the navigationEvent. - */ - @Override - public void navigationPerformed(NavigationEvent navigationEvent) { - if (this == navigationEvent.getSource()) { - return; - } - if (navigationEvent.getCurrentResource() == null) { - return; - } - - if ((System.currentTimeMillis() - this.lastUpdateTime) > historyWaitTime) { - // if the user scrolled rapidly through the pages then the last page - // will not be added to the history. We fix that here: - addLocation(navigationEvent.getOldResource()); - - addLocation(navigationEvent.getCurrentResource().getHref()); - } - lastUpdateTime = System.currentTimeMillis(); - } - - public String getCurrentHref() { - if (currentPos < 0 || currentPos >= locations.size()) { - return null; - } - return locations.get(currentPos).getHref(); - } - - public void setMaxHistorySize(int maxHistorySize) { - this.maxHistorySize = maxHistorySize; - } - - public int getMaxHistorySize() { - return maxHistorySize; - } -} diff --git a/book/src/main/java/me/ag2s/epublib/browsersupport/Navigator.java b/book/src/main/java/me/ag2s/epublib/browsersupport/Navigator.java deleted file mode 100644 index 84319e65e..000000000 --- a/book/src/main/java/me/ag2s/epublib/browsersupport/Navigator.java +++ /dev/null @@ -1,220 +0,0 @@ -package me.ag2s.epublib.browsersupport; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -import me.ag2s.epublib.domain.EpubBook; -import me.ag2s.epublib.domain.Resource; - -/** - * A helper class for epub browser applications. - *

- * It helps moving from one resource to the other, from one resource - * to the other and keeping other elements of the application up-to-date - * by calling the NavigationEventListeners. - * - * @author paul - */ -public class Navigator implements Serializable { - - private static final long serialVersionUID = 1076126986424925474L; - private EpubBook book; - private int currentSpinePos; - private Resource currentResource; - private int currentPagePos; - private String currentFragmentId; - - private final List eventListeners = new ArrayList<>(); - - public Navigator() { - this(null); - } - - public Navigator(EpubBook book) { - this.book = book; - this.currentSpinePos = 0; - if (book != null) { - this.currentResource = book.getCoverPage(); - } - this.currentPagePos = 0; - } - - private synchronized void handleEventListeners( - NavigationEvent navigationEvent) { - for (int i = 0; i < eventListeners.size(); i++) { - NavigationEventListener navigationEventListener = eventListeners.get(i); - navigationEventListener.navigationPerformed(navigationEvent); - } - } - - public boolean addNavigationEventListener( - NavigationEventListener navigationEventListener) { - return this.eventListeners.add(navigationEventListener); - } - - public boolean removeNavigationEventListener( - NavigationEventListener navigationEventListener) { - return this.eventListeners.remove(navigationEventListener); - } - - public int gotoFirstSpineSection(Object source) { - return gotoSpineSection(0, source); - } - - public int gotoPreviousSpineSection(Object source) { - return gotoPreviousSpineSection(0, source); - } - - public int gotoPreviousSpineSection(int pagePos, Object source) { - if (currentSpinePos < 0) { - return gotoSpineSection(0, pagePos, source); - } else { - return gotoSpineSection(currentSpinePos - 1, pagePos, source); - } - } - - public boolean hasNextSpineSection() { - return (currentSpinePos < (book.getSpine().size() - 1)); - } - - public boolean hasPreviousSpineSection() { - return (currentSpinePos > 0); - } - - public int gotoNextSpineSection(Object source) { - if (currentSpinePos < 0) { - return gotoSpineSection(0, source); - } else { - return gotoSpineSection(currentSpinePos + 1, source); - } - } - - public int gotoResource(String resourceHref, Object source) { - Resource resource = book.getResources().getByHref(resourceHref); - return gotoResource(resource, source); - } - - - public int gotoResource(Resource resource, Object source) { - return gotoResource(resource, 0, null, source); - } - - public int gotoResource(Resource resource, String fragmentId, Object source) { - return gotoResource(resource, 0, fragmentId, source); - } - - public int gotoResource(Resource resource, int pagePos, Object source) { - return gotoResource(resource, pagePos, null, source); - } - - public int gotoResource(Resource resource, int pagePos, String fragmentId, - Object source) { - if (resource == null) { - return -1; - } - NavigationEvent navigationEvent = new NavigationEvent(source, this); - this.currentResource = resource; - this.currentSpinePos = book.getSpine().getResourceIndex(currentResource); - this.currentPagePos = pagePos; - this.currentFragmentId = fragmentId; - handleEventListeners(navigationEvent); - - return currentSpinePos; - } - - public int gotoResourceId(String resourceId, Object source) { - return gotoSpineSection(book.getSpine().findFirstResourceById(resourceId), - source); - } - - public int gotoSpineSection(int newSpinePos, Object source) { - return gotoSpineSection(newSpinePos, 0, source); - } - - /** - * Go to a specific section. - * Illegal spine positions are silently ignored. - * - * @param newSpinePos f - * @param source f - * @return The current position within the spine - */ - public int gotoSpineSection(int newSpinePos, int newPagePos, Object source) { - if (newSpinePos == currentSpinePos) { - return currentSpinePos; - } - if (newSpinePos < 0 || newSpinePos >= book.getSpine().size()) { - return currentSpinePos; - } - NavigationEvent navigationEvent = new NavigationEvent(source, this); - currentSpinePos = newSpinePos; - currentPagePos = newPagePos; - currentResource = book.getSpine().getResource(currentSpinePos); - handleEventListeners(navigationEvent); - return currentSpinePos; - } - - public int gotoLastSpineSection(Object source) { - return gotoSpineSection(book.getSpine().size() - 1, source); - } - - public void gotoBook(EpubBook book, Object source) { - NavigationEvent navigationEvent = new NavigationEvent(source, this); - this.book = book; - this.currentFragmentId = null; - this.currentPagePos = 0; - this.currentResource = null; - this.currentSpinePos = book.getSpine().getResourceIndex(currentResource); - handleEventListeners(navigationEvent); - } - - /** - * The current position within the spine. - * - * @return something < 0 if the current position is not within the spine. - */ - public int getCurrentSpinePos() { - return currentSpinePos; - } - - public Resource getCurrentResource() { - return currentResource; - } - - /** - * Sets the current index and resource without calling the eventlisteners. - * - * If you want the eventListeners called use gotoSection(index); - * - * @param currentIndex f - */ - public void setCurrentSpinePos(int currentIndex) { - this.currentSpinePos = currentIndex; - this.currentResource = book.getSpine().getResource(currentIndex); - } - - public EpubBook getBook() { - return book; - } - - /** - * Sets the current index and resource without calling the eventlisteners. - * - * If you want the eventListeners called use gotoSection(index); - * - */ - public int setCurrentResource(Resource currentResource) { - this.currentSpinePos = book.getSpine().getResourceIndex(currentResource); - this.currentResource = currentResource; - return currentSpinePos; - } - - public String getCurrentFragmentId() { - return currentFragmentId; - } - - public int getCurrentSectionPos() { - return currentPagePos; - } -} diff --git a/book/src/main/java/me/ag2s/epublib/domain/EpubResourceProvider.java b/book/src/main/java/me/ag2s/epublib/domain/EpubResourceProvider.java deleted file mode 100644 index a1b42c75c..000000000 --- a/book/src/main/java/me/ag2s/epublib/domain/EpubResourceProvider.java +++ /dev/null @@ -1,37 +0,0 @@ -package me.ag2s.epublib.domain; - -import androidx.annotation.NonNull; - -import java.io.IOException; -import java.io.InputStream; - -import me.ag2s.epublib.util.zip.ZipEntryWrapper; -import me.ag2s.epublib.util.zip.ZipFileWrapper; - -/** - * @author jake - */ -public class EpubResourceProvider implements LazyResourceProvider { - - - private final ZipFileWrapper zipFileWrapper; - - - public EpubResourceProvider(ZipFileWrapper zipFileWrapper) { - this.zipFileWrapper = zipFileWrapper; - } - - - @Override - public InputStream getResourceStream(@NonNull String href) throws IOException { - - //ZipFile zipFile = new ZipFile(epubFilename); - ZipEntryWrapper zipEntry = zipFileWrapper.getEntry(href); - if (zipEntry == null) { - //zipFile.close(); - throw new IllegalStateException( - "Cannot find entry " + href + " in epub file " + zipFileWrapper); - } - return new ResourceInputStream(zipFileWrapper.getInputStream(zipEntry)); - } -} diff --git a/book/src/main/java/me/ag2s/epublib/domain/Guide.java b/book/src/main/java/me/ag2s/epublib/domain/Guide.java deleted file mode 100644 index 57c0467a9..000000000 --- a/book/src/main/java/me/ag2s/epublib/domain/Guide.java +++ /dev/null @@ -1,128 +0,0 @@ -package me.ag2s.epublib.domain; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -/** - * The guide is a selection of special pages of the book. - * Examples of these are the cover, list of illustrations, etc. - * - * It is an optional part of an epub, and support for the various types - * of references varies by reader. - * - * The only part of this that is heavily used is the cover page. - * - * @author paul - * - */ -public class Guide implements Serializable { - - /** - * - */ - private static final long serialVersionUID = -6256645339915751189L; - - public static final String DEFAULT_COVER_TITLE = GuideReference.COVER; - - private List references = new ArrayList<>(); - private static final int COVERPAGE_NOT_FOUND = -1; - private static final int COVERPAGE_UNITIALIZED = -2; - - private int coverPageIndex = -1; - - public List getReferences() { - return references; - } - - public void setReferences(List references) { - this.references = references; - uncheckCoverPage(); - } - - private void uncheckCoverPage() { - coverPageIndex = COVERPAGE_UNITIALIZED; - } - - public GuideReference getCoverReference() { - checkCoverPage(); - if (coverPageIndex >= 0) { - return references.get(coverPageIndex); - } - return null; - } - @SuppressWarnings("UnusedReturnValue") - public int setCoverReference(GuideReference guideReference) { - if (coverPageIndex >= 0) { - references.set(coverPageIndex, guideReference); - } else { - references.add(0, guideReference); - coverPageIndex = 0; - } - return coverPageIndex; - } - - private void checkCoverPage() { - if (coverPageIndex == COVERPAGE_UNITIALIZED) { - initCoverPage(); - } - } - - - private void initCoverPage() { - int result = COVERPAGE_NOT_FOUND; - for (int i = 0; i < references.size(); i++) { - GuideReference guideReference = references.get(i); - if (guideReference.getType().equals(GuideReference.COVER)) { - result = i; - break; - } - } - coverPageIndex = result; - } - - /** - * The coverpage of the book. - * - * @return The coverpage of the book. - */ - public Resource getCoverPage() { - GuideReference guideReference = getCoverReference(); - if (guideReference == null) { - return null; - } - return guideReference.getResource(); - } - - public void setCoverPage(Resource coverPage) { - GuideReference coverpageGuideReference = new GuideReference(coverPage, - GuideReference.COVER, DEFAULT_COVER_TITLE); - setCoverReference(coverpageGuideReference); - } - - @SuppressWarnings("UnusedReturnValue") - public ResourceReference addReference(GuideReference reference) { - this.references.add(reference); - uncheckCoverPage(); - return reference; - } - - /** - * A list of all GuideReferences that have the given - * referenceTypeName (ignoring case). - * - * @param referenceTypeName referenceTypeName - * @return A list of all GuideReferences that have the given - * referenceTypeName (ignoring case). - */ - public List getGuideReferencesByType( - String referenceTypeName) { - List result = new ArrayList<>(); - for (GuideReference guideReference : references) { - if (referenceTypeName.equalsIgnoreCase(guideReference.getType())) { - result.add(guideReference); - } - } - return result; - } -} diff --git a/book/src/main/java/me/ag2s/epublib/domain/GuideReference.java b/book/src/main/java/me/ag2s/epublib/domain/GuideReference.java deleted file mode 100644 index 770f4c003..000000000 --- a/book/src/main/java/me/ag2s/epublib/domain/GuideReference.java +++ /dev/null @@ -1,103 +0,0 @@ -package me.ag2s.epublib.domain; - -import java.io.Serializable; - -import me.ag2s.epublib.util.StringUtil; - - -/** - * These are references to elements of the book's guide. - * - * @see Guide - * - * @author paul - * - */ -public class GuideReference extends TitledResourceReference - implements Serializable { - - private static final long serialVersionUID = -316179702440631834L; - - /** - * the book cover(s), jacket information, etc. - */ - public static final String COVER = "cover"; - - /** - * human-readable page with title, author, publisher, and other metadata - */ - public static String TITLE_PAGE = "title-page"; - - /** - * Human-readable table of contents. - * Not to be confused the epub file table of contents - * - */ - public static String TOC = "toc"; - - /** - * back-of-book style index - */ - public static String INDEX = "index"; - public static String GLOSSARY = "glossary"; - public static String ACKNOWLEDGEMENTS = "acknowledgements"; - public static String BIBLIOGRAPHY = "bibliography"; - public static String COLOPHON = "colophon"; - public static String COPYRIGHT_PAGE = "copyright-page"; - public static String DEDICATION = "dedication"; - - /** - * an epigraph is a phrase, quotation, or poem that is set at the - * beginning of a document or component. - * - * source: http://en.wikipedia.org/wiki/Epigraph_%28literature%29 - */ - public static String EPIGRAPH = "epigraph"; - - public static String FOREWORD = "foreword"; - - /** - * list of illustrations - */ - public static String LOI = "loi"; - - /** - * list of tables - */ - public static String LOT = "lot"; - public static String NOTES = "notes"; - public static String PREFACE = "preface"; - - /** - * A page of content (e.g. "Chapter 1") - */ - public static String TEXT = "text"; - - private String type; - - public GuideReference(Resource resource) { - this(resource, null); - } - - public GuideReference(Resource resource, String title) { - super(resource, title); - } - - public GuideReference(Resource resource, String type, String title) { - this(resource, type, title, null); - } - - public GuideReference(Resource resource, String type, String title, - String fragmentId) { - super(resource, title, fragmentId); - this.type = StringUtil.isNotBlank(type) ? type.toLowerCase() : null; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } -} diff --git a/book/src/main/java/me/ag2s/epublib/domain/Identifier.java b/book/src/main/java/me/ag2s/epublib/domain/Identifier.java deleted file mode 100644 index 341c1da73..000000000 --- a/book/src/main/java/me/ag2s/epublib/domain/Identifier.java +++ /dev/null @@ -1,131 +0,0 @@ -package me.ag2s.epublib.domain; - -import java.io.Serializable; -import java.util.List; -import java.util.UUID; - -import me.ag2s.epublib.util.StringUtil; - -/** - * A Book's identifier. - * - * Defaults to a random UUID and scheme "UUID" - * - * @author paul - */ -public class Identifier implements Serializable { - - private static final long serialVersionUID = 955949951416391810L; - @SuppressWarnings("unused") - public interface Scheme { - - String UUID = "UUID"; - String ISBN = "ISBN"; - String URL = "URL"; - String URI = "URI"; - } - - private boolean bookId = false; - private String scheme; - private String value; - - /** - * Creates an Identifier with as value a random UUID and scheme "UUID" - */ - public Identifier() { - this(Scheme.UUID, UUID.randomUUID().toString()); - } - - - public Identifier(String scheme, String value) { - this.scheme = scheme; - this.value = value; - } - - /** - * The first identifier for which the bookId is true is made the - * bookId identifier. - * - * If no identifier has bookId == true then the first bookId identifier - * is written as the primary. - * - * @param identifiers i - * @return The first identifier for which the bookId is true is made - * the bookId identifier. - */ - public static Identifier getBookIdIdentifier(List identifiers) { - if (identifiers == null || identifiers.isEmpty()) { - return null; - } - - Identifier result = null; - for (Identifier identifier : identifiers) { - if (identifier.isBookId()) { - result = identifier; - break; - } - } - - if (result == null) { - result = identifiers.get(0); - } - - return result; - } - - public String getScheme() { - return scheme; - } - - public void setScheme(String scheme) { - this.scheme = scheme; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - - public void setBookId(boolean bookId) { - this.bookId = bookId; - } - - - /** - * This bookId property allows the book creator to add multiple ids and - * tell the epubwriter which one to write out as the bookId. - * - * The Dublin Core metadata spec allows multiple identifiers for a Book. - * The epub spec requires exactly one identifier to be marked as the book id. - * - * @return whether this is the unique book id. - */ - public boolean isBookId() { - return bookId; - } - - public int hashCode() { - return StringUtil.defaultIfNull(scheme).hashCode() ^ StringUtil - .defaultIfNull(value).hashCode(); - } - - public boolean equals(Object otherIdentifier) { - if (!(otherIdentifier instanceof Identifier)) { - return false; - } - return StringUtil.equals(scheme, ((Identifier) otherIdentifier).scheme) - && StringUtil.equals(value, ((Identifier) otherIdentifier).value); - } - @SuppressWarnings("NullableProblems") - @Override - public String toString() { - if (StringUtil.isBlank(scheme)) { - return "" + value; - } - return "" + scheme + ":" + value; - } -} diff --git a/book/src/main/java/me/ag2s/epublib/domain/LazyResource.java b/book/src/main/java/me/ag2s/epublib/domain/LazyResource.java deleted file mode 100644 index b4fd1522d..000000000 --- a/book/src/main/java/me/ag2s/epublib/domain/LazyResource.java +++ /dev/null @@ -1,144 +0,0 @@ -package me.ag2s.epublib.domain; - -import android.util.Log; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; - -import me.ag2s.epublib.util.IOUtil; - -/** - * A Resource that loads its data only on-demand from a EPUB book file. - * This way larger books can fit into memory and can be opened faster. - */ -public class LazyResource extends Resource { - - private static final long serialVersionUID = 5089400472352002866L; - private final String TAG= getClass().getName(); - - private final LazyResourceProvider resourceProvider; - private final long cachedSize; - - /** - * Creates a lazy resource, when the size is unknown. - * - * @param resourceProvider The resource provider loads data on demand. - * @param href The resource's href within the epub. - */ - public LazyResource(LazyResourceProvider resourceProvider, String href) { - this(resourceProvider, -1, href); - } - public LazyResource(LazyResourceProvider resourceProvider, String href, String originalHref) { - this(resourceProvider, -1, href, originalHref); - } - - /** - * Creates a Lazy resource, by not actually loading the data for this entry. - * - * The data will be loaded on the first call to getData() - * - * @param resourceProvider The resource provider loads data on demand. - * @param size The size of this resource. - * @param href The resource's href within the epub. - */ - public LazyResource( - LazyResourceProvider resourceProvider, long size, String href) { - super(null, null, href, MediaTypes.determineMediaType(href)); - this.resourceProvider = resourceProvider; - this.cachedSize = size; - } - public LazyResource( - LazyResourceProvider resourceProvider, long size, String href, String originalHref) { - super(null, null, href, originalHref, MediaTypes.determineMediaType(href)); - this.resourceProvider = resourceProvider; - this.cachedSize = size; - } - - /** - * Gets the contents of the Resource as an InputStream. - * - * @return The contents of the Resource. - * - * @throws IOException IOException - */ - public InputStream getInputStream() throws IOException { - if (isInitialized()) { - return new ByteArrayInputStream(getData()); - } else { - return resourceProvider.getResourceStream(this.originalHref); - } - } - - /** - * Initializes the resource by loading its data into memory. - * - * @throws IOException IOException - */ - public void initialize() throws IOException { - getData(); - } - - /** - * The contents of the resource as a byte[] - * - * If this resource was lazy-loaded and the data was not yet loaded, - * it will be loaded into memory at this point. - * This included opening the zip file, so expect a first load to be slow. - * - * @return The contents of the resource - */ - public byte[] getData() throws IOException { - - if (data == null) { - - Log.d(TAG, "Initializing lazy resource: " + this.getHref()); - - InputStream in = resourceProvider.getResourceStream(this.originalHref); - byte[] readData = IOUtil.toByteArray(in, (int) this.cachedSize); - if (readData == null) { - throw new IOException( - "Could not load the contents of resource: " + this.getHref()); - } else { - this.data = readData; - } - - in.close(); - } - - return data; - } - - /** - * Tells this resource to release its cached data. - * - * If this resource was not lazy-loaded, this is a no-op. - */ - public void close() { - if (this.resourceProvider != null) { - this.data = null; - } - } - - /** - * Returns if the data for this resource has been loaded into memory. - * - * @return true if data was loaded. - */ - public boolean isInitialized() { - return data != null; - } - - /** - * Returns the size of this resource in bytes. - * - * @return the size. - */ - public long getSize() { - if (data != null) { - return data.length; - } - - return cachedSize; - } -} diff --git a/book/src/main/java/me/ag2s/epublib/domain/ManifestItemProperties.java b/book/src/main/java/me/ag2s/epublib/domain/ManifestItemProperties.java deleted file mode 100644 index dd21eead5..000000000 --- a/book/src/main/java/me/ag2s/epublib/domain/ManifestItemProperties.java +++ /dev/null @@ -1,21 +0,0 @@ -package me.ag2s.epublib.domain; -@SuppressWarnings("unused") -public enum ManifestItemProperties implements ManifestProperties { - COVER_IMAGE("cover-image"), - MATHML("mathml"), - NAV("nav"), - REMOTE_RESOURCES("remote-resources"), - SCRIPTED("scripted"), - SVG("svg"), - SWITCH("switch"); - - private final String name; - - ManifestItemProperties(String name) { - this.name = name; - } - - public String getName() { - return name; - } -} diff --git a/book/src/main/java/me/ag2s/epublib/domain/ManifestItemRefProperties.java b/book/src/main/java/me/ag2s/epublib/domain/ManifestItemRefProperties.java deleted file mode 100644 index b67d63f91..000000000 --- a/book/src/main/java/me/ag2s/epublib/domain/ManifestItemRefProperties.java +++ /dev/null @@ -1,16 +0,0 @@ -package me.ag2s.epublib.domain; -@SuppressWarnings("unused") -public enum ManifestItemRefProperties implements ManifestProperties { - PAGE_SPREAD_LEFT("page-spread-left"), - PAGE_SPREAD_RIGHT("page-spread-right"); - - private final String name; - - ManifestItemRefProperties(String name) { - this.name = name; - } - - public String getName() { - return name; - } -} diff --git a/book/src/main/java/me/ag2s/epublib/domain/MediaType.java b/book/src/main/java/me/ag2s/epublib/domain/MediaType.java deleted file mode 100644 index 9a6817996..000000000 --- a/book/src/main/java/me/ag2s/epublib/domain/MediaType.java +++ /dev/null @@ -1,73 +0,0 @@ -package me.ag2s.epublib.domain; - -import java.io.Serializable; -import java.util.Arrays; -import java.util.Collection; - -/** - * MediaType is used to tell the type of content a resource is. - * - * Examples of mediatypes are image/gif, text/css and application/xhtml+xml - * - * All allowed mediaTypes are maintained bye the MediaTypeService. - * - * @see MediaTypes - * - * @author paul - */ -public class MediaType implements Serializable { - - private static final long serialVersionUID = -7256091153727506788L; - private final String name; - private final String defaultExtension; - private final Collection extensions; - - public MediaType(String name, String defaultExtension) { - this(name, defaultExtension, new String[]{defaultExtension}); - } - - public MediaType(String name, String defaultExtension, - String[] extensions) { - this(name, defaultExtension, Arrays.asList(extensions)); - } - - public int hashCode() { - if (name == null) { - return 0; - } - return name.hashCode(); - } - - public MediaType(String name, String defaultExtension, - Collection mextensions) { - super(); - this.name = name; - this.defaultExtension = defaultExtension; - this.extensions = mextensions; - } - - public String getName() { - return name; - } - - - public String getDefaultExtension() { - return defaultExtension; - } - - - public Collection getExtensions() { - return extensions; - } - - public boolean equals(Object otherMediaType) { - if (!(otherMediaType instanceof MediaType)) { - return false; - } - return name.equals(((MediaType) otherMediaType).getName()); - } - @SuppressWarnings("NullableProblems") - public String toString() { - return name; - } -} diff --git a/book/src/main/java/me/ag2s/epublib/domain/MediaTypes.java b/book/src/main/java/me/ag2s/epublib/domain/MediaTypes.java deleted file mode 100644 index bba77ccc6..000000000 --- a/book/src/main/java/me/ag2s/epublib/domain/MediaTypes.java +++ /dev/null @@ -1,95 +0,0 @@ -package me.ag2s.epublib.domain; - -import java.util.HashMap; -import java.util.Map; - -import me.ag2s.epublib.util.StringUtil; - - -/** - * Manages mediatypes that are used by epubs - * - * @author paul - */ -public class MediaTypes { - - public static final MediaType XHTML = new MediaType("application/xhtml+xml", - ".xhtml", new String[]{".htm", ".html", ".xhtml"}); - public static final MediaType EPUB = new MediaType("application/epub+zip", - ".epub"); - public static final MediaType NCX = new MediaType("application/x-dtbncx+xml", - ".ncx"); - - public static final MediaType JAVASCRIPT = new MediaType("text/javascript", - ".js"); - public static final MediaType CSS = new MediaType("text/css", ".css"); - - // images - public static final MediaType JPG = new MediaType("image/jpeg", ".jpg", - new String[]{".jpg", ".jpeg"}); - public static final MediaType PNG = new MediaType("image/png", ".png"); - public static final MediaType GIF = new MediaType("image/gif", ".gif"); - - public static final MediaType SVG = new MediaType("image/svg+xml", ".svg"); - - // fonts - public static final MediaType TTF = new MediaType( - "application/x-truetype-font", ".ttf"); - public static final MediaType OPENTYPE = new MediaType( - "application/vnd.ms-opentype", ".otf"); - public static final MediaType WOFF = new MediaType("application/font-woff", - ".woff"); - - // audio - public static final MediaType MP3 = new MediaType("audio/mpeg", ".mp3"); - public static final MediaType OGG = new MediaType("audio/ogg", ".ogg"); - - // video - public static final MediaType MP4 = new MediaType("video/mp4", ".mp4"); - - public static final MediaType SMIL = new MediaType("application/smil+xml", - ".smil"); - public static final MediaType XPGT = new MediaType( - "application/adobe-page-template+xml", ".xpgt"); - public static final MediaType PLS = new MediaType("application/pls+xml", - ".pls"); - - public static final MediaType[] mediaTypes = new MediaType[]{ - XHTML, EPUB, JPG, PNG, GIF, CSS, SVG, TTF, NCX, XPGT, OPENTYPE, WOFF, - SMIL, PLS, JAVASCRIPT, MP3, MP4, OGG - }; - - public static final Map mediaTypesByName = new HashMap<>(); - - static { - for (MediaType mediaType : mediaTypes) { - mediaTypesByName.put(mediaType.getName(), mediaType); - } - } - - public static boolean isBitmapImage(MediaType mediaType) { - return mediaType == JPG || mediaType == PNG || mediaType == GIF; - } - - /** - * Gets the MediaType based on the file extension. - * Null of no matching extension found. - * - * @param filename filename - * @return the MediaType based on the file extension. - */ - public static MediaType determineMediaType(String filename) { - for (MediaType mediaType : mediaTypesByName.values()) { - for (String extension : mediaType.getExtensions()) { - if (StringUtil.endsWithIgnoreCase(filename, extension)) { - return mediaType; - } - } - } - return null; - } - - public static MediaType getMediaTypeByName(String mediaTypeName) { - return mediaTypesByName.get(mediaTypeName); - } -} diff --git a/book/src/main/java/me/ag2s/epublib/domain/Relator.java b/book/src/main/java/me/ag2s/epublib/domain/Relator.java deleted file mode 100644 index b9637588d..000000000 --- a/book/src/main/java/me/ag2s/epublib/domain/Relator.java +++ /dev/null @@ -1,1144 +0,0 @@ -package me.ag2s.epublib.domain; - - -/** - * A relator denotes which role a certain individual had in the creation/modification of the ebook. - * - * Examples are 'creator', 'blurb writer', etc. - * - * This is contains the complete Library of Concress relator list. - * - * @see MARC Code List for Relators - * - * @author paul - */ -public enum Relator { - - /** - * Use for a person or organization who principally exhibits acting skills in a musical or dramatic presentation or entertainment. - */ - ACTOR("act", "Actor"), - - /** - * Use for a person or organization who 1) reworks a musical composition, usually for a different medium, or 2) rewrites novels or stories for motion pictures or other audiovisual medium. - */ - ADAPTER("adp", "Adapter"), - - /** - * Use for a person or organization that reviews, examines and interprets data or information in a specific area. - */ - ANALYST("anl", "Analyst"), - - /** - * Use for a person or organization who draws the two-dimensional figures, manipulates the three dimensional objects and/or also programs the computer to move objects and images for the purpose of animated film processing. Animation cameras, stands, celluloid screens, transparencies and inks are some of the tools of the animator. - */ - ANIMATOR("anm", "Animator"), - - /** - * Use for a person who writes manuscript annotations on a printed item. - */ - ANNOTATOR("ann", "Annotator"), - - /** - * Use for a person or organization responsible for the submission of an application or who is named as eligible for the results of the processing of the application (e.g., bestowing of rights, reward, title, position). - */ - APPLICANT("app", "Applicant"), - - /** - * Use for a person or organization who designs structures or oversees their construction. - */ - ARCHITECT("arc", "Architect"), - - /** - * Use for a person or organization who transcribes a musical composition, usually for a different medium from that of the original; in an arrangement the musical substance remains essentially unchanged. - */ - ARRANGER("arr", "Arranger"), - - /** - * Use for a person (e.g., a painter or sculptor) who makes copies of works of visual art. - */ - ART_COPYIST("acp", "Art copyist"), - - /** - * Use for a person (e.g., a painter) or organization who conceives, and perhaps also implements, an original graphic design or work of art, if specific codes (e.g., [egr], [etr]) are not desired. For book illustrators, prefer Illustrator [ill]. - */ - ARTIST("art", "Artist"), - - /** - * Use for a person responsible for controlling the development of the artistic style of an entire production, including the choice of works to be presented and selection of senior production staff. - */ - ARTISTIC_DIRECTOR("ard", "Artistic director"), - - /** - * Use for a person or organization to whom a license for printing or publishing has been transferred. - */ - ASSIGNEE("asg", "Assignee"), - - /** - * Use for a person or organization associated with or found in an item or collection, which cannot be determined to be that of a Former owner [fmo] or other designated relator indicative of provenance. - */ - ASSOCIATED_NAME("asn", "Associated name"), - - /** - * Use for an author, artist, etc., relating him/her to a work for which there is or once was substantial authority for designating that person as author, creator, etc. of the work. - */ - ATTRIBUTED_NAME("att", "Attributed name"), - - /** - * Use for a person or organization in charge of the estimation and public auctioning of goods, particularly books, artistic works, etc. - */ - AUCTIONEER("auc", "Auctioneer"), - - /** - * Use for a person or organization chiefly responsible for the intellectual or artistic content of a work, usually printed text. This term may also be used when more than one person or body bears such responsibility. - */ - AUTHOR("aut", "Author"), - - /** - * Use for a person or organization whose work is largely quoted or extracted in works to which he or she did not contribute directly. Such quotations are found particularly in exhibition catalogs, collections of photographs, etc. - */ - AUTHOR_IN_QUOTATIONS_OR_TEXT_EXTRACTS("aqt", - "Author in quotations or text extracts"), - - /** - * Use for a person or organization responsible for an afterword, postface, colophon, etc. but who is not the chief author of a work. - */ - AUTHOR_OF_AFTERWORD_COLOPHON_ETC("aft", - "Author of afterword, colophon, etc."), - - /** - * Use for a person or organization responsible for the dialog or spoken commentary for a screenplay or sound recording. - */ - AUTHOR_OF_DIALOG("aud", "Author of dialog"), - - /** - * Use for a person or organization responsible for an introduction, preface, foreword, or other critical introductory matter, but who is not the chief author. - */ - AUTHOR_OF_INTRODUCTION_ETC("aui", "Author of introduction, etc."), - - /** - * Use for a person or organization responsible for a motion picture screenplay, dialog, spoken commentary, etc. - */ - AUTHOR_OF_SCREENPLAY_ETC("aus", "Author of screenplay, etc."), - - /** - * Use for a person or organization responsible for a work upon which the work represented by the catalog record is based. This may be appropriate for adaptations, sequels, continuations, indexes, etc. - */ - BIBLIOGRAPHIC_ANTECEDENT("ant", "Bibliographic antecedent"), - - /** - * Use for a person or organization responsible for the binding of printed or manuscript materials. - */ - BINDER("bnd", "Binder"), - - /** - * Use for a person or organization responsible for the binding design of a book, including the type of binding, the type of materials used, and any decorative aspects of the binding. - */ - BINDING_DESIGNER("bdd", "Binding designer"), - - /** - * Use for the named entity responsible for writing a commendation or testimonial for a work, which appears on or within the publication itself, frequently on the back or dust jacket of print publications or on advertising material for all media. - */ - BLURB_WRITER("blw", "Blurb writer"), - - /** - * Use for a person or organization responsible for the entire graphic design of a book, including arrangement of type and illustration, choice of materials, and process used. - */ - BOOK_DESIGNER("bkd", "Book designer"), - - /** - * Use for a person or organization responsible for the production of books and other print media, if specific codes (e.g., [bkd], [egr], [tyd], [prt]) are not desired. - */ - BOOK_PRODUCER("bkp", "Book producer"), - - /** - * Use for a person or organization responsible for the design of flexible covers designed for or published with a book, including the type of materials used, and any decorative aspects of the bookjacket. - */ - BOOKJACKET_DESIGNER("bjd", "Bookjacket designer"), - - /** - * Use for a person or organization responsible for the design of a book owner's identification label that is most commonly pasted to the inside front cover of a book. - */ - BOOKPLATE_DESIGNER("bpd", "Bookplate designer"), - - /** - * Use for a person or organization who makes books and other bibliographic materials available for purchase. Interest in the materials is primarily lucrative. - */ - BOOKSELLER("bsl", "Bookseller"), - - /** - * Use for a person or organization who writes in an artistic hand, usually as a copyist and or engrosser. - */ - CALLIGRAPHER("cll", "Calligrapher"), - - /** - * Use for a person or organization responsible for the creation of maps and other cartographic materials. - */ - CARTOGRAPHER("ctg", "Cartographer"), - - /** - * Use for a censor, bowdlerizer, expurgator, etc., official or private. - */ - CENSOR("cns", "Censor"), - - /** - * Use for a person or organization who composes or arranges dances or other movements (e.g., "master of swords") for a musical or dramatic presentation or entertainment. - */ - CHOREOGRAPHER("chr", "Choreographer"), - - /** - * Use for a person or organization who is in charge of the images captured for a motion picture film. The cinematographer works under the supervision of a director, and may also be referred to as director of photography. Do not confuse with videographer. - */ - CINEMATOGRAPHER("cng", "Cinematographer"), - - /** - * Use for a person or organization for whom another person or organization is acting. - */ - CLIENT("cli", "Client"), - - /** - * Use for a person or organization that takes a limited part in the elaboration of a work of another person or organization that brings complements (e.g., appendices, notes) to the work. - */ - COLLABORATOR("clb", "Collaborator"), - - /** - * Use for a person or organization who has brought together material from various sources that has been arranged, described, and cataloged as a collection. A collector is neither the creator of the material nor a person to whom manuscripts in the collection may have been addressed. - */ - COLLECTOR("col", "Collector"), - - /** - * Use for a person or organization responsible for the production of photographic prints from film or other colloid that has ink-receptive and ink-repellent surfaces. - */ - COLLOTYPER("clt", "Collotyper"), - - /** - * Use for the named entity responsible for applying color to drawings, prints, photographs, maps, moving images, etc. - */ - COLORIST("clr", "Colorist"), - - /** - * Use for a person or organization who provides interpretation, analysis, or a discussion of the subject matter on a recording, motion picture, or other audiovisual medium. - */ - COMMENTATOR("cmm", "Commentator"), - - /** - * Use for a person or organization responsible for the commentary or explanatory notes about a text. For the writer of manuscript annotations in a printed book, use Annotator [ann]. - */ - COMMENTATOR_FOR_WRITTEN_TEXT("cwt", "Commentator for written text"), - - /** - * Use for a person or organization who produces a work or publication by selecting and putting together material from the works of various persons or bodies. - */ - COMPILER("com", "Compiler"), - - /** - * Use for the party who applies to the courts for redress, usually in an equity proceeding. - */ - COMPLAINANT("cpl", "Complainant"), - - /** - * Use for a complainant who takes an appeal from one court or jurisdiction to another to reverse the judgment, usually in an equity proceeding. - */ - COMPLAINANT_APPELLANT("cpt", "Complainant-appellant"), - - /** - * Use for a complainant against whom an appeal is taken from one court or jurisdiction to another to reverse the judgment, usually in an equity proceeding. - */ - COMPLAINANT_APPELLEE("cpe", "Complainant-appellee"), - - /** - * Use for a person or organization who creates a musical work, usually a piece of music in manuscript or printed form. - */ - COMPOSER("cmp", "Composer"), - - /** - * Use for a person or organization responsible for the creation of metal slug, or molds made of other materials, used to produce the text and images in printed matter. - */ - COMPOSITOR("cmt", "Compositor"), - - /** - * Use for a person or organization responsible for the original idea on which a work is based, this includes the scientific author of an audio-visual item and the conceptor of an advertisement. - */ - CONCEPTOR("ccp", "Conceptor"), - - /** - * Use for a person who directs a performing group (orchestra, chorus, opera, etc.) in a musical or dramatic presentation or entertainment. - */ - CONDUCTOR("cnd", "Conductor"), - - /** - * Use for the named entity responsible for documenting, preserving, or treating printed or manuscript material, works of art, artifacts, or other media. - */ - CONSERVATOR("con", "Conservator"), - - /** - * Use for a person or organization relevant to a resource, who is called upon for professional advice or services in a specialized field of knowledge or training. - */ - CONSULTANT("csl", "Consultant"), - - /** - * Use for a person or organization relevant to a resource, who is engaged specifically to provide an intellectual overview of a strategic or operational task and by analysis, specification, or instruction, to create or propose a cost-effective course of action or solution. - */ - CONSULTANT_TO_A_PROJECT("csp", "Consultant to a project"), - - /** - * Use for the party who opposes, resists, or disputes, in a court of law, a claim, decision, result, etc. - */ - CONTESTANT("cos", "Contestant"), - - /** - * Use for a contestant who takes an appeal from one court of law or jurisdiction to another to reverse the judgment. - */ - CONTESTANT_APPELLANT("cot", "Contestant-appellant"), - - /** - * Use for a contestant against whom an appeal is taken from one court of law or jurisdiction to another to reverse the judgment. - */ - CONTESTANT_APPELLEE("coe", "Contestant-appellee"), - - /** - * Use for the party defending a claim, decision, result, etc. being opposed, resisted, or disputed in a court of law. - */ - CONTESTEE("cts", "Contestee"), - - /** - * Use for a contestee who takes an appeal from one court or jurisdiction to another to reverse the judgment. - */ - CONTESTEE_APPELLANT("ctt", "Contestee-appellant"), - - /** - * Use for a contestee against whom an appeal is taken from one court or jurisdiction to another to reverse the judgment. - */ - CONTESTEE_APPELLEE("cte", "Contestee-appellee"), - - /** - * Use for a person or organization relevant to a resource, who enters into a contract with another person or organization to perform a specific task. - */ - CONTRACTOR("ctr", "Contractor"), - - /** - * Use for a person or organization one whose work has been contributed to a larger work, such as an anthology, serial publication, or other compilation of individual works. Do not use if the sole function in relation to a work is as author, editor, compiler or translator. - */ - CONTRIBUTOR("ctb", "Contributor"), - - /** - * Use for a person or organization listed as a copyright owner at the time of registration. Copyright can be granted or later transferred to another person or organization, at which time the claimant becomes the copyright holder. - */ - COPYRIGHT_CLAIMANT("cpc", "Copyright claimant"), - - /** - * Use for a person or organization to whom copy and legal rights have been granted or transferred for the intellectual content of a work. The copyright holder, although not necessarily the creator of the work, usually has the exclusive right to benefit financially from the sale and use of the work to which the associated copyright protection applies. - */ - COPYRIGHT_HOLDER("cph", "Copyright holder"), - - /** - * Use for a person or organization who is a corrector of manuscripts, such as the scriptorium official who corrected the work of a scribe. For printed matter, use Proofreader. - */ - CORRECTOR("crr", "Corrector"), - - /** - * Use for a person or organization who was either the writer or recipient of a letter or other communication. - */ - CORRESPONDENT("crp", "Correspondent"), - - /** - * Use for a person or organization who designs or makes costumes, fixes hair, etc., for a musical or dramatic presentation or entertainment. - */ - COSTUME_DESIGNER("cst", "Costume designer"), - - /** - * Use for a person or organization responsible for the graphic design of a book cover, album cover, slipcase, box, container, etc. For a person or organization responsible for the graphic design of an entire book, use Book designer; for book jackets, use Bookjacket designer. - */ - COVER_DESIGNER("cov", "Cover designer"), - - /** - * Use for a person or organization responsible for the intellectual or artistic content of a work. - */ - CREATOR("cre", "Creator"), - - /** - * Use for a person or organization responsible for conceiving and organizing an exhibition. - */ - CURATOR_OF_AN_EXHIBITION("cur", "Curator of an exhibition"), - - /** - * Use for a person or organization who principally exhibits dancing skills in a musical or dramatic presentation or entertainment. - */ - DANCER("dnc", "Dancer"), - - /** - * Use for a person or organization that submits data for inclusion in a database or other collection of data. - */ - DATA_CONTRIBUTOR("dtc", "Data contributor"), - - /** - * Use for a person or organization responsible for managing databases or other data sources. - */ - DATA_MANAGER("dtm", "Data manager"), - - /** - * Use for a person or organization to whom a book, manuscript, etc., is dedicated (not the recipient of a gift). - */ - DEDICATEE("dte", "Dedicatee"), - - /** - * Use for the author of a dedication, which may be a formal statement or in epistolary or verse form. - */ - DEDICATOR("dto", "Dedicator"), - - /** - * Use for the party defending or denying allegations made in a suit and against whom relief or recovery is sought in the courts, usually in a legal action. - */ - DEFENDANT("dfd", "Defendant"), - - /** - * Use for a defendant who takes an appeal from one court or jurisdiction to another to reverse the judgment, usually in a legal action. - */ - DEFENDANT_APPELLANT("dft", "Defendant-appellant"), - - /** - * Use for a defendant against whom an appeal is taken from one court or jurisdiction to another to reverse the judgment, usually in a legal action. - */ - DEFENDANT_APPELLEE("dfe", "Defendant-appellee"), - - /** - * Use for the organization granting a degree for which the thesis or dissertation described was presented. - */ - DEGREE_GRANTOR("dgg", "Degree grantor"), - - /** - * Use for a person or organization executing technical drawings from others' designs. - */ - DELINEATOR("dln", "Delineator"), - - /** - * Use for an entity depicted or portrayed in a work, particularly in a work of art. - */ - DEPICTED("dpc", "Depicted"), - - /** - * Use for a person or organization placing material in the physical custody of a library or repository without transferring the legal title. - */ - DEPOSITOR("dpt", "Depositor"), - - /** - * Use for a person or organization responsible for the design if more specific codes (e.g., [bkd], [tyd]) are not desired. - */ - DESIGNER("dsr", "Designer"), - - /** - * Use for a person or organization who is responsible for the general management of a work or who supervises the production of a performance for stage, screen, or sound recording. - */ - DIRECTOR("drt", "Director"), - - /** - * Use for a person who presents a thesis for a university or higher-level educational degree. - */ - DISSERTANT("dis", "Dissertant"), - - /** - * Use for the name of a place from which a resource, e.g., a serial, is distributed. - */ - DISTRIBUTION_PLACE("dbp", "Distribution place"), - - /** - * Use for a person or organization that has exclusive or shared marketing rights for an item. - */ - DISTRIBUTOR("dst", "Distributor"), - - /** - * Use for a person or organization who is the donor of a book, manuscript, etc., to its present owner. Donors to previous owners are designated as Former owner [fmo] or Inscriber [ins]. - */ - DONOR("dnr", "Donor"), - - /** - * Use for a person or organization who prepares artistic or technical drawings. - */ - DRAFTSMAN("drm", "Draftsman"), - - /** - * Use for a person or organization to which authorship has been dubiously or incorrectly ascribed. - */ - DUBIOUS_AUTHOR("dub", "Dubious author"), - - /** - * Use for a person or organization who prepares for publication a work not primarily his/her own, such as by elucidating text, adding introductory or other critical matter, or technically directing an editorial staff. - */ - EDITOR("edt", "Editor"), - - /** - * Use for a person responsible for setting up a lighting rig and focusing the lights for a production, and running the lighting at a performance. - */ - ELECTRICIAN("elg", "Electrician"), - - /** - * Use for a person or organization who creates a duplicate printing surface by pressure molding and electrodepositing of metal that is then backed up with lead for printing. - */ - ELECTROTYPER("elt", "Electrotyper"), - - /** - * Use for a person or organization that is responsible for technical planning and design, particularly with construction. - */ - ENGINEER("eng", "Engineer"), - - /** - * Use for a person or organization who cuts letters, figures, etc. on a surface, such as a wooden or metal plate, for printing. - */ - ENGRAVER("egr", "Engraver"), - - /** - * Use for a person or organization who produces text or images for printing by subjecting metal, glass, or some other surface to acid or the corrosive action of some other substance. - */ - ETCHER("etr", "Etcher"), - - /** - * Use for the name of the place where an event such as a conference or a concert took place. - */ - EVENT_PLACE("evp", "Event place"), - - /** - * Use for a person or organization in charge of the description and appraisal of the value of goods, particularly rare items, works of art, etc. - */ - EXPERT("exp", "Expert"), - - /** - * Use for a person or organization that executed the facsimile. - */ - FACSIMILIST("fac", "Facsimilist"), - - /** - * Use for a person or organization that manages or supervises the work done to collect raw data or do research in an actual setting or environment (typically applies to the natural and social sciences). - */ - FIELD_DIRECTOR("fld", "Field director"), - - /** - * Use for a person or organization who is an editor of a motion picture film. This term is used regardless of the medium upon which the motion picture is produced or manufactured (e.g., acetate film, video tape). - */ - FILM_EDITOR("flm", "Film editor"), - - /** - * Use for a person or organization who is identified as the only party or the party of the first part. In the case of transfer of right, this is the assignor, transferor, licensor, grantor, etc. Multiple parties can be named jointly as the first party - */ - FIRST_PARTY("fpy", "First party"), - - /** - * Use for a person or organization who makes or imitates something of value or importance, especially with the intent to defraud. - */ - FORGER("frg", "Forger"), - - /** - * Use for a person or organization who owned an item at any time in the past. Includes those to whom the material was once presented. A person or organization giving the item to the present owner is designated as Donor [dnr] - */ - FORMER_OWNER("fmo", "Former owner"), - - /** - * Use for a person or organization that furnished financial support for the production of the work. - */ - FUNDER("fnd", "Funder"), - - /** - * Use for a person responsible for geographic information system (GIS) development and integration with global positioning system data. - */ - GEOGRAPHIC_INFORMATION_SPECIALIST("gis", "Geographic information specialist"), - - /** - * Use for a person or organization in memory or honor of whom a book, manuscript, etc. is donated. - */ - HONOREE("hnr", "Honoree"), - - /** - * Use for a person who is invited or regularly leads a program (often broadcast) that includes other guests, performers, etc. (e.g., talk show host). - */ - HOST("hst", "Host"), - - /** - * Use for a person or organization responsible for the decoration of a work (especially manuscript material) with precious metals or color, usually with elaborate designs and motifs. - */ - ILLUMINATOR("ilu", "Illuminator"), - - /** - * Use for a person or organization who conceives, and perhaps also implements, a design or illustration, usually to accompany a written text. - */ - ILLUSTRATOR("ill", "Illustrator"), - - /** - * Use for a person who signs a presentation statement. - */ - INSCRIBER("ins", "Inscriber"), - - /** - * Use for a person or organization who principally plays an instrument in a musical or dramatic presentation or entertainment. - */ - INSTRUMENTALIST("itr", "Instrumentalist"), - - /** - * Use for a person or organization who is interviewed at a consultation or meeting, usually by a reporter, pollster, or some other information gathering agent. - */ - INTERVIEWEE("ive", "Interviewee"), - - /** - * Use for a person or organization who acts as a reporter, pollster, or other information gathering agent in a consultation or meeting involving one or more individuals. - */ - INTERVIEWER("ivr", "Interviewer"), - - /** - * Use for a person or organization who first produces a particular useful item, or develops a new process for obtaining a known item or result. - */ - INVENTOR("inv", "Inventor"), - - /** - * Use for an institution that provides scientific analyses of material samples. - */ - LABORATORY("lbr", "Laboratory"), - - /** - * Use for a person or organization that manages or supervises work done in a controlled setting or environment. - */ - LABORATORY_DIRECTOR("ldr", "Laboratory director"), - - /** - * Use for a person or organization whose work involves coordinating the arrangement of existing and proposed land features and structures. - */ - LANDSCAPE_ARCHITECT("lsa", "Landscape architect"), - - /** - * Use to indicate that a person or organization takes primary responsibility for a particular activity or endeavor. Use with another relator term or code to show the greater importance this person or organization has regarding that particular role. If more than one relator is assigned to a heading, use the Lead relator only if it applies to all the relators. - */ - LEAD("led", "Lead"), - - /** - * Use for a person or organization permitting the temporary use of a book, manuscript, etc., such as for photocopying or microfilming. - */ - LENDER("len", "Lender"), - - /** - * Use for the party who files a libel in an ecclesiastical or admiralty case. - */ - LIBELANT("lil", "Libelant"), - - /** - * Use for a libelant who takes an appeal from one ecclesiastical court or admiralty to another to reverse the judgment. - */ - LIBELANT_APPELLANT("lit", "Libelant-appellant"), - - /** - * Use for a libelant against whom an appeal is taken from one ecclesiastical court or admiralty to another to reverse the judgment. - */ - LIBELANT_APPELLEE("lie", "Libelant-appellee"), - - /** - * Use for a party against whom a libel has been filed in an ecclesiastical court or admiralty. - */ - LIBELEE("lel", "Libelee"), - - /** - * Use for a libelee who takes an appeal from one ecclesiastical court or admiralty to another to reverse the judgment. - */ - LIBELEE_APPELLANT("let", "Libelee-appellant"), - - /** - * Use for a libelee against whom an appeal is taken from one ecclesiastical court or admiralty to another to reverse the judgment. - */ - LIBELEE_APPELLEE("lee", "Libelee-appellee"), - - /** - * Use for a person or organization who is a writer of the text of an opera, oratorio, etc. - */ - LIBRETTIST("lbt", "Librettist"), - - /** - * Use for a person or organization who is an original recipient of the right to print or publish. - */ - LICENSEE("lse", "Licensee"), - - /** - * Use for person or organization who is a signer of the license, imprimatur, etc. - */ - LICENSOR("lso", "Licensor"), - - /** - * Use for a person or organization who designs the lighting scheme for a theatrical presentation, entertainment, motion picture, etc. - */ - LIGHTING_DESIGNER("lgd", "Lighting designer"), - - /** - * Use for a person or organization who prepares the stone or plate for lithographic printing, including a graphic artist creating a design directly on the surface from which printing will be done. - */ - LITHOGRAPHER("ltg", "Lithographer"), - - /** - * Use for a person or organization who is a writer of the text of a song. - */ - LYRICIST("lyr", "Lyricist"), - - /** - * Use for a person or organization that makes an artifactual work (an object made or modified by one or more persons). Examples of artifactual works include vases, cannons or pieces of furniture. - */ - MANUFACTURER("mfr", "Manufacturer"), - - /** - * Use for the named entity responsible for marbling paper, cloth, leather, etc. used in construction of a resource. - */ - MARBLER("mrb", "Marbler"), - - /** - * Use for a person or organization performing the coding of SGML, HTML, or XML markup of metadata, text, etc. - */ - MARKUP_EDITOR("mrk", "Markup editor"), - - /** - * Use for a person or organization primarily responsible for compiling and maintaining the original description of a metadata set (e.g., geospatial metadata set). - */ - METADATA_CONTACT("mdc", "Metadata contact"), - - /** - * Use for a person or organization responsible for decorations, illustrations, letters, etc. cut on a metal surface for printing or decoration. - */ - METAL_ENGRAVER("mte", "Metal-engraver"), - - /** - * Use for a person who leads a program (often broadcast) where topics are discussed, usually with participation of experts in fields related to the discussion. - */ - MODERATOR("mod", "Moderator"), - - /** - * Use for a person or organization that supervises compliance with the contract and is responsible for the report and controls its distribution. Sometimes referred to as the grantee, or controlling agency. - */ - MONITOR("mon", "Monitor"), - - /** - * Use for a person who transcribes or copies musical notation - */ - MUSIC_COPYIST("mcp", "Music copyist"), - - /** - * Use for a person responsible for basic music decisions about a production, including coordinating the work of the composer, the sound editor, and sound mixers, selecting musicians, and organizing and/or conducting sound for rehearsals and performances. - */ - MUSICAL_DIRECTOR("msd", "Musical director"), - - /** - * Use for a person or organization who performs music or contributes to the musical content of a work when it is not possible or desirable to identify the function more precisely. - */ - MUSICIAN("mus", "Musician"), - - /** - * Use for a person who is a speaker relating the particulars of an act, occurrence, or course of events. - */ - NARRATOR("nrt", "Narrator"), - - /** - * Use for a person or organization responsible for opposing a thesis or dissertation. - */ - OPPONENT("opn", "Opponent"), - - /** - * Use for a person or organization responsible for organizing a meeting for which an item is the report or proceedings. - */ - ORGANIZER_OF_MEETING("orm", "Organizer of meeting"), - - /** - * Use for a person or organization performing the work, i.e., the name of a person or organization associated with the intellectual content of the work. This category does not include the publisher or personal affiliation, or sponsor except where it is also the corporate author. - */ - ORIGINATOR("org", "Originator"), - - /** - * Use for relator codes from other lists which have no equivalent in the MARC list or for terms which have not been assigned a code. - */ - OTHER("oth", "Other"), - - /** - * Use for a person or organization that currently owns an item or collection. - */ - OWNER("own", "Owner"), - - /** - * Use for a person or organization responsible for the production of paper, usually from wood, cloth, or other fibrous material. - */ - PAPERMAKER("ppm", "Papermaker"), - - /** - * Use for a person or organization that applied for a patent. - */ - PATENT_APPLICANT("pta", "Patent applicant"), - - /** - * Use for a person or organization that was granted the patent referred to by the item. - */ - PATENT_HOLDER("pth", "Patent holder"), - - /** - * Use for a person or organization responsible for commissioning a work. Usually a patron uses his or her means or influence to support the work of artists, writers, etc. This includes those who commission and pay for individual works. - */ - PATRON("pat", "Patron"), - - /** - * Use for a person or organization who exhibits musical or acting skills in a musical or dramatic presentation or entertainment, if specific codes for those functions ([act], [dnc], [itr], [voc], etc.) are not used. If specific codes are used, [prf] is used for a person whose principal skill is not known or specified. - */ - PERFORMER("prf", "Performer"), - - /** - * Use for an authority (usually a government agency) that issues permits under which work is accomplished. - */ - PERMITTING_AGENCY("pma", "Permitting agency"), - - /** - * Use for a person or organization responsible for taking photographs, whether they are used in their original form or as reproductions. - */ - PHOTOGRAPHER("pht", "Photographer"), - - /** - * Use for the party who complains or sues in court in a personal action, usually in a legal proceeding. - */ - PLAINTIFF("ptf", "Plaintiff"), - - /** - * Use for a plaintiff who takes an appeal from one court or jurisdiction to another to reverse the judgment, usually in a legal proceeding. - */ - PLAINTIFF_APPELLANT("ptt", "Plaintiff-appellant"), - - /** - * Use for a plaintiff against whom an appeal is taken from one court or jurisdiction to another to reverse the judgment, usually in a legal proceeding. - */ - PLAINTIFF_APPELLEE("pte", "Plaintiff-appellee"), - - /** - * Use for a person or organization responsible for the production of plates, usually for the production of printed images and/or text. - */ - PLATEMAKER("plt", "Platemaker"), - - /** - * Use for a person or organization who prints texts, whether from type or plates. - */ - PRINTER("prt", "Printer"), - - /** - * Use for a person or organization who prints illustrations from plates. - */ - PRINTER_OF_PLATES("pop", "Printer of plates"), - - /** - * Use for a person or organization who makes a relief, intaglio, or planographic printing surface. - */ - PRINTMAKER("prm", "Printmaker"), - - /** - * Use for a person or organization primarily responsible for performing or initiating a process, such as is done with the collection of metadata sets. - */ - PROCESS_CONTACT("prc", "Process contact"), - - /** - * Use for a person or organization responsible for the making of a motion picture, including business aspects, management of the productions, and the commercial success of the work. - */ - PRODUCER("pro", "Producer"), - - /** - * Use for a person responsible for all technical and business matters in a production. - */ - PRODUCTION_MANAGER("pmn", "Production manager"), - - /** - * Use for a person or organization associated with the production (props, lighting, special effects, etc.) of a musical or dramatic presentation or entertainment. - */ - PRODUCTION_PERSONNEL("prd", "Production personnel"), - - /** - * Use for a person or organization responsible for the creation and/or maintenance of computer program design documents, source code, and machine-executable digital files and supporting documentation. - */ - PROGRAMMER("prg", "Programmer"), - - /** - * Use for a person or organization with primary responsibility for all essential aspects of a project, or that manages a very large project that demands senior level responsibility, or that has overall responsibility for managing projects, or provides overall direction to a project manager. - */ - PROJECT_DIRECTOR("pdr", "Project director"), - - /** - * Use for a person who corrects printed matter. For manuscripts, use Corrector [crr]. - */ - PROOFREADER("pfr", "Proofreader"), - - /** - * Use for the name of the place where a resource is published. - */ - PUBLICATION_PLACE("pup", "Publication place"), - - /** - * Use for a person or organization that makes printed matter, often text, but also printed music, artwork, etc. available to the public. - */ - PUBLISHER("pbl", "Publisher"), - - /** - * Use for a person or organization who presides over the elaboration of a collective work to ensure its coherence or continuity. This includes editors-in-chief, literary editors, editors of series, etc. - */ - PUBLISHING_DIRECTOR("pbd", "Publishing director"), - - /** - * Use for a person or organization who manipulates, controls, or directs puppets or marionettes in a musical or dramatic presentation or entertainment. - */ - PUPPETEER("ppt", "Puppeteer"), - - /** - * Use for a person or organization to whom correspondence is addressed. - */ - RECIPIENT("rcp", "Recipient"), - - /** - * Use for a person or organization who supervises the technical aspects of a sound or video recording session. - */ - RECORDING_ENGINEER("rce", "Recording engineer"), - - /** - * Use for a person or organization who writes or develops the framework for an item without being intellectually responsible for its content. - */ - REDACTOR("red", "Redactor"), - - /** - * Use for a person or organization who prepares drawings of architectural designs (i.e., renderings) in accurate, representational perspective to show what the project will look like when completed. - */ - RENDERER("ren", "Renderer"), - - /** - * Use for a person or organization who writes or presents reports of news or current events on air or in print. - */ - REPORTER("rpt", "Reporter"), - - /** - * Use for an agency that hosts data or material culture objects and provides services to promote long term, consistent and shared use of those data or objects. - */ - REPOSITORY("rps", "Repository"), - - /** - * Use for a person who directed or managed a research project. - */ - RESEARCH_TEAM_HEAD("rth", "Research team head"), - - /** - * Use for a person who participated in a research project but whose role did not involve direction or management of it. - */ - RESEARCH_TEAM_MEMBER("rtm", "Research team member"), - - /** - * Use for a person or organization responsible for performing research. - */ - RESEARCHER("res", "Researcher"), - - /** - * Use for the party who makes an answer to the courts pursuant to an application for redress, usually in an equity proceeding. - */ - RESPONDENT("rsp", "Respondent"), - - /** - * Use for a respondent who takes an appeal from one court or jurisdiction to another to reverse the judgment, usually in an equity proceeding. - */ - RESPONDENT_APPELLANT("rst", "Respondent-appellant"), - - /** - * Use for a respondent against whom an appeal is taken from one court or jurisdiction to another to reverse the judgment, usually in an equity proceeding. - */ - RESPONDENT_APPELLEE("rse", "Respondent-appellee"), - - /** - * Use for a person or organization legally responsible for the content of the published material. - */ - RESPONSIBLE_PARTY("rpy", "Responsible party"), - - /** - * Use for a person or organization, other than the original choreographer or director, responsible for restaging a choreographic or dramatic work and who contributes minimal new content. - */ - RESTAGER("rsg", "Restager"), - - /** - * Use for a person or organization responsible for the review of a book, motion picture, performance, etc. - */ - REVIEWER("rev", "Reviewer"), - - /** - * Use for a person or organization responsible for parts of a work, often headings or opening parts of a manuscript, that appear in a distinctive color, usually red. - */ - RUBRICATOR("rbr", "Rubricator"), - - /** - * Use for a person or organization who is the author of a motion picture screenplay. - */ - SCENARIST("sce", "Scenarist"), - - /** - * Use for a person or organization who brings scientific, pedagogical, or historical competence to the conception and realization on a work, particularly in the case of audio-visual items. - */ - SCIENTIFIC_ADVISOR("sad", "Scientific advisor"), - - /** - * Use for a person who is an amanuensis and for a writer of manuscripts proper. For a person who makes pen-facsimiles, use Facsimilist [fac]. - */ - SCRIBE("scr", "Scribe"), - - /** - * Use for a person or organization who models or carves figures that are three-dimensional representations. - */ - SCULPTOR("scl", "Sculptor"), - - /** - * Use for a person or organization who is identified as the party of the second part. In the case of transfer of right, this is the assignee, transferee, licensee, grantee, etc. Multiple parties can be named jointly as the second party. - */ - SECOND_PARTY("spy", "Second party"), - - /** - * Use for a person or organization who is a recorder, redactor, or other person responsible for expressing the views of a organization. - */ - SECRETARY("sec", "Secretary"), - - /** - * Use for a person or organization who translates the rough sketches of the art director into actual architectural structures for a theatrical presentation, entertainment, motion picture, etc. Set designers draw the detailed guides and specifications for building the set. - */ - SET_DESIGNER("std", "Set designer"), - - /** - * Use for a person whose signature appears without a presentation or other statement indicative of provenance. When there is a presentation statement, use Inscriber [ins]. - */ - SIGNER("sgn", "Signer"), - - /** - * Use for a person or organization who uses his/her/their voice with or without instrumental accompaniment to produce music. A performance may or may not include actual words. - */ - SINGER("sng", "Singer"), - - /** - * Use for a person who produces and reproduces the sound score (both live and recorded), the installation of microphones, the setting of sound levels, and the coordination of sources of sound for a production. - */ - SOUND_DESIGNER("sds", "Sound designer"), - - /** - * Use for a person who participates in a program (often broadcast) and makes a formalized contribution or presentation generally prepared in advance. - */ - SPEAKER("spk", "Speaker"), - - /** - * Use for a person or organization that issued a contract or under the auspices of which a work has been written, printed, published, etc. - */ - SPONSOR("spn", "Sponsor"), - - /** - * Use for a person who is in charge of everything that occurs on a performance stage, and who acts as chief of all crews and assistant to a director during rehearsals. - */ - STAGE_MANAGER("stm", "Stage manager"), - - /** - * Use for an organization responsible for the development or enforcement of a standard. - */ - STANDARDS_BODY("stn", "Standards body"), - - /** - * Use for a person or organization who creates a new plate for printing by molding or copying another printing surface. - */ - STEREOTYPER("str", "Stereotyper"), - - /** - * Use for a person relaying a story with creative and/or theatrical interpretation. - */ - STORYTELLER("stl", "Storyteller"), - - /** - * Use for a person or organization that supports (by allocating facilities, staff, or other resources) a project, program, meeting, event, data objects, material culture objects, or other entities capable of support. - */ - SUPPORTING_HOST("sht", "Supporting host"), - - /** - * Use for a person or organization who does measurements of tracts of land, etc. to determine location, forms, and boundaries. - */ - SURVEYOR("srv", "Surveyor"), - - /** - * Use for a person who, in the context of a resource, gives instruction in an intellectual subject or demonstrates while teaching physical skills. - */ - TEACHER("tch", "Teacher"), - - /** - * Use for a person who is ultimately in charge of scenery, props, lights and sound for a production. - */ - TECHNICAL_DIRECTOR("tcd", "Technical director"), - - /** - * Use for a person under whose supervision a degree candidate develops and presents a thesis, mémoire, or text of a dissertation. - */ - THESIS_ADVISOR("ths", "Thesis advisor"), - - /** - * Use for a person who prepares a handwritten or typewritten copy from original material, including from dictated or orally recorded material. For makers of pen-facsimiles, use Facsimilist [fac]. - */ - TRANSCRIBER("trc", "Transcriber"), - - /** - * Use for a person or organization who renders a text from one language into another, or from an older form of a language into the modern form. - */ - TRANSLATOR("trl", "Translator"), - - /** - * Use for a person or organization who designed the type face used in a particular item. - */ - TYPE_DESIGNER("tyd", "Type designer"), - - /** - * Use for a person or organization primarily responsible for choice and arrangement of type used in an item. If the typographer is also responsible for other aspects of the graphic design of a book (e.g., Book designer [bkd]), codes for both functions may be needed. - */ - TYPOGRAPHER("tyg", "Typographer"), - - /** - * Use for the name of a place where a university that is associated with a resource is located, for example, a university where an academic dissertation or thesis was presented. - */ - UNIVERSITY_PLACE("uvp", "University place"), - - /** - * Use for a person or organization in charge of a video production, e.g. the video recording of a stage production as opposed to a commercial motion picture. The videographer may be the camera operator or may supervise one or more camera operators. Do not confuse with cinematographer. - */ - VIDEOGRAPHER("vdg", "Videographer"), - - /** - * Use for a person or organization who principally exhibits singing skills in a musical or dramatic presentation or entertainment. - */ - VOCALIST("voc", "Vocalist"), - - /** - * Use for a person who verifies the truthfulness of an event or action. - */ - WITNESS("wit", "Witness"), - - /** - * Use for a person or organization who makes prints by cutting the image in relief on the end-grain of a wood block. - */ - WOOD_ENGRAVER("wde", "Wood-engraver"), - - /** - * Use for a person or organization who makes prints by cutting the image in relief on the plank side of a wood block. - */ - WOODCUTTER("wdc", "Woodcutter"), - - /** - * Use for a person or organization who writes significant material which accompanies a sound recording or other audiovisual material. - */ - WRITER_OF_ACCOMPANYING_MATERIAL("wam", "Writer of accompanying material"); - - private final String code; - private final String name; - - Relator(String code, String name) { - this.code = code; - this.name = name; - } - - public String getCode() { - return code; - } - - public String getName() { - return name; - } - - public static Relator byCode(String code) { - for (Relator relator : Relator.values()) { - if (relator.getCode().equalsIgnoreCase(code)) { - return relator; - } - } - return null; - } - -} diff --git a/book/src/main/java/me/ag2s/epublib/domain/Resource.java b/book/src/main/java/me/ag2s/epublib/domain/Resource.java deleted file mode 100644 index c5876e9f2..000000000 --- a/book/src/main/java/me/ag2s/epublib/domain/Resource.java +++ /dev/null @@ -1,340 +0,0 @@ -package me.ag2s.epublib.domain; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.io.Serializable; - -import me.ag2s.epublib.Constants; -import me.ag2s.epublib.util.IOUtil; -import me.ag2s.epublib.util.StringUtil; -import me.ag2s.epublib.util.commons.io.XmlStreamReader; - -/** - * Represents a resource that is part of the epub. - * A resource can be a html file, image, xml, etc. - * - * @author paul - * - */ -public class Resource implements Serializable { - - private static final long serialVersionUID = 1043946707835004037L; - private String id; - private String title; - private String href; - - - - private String properties; - protected final String originalHref; - private MediaType mediaType; - private String inputEncoding; - protected byte[] data; - - /** - * Creates an empty Resource with the given href. - * - * Assumes that if the data is of a text type (html/css/etc) then the encoding will be UTF-8 - * - * @param href The location of the resource within the epub. Example: "chapter1.html". - */ - public Resource(String href) { - this(null, new byte[0], href, MediaTypes.determineMediaType(href)); - } - - /** - * Creates a Resource with the given data and MediaType. - * The href will be automatically generated. - * - * Assumes that if the data is of a text type (html/css/etc) then the encoding will be UTF-8 - * - * @param data The Resource's contents - * @param mediaType The MediaType of the Resource - */ - public Resource(byte[] data, MediaType mediaType) { - this(null, data, null, mediaType); - } - - /** - * Creates a resource with the given data at the specified href. - * The MediaType will be determined based on the href extension. - * - * Assumes that if the data is of a text type (html/css/etc) then the encoding will be UTF-8 - * - * @see MediaTypes#determineMediaType(String) - * - * @param data The Resource's contents - * @param href The location of the resource within the epub. Example: "chapter1.html". - */ - public Resource(byte[] data, String href) { - this(null, data, href, MediaTypes.determineMediaType(href), - Constants.CHARACTER_ENCODING); - } - - /** - * Creates a resource with the data from the given Reader at the specified href. - * The MediaType will be determined based on the href extension. - * - * @see MediaTypes#determineMediaType(String) - * - * @param in The Resource's contents - * @param href The location of the resource within the epub. Example: "cover.jpg". - */ - public Resource(Reader in, String href) throws IOException { - this(null, IOUtil.toByteArray(in, Constants.CHARACTER_ENCODING), href, - MediaTypes.determineMediaType(href), - Constants.CHARACTER_ENCODING); - } - - /** - * Creates a resource with the data from the given InputStream at the specified href. - * The MediaType will be determined based on the href extension. - * - * @see MediaTypes#determineMediaType(String) - * - * Assumes that if the data is of a text type (html/css/etc) then the encoding will be UTF-8 - * - * It is recommended to us the {@link #Resource(Reader, String)} method for creating textual - * (html/css/etc) resources to prevent encoding problems. - * Use this method only for binary Resources like images, fonts, etc. - * - * - * @param in The Resource's contents - * @param href The location of the resource within the epub. Example: "cover.jpg". - */ - public Resource(InputStream in, String href) throws IOException { - this(null, IOUtil.toByteArray(in), href, - MediaTypes.determineMediaType(href)); - } - - /** - * Creates a resource with the given id, data, mediatype at the specified href. - * Assumes that if the data is of a text type (html/css/etc) then the encoding will be UTF-8 - * - * @param id The id of the Resource. Internal use only. Will be auto-generated if it has a null-value. - * @param data The Resource's contents - * @param href The location of the resource within the epub. Example: "chapter1.html". - * @param mediaType The resources MediaType - */ - public Resource(String id, byte[] data, String href, MediaType mediaType) { - this(id, data, href, mediaType, Constants.CHARACTER_ENCODING); - } - public Resource(String id, byte[] data, String href, String originalHref, MediaType mediaType) { - this(id, data, href, originalHref, mediaType, Constants.CHARACTER_ENCODING); - } - - - /** - * Creates a resource with the given id, data, mediatype at the specified href. - * If the data is of a text type (html/css/etc) then it will use the given inputEncoding. - * - * @param id The id of the Resource. Internal use only. Will be auto-generated if it has a null-value. - * @param data The Resource's contents - * @param href The location of the resource within the epub. Example: "chapter1.html". - * @param mediaType The resources MediaType - * @param inputEncoding If the data is of a text type (html/css/etc) then it will use the given inputEncoding. - */ - public Resource(String id, byte[] data, String href, MediaType mediaType, - String inputEncoding) { - this.id = id; - this.href = href; - this.originalHref = href; - this.mediaType = mediaType; - this.inputEncoding = inputEncoding; - this.data = data; - } - public Resource(String id, byte[] data, String href, String originalHref, MediaType mediaType, - String inputEncoding) { - this.id = id; - this.href = href; - this.originalHref = originalHref; - this.mediaType = mediaType; - this.inputEncoding = inputEncoding; - this.data = data; - } - - /** - * Gets the contents of the Resource as an InputStream. - * - * @return The contents of the Resource. - * - * @throws IOException IOException - */ - public InputStream getInputStream() throws IOException { - return new ByteArrayInputStream(getData()); - } - - /** - * The contents of the resource as a byte[] - * - * @return The contents of the resource - */ - public byte[] getData() throws IOException { - return data; - } - - /** - * Tells this resource to release its cached data. - * - * If this resource was not lazy-loaded, this is a no-op. - */ - public void close() { - } - - /** - * Sets the data of the Resource. - * If the data is a of a different type then the original data then make sure to change the MediaType. - * - * @param data the data of the Resource - */ - public void setData(byte[] data) { - this.data = data; - } - - /** - * Returns the size of this resource in bytes. - * - * @return the size. - */ - public long getSize() { - return data.length; - } - - /** - * If the title is found by scanning the underlying html document then it is cached here. - * - * @return the title - */ - public String getTitle() { - return title; - } - - /** - * Sets the Resource's id: Make sure it is unique and a valid identifier. - * - * @param id Resource's id - */ - public void setId(String id) { - this.id = id; - } - - /** - * The resources Id. - * - * Must be both unique within all the resources of this book and a valid identifier. - * @return The resources Id. - */ - public String getId() { - return id; - } - - /** - * The location of the resource within the contents folder of the epub file. - * - * Example:
- * images/cover.jpg
- * content/chapter1.xhtml
- * - * @return The location of the resource within the contents folder of the epub file. - */ - public String getHref() { - return href; - } - - /** - * Sets the Resource's href. - * - * @param href Resource's href. - */ - public void setHref(String href) { - this.href = href; - } - - /** - * The character encoding of the resource. - * Is allowed to be null for non-text resources like images. - * - * @return The character encoding of the resource. - */ - public String getInputEncoding() { - return inputEncoding; - } - - /** - * Sets the Resource's input character encoding. - * - * @param encoding Resource's input character encoding. - */ - public void setInputEncoding(String encoding) { - this.inputEncoding = encoding; - } - - /** - * Gets the contents of the Resource as Reader. - * - * Does all sorts of smart things (courtesy of apache commons io XMLStreamREader) to handle encodings, byte order markers, etc. - * - * @return the contents of the Resource as Reader. - * @throws IOException IOException - */ - public Reader getReader() throws IOException { - return new XmlStreamReader(new ByteArrayInputStream(getData()), - getInputEncoding()); - } - - /** - * Gets the hashCode of the Resource's href. - * - */ - public int hashCode() { - return href.hashCode(); - } - - /** - * Checks to see of the given resourceObject is a resource and whether its href is equal to this one. - * - * @return whether the given resourceObject is a resource and whether its href is equal to this one. - */ - public boolean equals(Object resourceObject) { - if (!(resourceObject instanceof Resource)) { - return false; - } - return href.equals(((Resource) resourceObject).getHref()); - } - - /** - * This resource's mediaType. - * - * @return This resource's mediaType. - */ - public MediaType getMediaType() { - return mediaType; - } - - public void setMediaType(MediaType mediaType) { - this.mediaType = mediaType; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getProperties() { - return properties; - } - - public void setProperties(String properties) { - this.properties = properties; - } - @SuppressWarnings("NullableProblems") - public String toString() { - return StringUtil.toString("id", id, - "title", title, - "encoding", inputEncoding, - "mediaType", mediaType, - "href", href, - "size", (data == null ? 0 : data.length)); - } -} diff --git a/book/src/main/java/me/ag2s/epublib/domain/ResourceReference.java b/book/src/main/java/me/ag2s/epublib/domain/ResourceReference.java deleted file mode 100644 index f09c97643..000000000 --- a/book/src/main/java/me/ag2s/epublib/domain/ResourceReference.java +++ /dev/null @@ -1,43 +0,0 @@ -package me.ag2s.epublib.domain; - -import java.io.Serializable; - -public class ResourceReference implements Serializable { - - private static final long serialVersionUID = 2596967243557743048L; - - protected Resource resource; - - public ResourceReference(Resource resource) { - this.resource = resource; - } - - - public Resource getResource() { - return resource; - } - - /** - * Besides setting the resource it also sets the fragmentId to null. - * - * @param resource resource - */ - public void setResource(Resource resource) { - this.resource = resource; - } - - - /** - * The id of the reference referred to. - * - * null of the reference is null or has a null id itself. - * - * @return The id of the reference referred to. - */ - public String getResourceId() { - if (resource != null) { - return resource.getId(); - } - return null; - } -} diff --git a/book/src/main/java/me/ag2s/epublib/domain/Spine.java b/book/src/main/java/me/ag2s/epublib/domain/Spine.java deleted file mode 100644 index 626304592..000000000 --- a/book/src/main/java/me/ag2s/epublib/domain/Spine.java +++ /dev/null @@ -1,192 +0,0 @@ -package me.ag2s.epublib.domain; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import me.ag2s.epublib.util.StringUtil; - -/** - * The spine sections are the sections of the book in the order in which the book should be read. - * - * This contrasts with the Table of Contents sections which is an index into the Book's sections. - * - * @see TableOfContents - * - * @author paul - */ -public class Spine implements Serializable { - - private static final long serialVersionUID = 3878483958947357246L; - private Resource tocResource; - private List spineReferences; - - public Spine() { - this(new ArrayList<>()); - } - - /** - * Creates a spine out of all the resources in the table of contents. - * - * @param tableOfContents tableOfContents - */ - public Spine(TableOfContents tableOfContents) { - this.spineReferences = createSpineReferences( - tableOfContents.getAllUniqueResources()); - } - - public Spine(List spineReferences) { - this.spineReferences = spineReferences; - } - - public static List createSpineReferences( - Collection resources) { - List result = new ArrayList<>( - resources.size()); - for (Resource resource : resources) { - result.add(new SpineReference(resource)); - } - return result; - } - - public List getSpineReferences() { - return spineReferences; - } - - public void setSpineReferences(List spineReferences) { - this.spineReferences = spineReferences; - } - - /** - * Gets the resource at the given index. - * Null if not found. - * - * @param index index - * @return the resource at the given index. - */ - public Resource getResource(int index) { - if (index < 0 || index >= spineReferences.size()) { - return null; - } - return spineReferences.get(index).getResource(); - } - - /** - * Finds the first resource that has the given resourceId. - * - * Null if not found. - * - * @param resourceId resourceId - * @return the first resource that has the given resourceId. - */ - public int findFirstResourceById(String resourceId) { - if (StringUtil.isBlank(resourceId)) { - return -1; - } - - for (int i = 0; i < spineReferences.size(); i++) { - SpineReference spineReference = spineReferences.get(i); - if (resourceId.equals(spineReference.getResourceId())) { - return i; - } - } - return -1; - } - - /** - * Adds the given spineReference to the spine references and returns it. - * - * @param spineReference spineReference - * @return the given spineReference - */ - public SpineReference addSpineReference(SpineReference spineReference) { - if (spineReferences == null) { - this.spineReferences = new ArrayList<>(); - } - spineReferences.add(spineReference); - return spineReference; - } - - /** - * Adds the given resource to the spine references and returns it. - * - * @return the given spineReference - */ - @SuppressWarnings("unused") - public SpineReference addResource(Resource resource) { - return addSpineReference(new SpineReference(resource)); - } - - /** - * The number of elements in the spine. - * - * @return The number of elements in the spine. - */ - public int size() { - return spineReferences.size(); - } - - /** - * As per the epub file format the spine officially maintains a reference to the Table of Contents. - * The epubwriter will look for it here first, followed by some clever tricks to find it elsewhere if not found. - * Put it here to be sure of the expected behaviours. - * - * @param tocResource tocResource - */ - public void setTocResource(Resource tocResource) { - this.tocResource = tocResource; - } - - /** - * The resource containing the XML for the tableOfContents. - * When saving an epub file this resource needs to be in this place. - * - * @return The resource containing the XML for the tableOfContents. - */ - public Resource getTocResource() { - return tocResource; - } - - /** - * The position within the spine of the given resource. - * - * @param currentResource currentResource - * @return something < 0 if not found. - * - */ - public int getResourceIndex(Resource currentResource) { - if (currentResource == null) { - return -1; - } - return getResourceIndex(currentResource.getHref()); - } - - /** - * The first position within the spine of a resource with the given href. - * - * @return something < 0 if not found. - * - */ - public int getResourceIndex(String resourceHref) { - int result = -1; - if (StringUtil.isBlank(resourceHref)) { - return result; - } - for (int i = 0; i < spineReferences.size(); i++) { - if (resourceHref.equals(spineReferences.get(i).getResource().getHref())) { - result = i; - break; - } - } - return result; - } - - /** - * Whether the spine has any references - * @return Whether the spine has any references - */ - public boolean isEmpty() { - return spineReferences.isEmpty(); - } -} diff --git a/book/src/main/java/me/ag2s/epublib/domain/TOCReference.java b/book/src/main/java/me/ag2s/epublib/domain/TOCReference.java deleted file mode 100644 index 5fe9c71bb..000000000 --- a/book/src/main/java/me/ag2s/epublib/domain/TOCReference.java +++ /dev/null @@ -1,56 +0,0 @@ -package me.ag2s.epublib.domain; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; - -/** - * An item in the Table of Contents. - * - * @see TableOfContents - * - * @author paul - */ -public class TOCReference extends TitledResourceReference - implements Serializable { - - private static final long serialVersionUID = 5787958246077042456L; - private List children; - private static final Comparator COMPARATOR_BY_TITLE_IGNORE_CASE = (tocReference1, tocReference2) -> String.CASE_INSENSITIVE_ORDER.compare(tocReference1.getTitle(), tocReference2.getTitle()); - @Deprecated - public TOCReference() { - this(null, null, null); - } - - public TOCReference(String name, Resource resource) { - this(name, resource, null); - } - - public TOCReference(String name, Resource resource, String fragmentId) { - this(name, resource, fragmentId, new ArrayList<>()); - } - - public TOCReference(String title, Resource resource, String fragmentId, - List children) { - super(resource, title, fragmentId); - this.children = children; - } - @SuppressWarnings("unused") - public static Comparator getComparatorByTitleIgnoreCase() { - return COMPARATOR_BY_TITLE_IGNORE_CASE; - } - - public List getChildren() { - return children; - } - - public TOCReference addChildSection(TOCReference childSection) { - this.children.add(childSection); - return childSection; - } - - public void setChildren(List children) { - this.children = children; - } -} diff --git a/book/src/main/java/me/ag2s/epublib/epub/BookProcessorPipeline.java b/book/src/main/java/me/ag2s/epublib/epub/BookProcessorPipeline.java deleted file mode 100644 index 35256370c..000000000 --- a/book/src/main/java/me/ag2s/epublib/epub/BookProcessorPipeline.java +++ /dev/null @@ -1,73 +0,0 @@ -package me.ag2s.epublib.epub; - -import android.util.Log; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import me.ag2s.epublib.domain.EpubBook; - -/** - * A book processor that combines several other bookprocessors - *

- * Fixes coverpage/coverimage. - * Cleans up the XHTML. - * - * @author paul.siegmann - */ -@SuppressWarnings("unused declaration") -public class BookProcessorPipeline implements BookProcessor { - - private static final String TAG= BookProcessorPipeline.class.getName(); - private List bookProcessors; - - public BookProcessorPipeline() { - this(null); - } - - public BookProcessorPipeline(List bookProcessingPipeline) { - this.bookProcessors = bookProcessingPipeline; - } - - @Override - public EpubBook processBook(EpubBook book) { - if (bookProcessors == null) { - return book; - } - for (BookProcessor bookProcessor : bookProcessors) { - try { - book = bookProcessor.processBook(book); - } catch (Exception e) { - Log.e(TAG, e.getMessage(), e); - } - } - return book; - } - - public void addBookProcessor(BookProcessor bookProcessor) { - if (this.bookProcessors == null) { - bookProcessors = new ArrayList<>(); - } - this.bookProcessors.add(bookProcessor); - } - - public void addBookProcessors(Collection bookProcessors) { - if (this.bookProcessors == null) { - this.bookProcessors = new ArrayList<>(); - } - this.bookProcessors.addAll(bookProcessors); - } - - - public List getBookProcessors() { - return bookProcessors; - } - - - public void setBookProcessingPipeline( - List bookProcessingPipeline) { - this.bookProcessors = bookProcessingPipeline; - } - -} diff --git a/book/src/main/java/me/ag2s/epublib/epub/EpubWriter.java b/book/src/main/java/me/ag2s/epublib/epub/EpubWriter.java deleted file mode 100644 index c421d5a9f..000000000 --- a/book/src/main/java/me/ag2s/epublib/epub/EpubWriter.java +++ /dev/null @@ -1,190 +0,0 @@ -package me.ag2s.epublib.epub; - -import android.util.Log; - -import org.xmlpull.v1.XmlSerializer; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.util.zip.CRC32; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; - -import me.ag2s.epublib.domain.EpubBook; -import me.ag2s.epublib.domain.MediaTypes; -import me.ag2s.epublib.domain.Resource; -import me.ag2s.epublib.util.IOUtil; - -/** - * Generates an epub file. Not thread-safe, single use object. - * - * @author paul - */ -public class EpubWriter { - - private static final String TAG= EpubWriter.class.getName(); - - // package - static final String EMPTY_NAMESPACE_PREFIX = ""; - - private BookProcessor bookProcessor; - - public EpubWriter() { - this(BookProcessor.IDENTITY_BOOKPROCESSOR); - } - - - public EpubWriter(BookProcessor bookProcessor) { - this.bookProcessor = bookProcessor; - } - - - public void write(EpubBook book, OutputStream out) throws IOException { - book = processBook(book); - ZipOutputStream resultStream = new ZipOutputStream(out); - writeMimeType(resultStream); - writeContainer(resultStream); - initTOCResource(book); - writeResources(book, resultStream); - writePackageDocument(book, resultStream); - resultStream.close(); - } - - private EpubBook processBook(EpubBook book) { - if (bookProcessor != null) { - book = bookProcessor.processBook(book); - } - return book; - } - - private void initTOCResource(EpubBook book) { - Resource tocResource; - try { - if (book.isEpub3()) { - tocResource = NCXDocumentV3.createNCXResource(book); - } else { - tocResource = NCXDocumentV2.createNCXResource(book); - } - - Resource currentTocResource = book.getSpine().getTocResource(); - if (currentTocResource != null) { - book.getResources().remove(currentTocResource.getHref()); - } - book.getSpine().setTocResource(tocResource); - book.getResources().add(tocResource); - } catch (Exception ex) { - Log.e(TAG, - "Error writing table of contents: " - + ex.getClass().getName() + ": " + ex.getMessage(), ex); - } - } - - - private void writeResources(EpubBook book, ZipOutputStream resultStream) { - for (Resource resource : book.getResources().getAll()) { - writeResource(resource, resultStream); - } - } - - /** - * Writes the resource to the resultStream. - * - * @param resource resource - * @param resultStream resultStream - */ - private void writeResource(Resource resource, ZipOutputStream resultStream) { - if (resource == null) { - return; - } - try { - resultStream.putNextEntry(new ZipEntry("OEBPS/" + resource.getHref())); - InputStream inputStream = resource.getInputStream(); - - IOUtil.copy(inputStream, resultStream); - inputStream.close(); - } catch (Exception e) { - Log.e(TAG,e.getMessage(), e); - } - } - - - private void writePackageDocument(EpubBook book, ZipOutputStream resultStream) - throws IOException { - resultStream.putNextEntry(new ZipEntry("OEBPS/content.opf")); - XmlSerializer xmlSerializer = EpubProcessorSupport - .createXmlSerializer(resultStream); - PackageDocumentWriter.write(this, xmlSerializer, book); - xmlSerializer.flush(); -// String resultAsString = result.toString(); -// resultStream.write(resultAsString.getBytes(Constants.ENCODING)); - } - - /** - * Writes the META-INF/container.xml file. - * - * @param resultStream resultStream - * @throws IOException IOException - */ - private void writeContainer(ZipOutputStream resultStream) throws IOException { - resultStream.putNextEntry(new ZipEntry("META-INF/container.xml")); - Writer out = new OutputStreamWriter(resultStream); - out.write("\n"); - out.write( - "\n"); - out.write("\t\n"); - out.write( - "\t\t\n"); - out.write("\t\n"); - out.write(""); - out.flush(); - } - - /** - * Stores the mimetype as an uncompressed file in the ZipOutputStream. - * - * @param resultStream resultStream - * @throws IOException IOException - */ - private void writeMimeType(ZipOutputStream resultStream) throws IOException { - ZipEntry mimetypeZipEntry = new ZipEntry("mimetype"); - mimetypeZipEntry.setMethod(ZipEntry.STORED); - byte[] mimetypeBytes = MediaTypes.EPUB.getName().getBytes(); - mimetypeZipEntry.setSize(mimetypeBytes.length); - mimetypeZipEntry.setCrc(calculateCrc(mimetypeBytes)); - resultStream.putNextEntry(mimetypeZipEntry); - resultStream.write(mimetypeBytes); - } - - private long calculateCrc(byte[] data) { - CRC32 crc = new CRC32(); - crc.update(data); - return crc.getValue(); - } - - String getNcxId() { - return "ncx"; - } - - String getNcxHref() { - return "toc.ncx"; - } - - String getNcxMediaType() { - return MediaTypes.NCX.getName(); - } - - - @SuppressWarnings("unused") - public BookProcessor getBookProcessor() { - return bookProcessor; - } - - @SuppressWarnings("unused") - public void setBookProcessor(BookProcessor bookProcessor) { - this.bookProcessor = bookProcessor; - } - -} diff --git a/book/src/main/java/me/ag2s/epublib/epub/PackageDocumentBase.java b/book/src/main/java/me/ag2s/epublib/epub/PackageDocumentBase.java deleted file mode 100644 index a172ce32d..000000000 --- a/book/src/main/java/me/ag2s/epublib/epub/PackageDocumentBase.java +++ /dev/null @@ -1,97 +0,0 @@ -package me.ag2s.epublib.epub; - - -/** - * Functionality shared by the PackageDocumentReader and the PackageDocumentWriter - * - * @author paul - * - */ -public class PackageDocumentBase { - - public static final String BOOK_ID_ID = "duokan-book-id"; - public static final String NAMESPACE_OPF = "http://www.idpf.org/2007/opf"; - public static final String NAMESPACE_DUBLIN_CORE = "http://purl.org/dc/elements/1.1/"; - public static final String PREFIX_DUBLIN_CORE = "dc"; - //public static final String PREFIX_OPF = "opf"; - //在EPUB3标准中,packge前面没有opf头,一些epub阅读器也不支持opf头。 - //Some Epub Reader not reconize op:packge,So just let it empty; - public static final String PREFIX_OPF = ""; - //添加 version 变量来区分Epub文件的版本 - //Add the version field to distinguish the version of EPUB file - public static final String version="version"; - public static final String dateFormat = "yyyy-MM-dd"; - - protected interface DCTags { - - String title = "title"; - String creator = "creator"; - String subject = "subject"; - String description = "description"; - String publisher = "publisher"; - String contributor = "contributor"; - String date = "date"; - String type = "type"; - String format = "format"; - String identifier = "identifier"; - String source = "source"; - String language = "language"; - String relation = "relation"; - String coverage = "coverage"; - String rights = "rights"; - } - - protected interface DCAttributes { - - String scheme = "scheme"; - String id = "id"; - } - - protected interface OPFTags { - - String metadata = "metadata"; - String meta = "meta"; - String manifest = "manifest"; - String packageTag = "package"; - String itemref = "itemref"; - String spine = "spine"; - String reference = "reference"; - String guide = "guide"; - String item = "item"; - } - - protected interface OPFAttributes { - - String uniqueIdentifier = "unique-identifier"; - String idref = "idref"; - String name = "name"; - String content = "content"; - String type = "type"; - String href = "href"; - String linear = "linear"; - String event = "event"; - String role = "role"; - String file_as = "file-as"; - String id = "id"; - String media_type = "media-type"; - String title = "title"; - String toc = "toc"; - String version = "version"; - String scheme = "scheme"; - String property = "property"; - //add for epub3 - /** - * add for epub3 - */ - String properties="properties"; - } - - protected interface OPFValues { - - String meta_cover = "cover"; - String reference_cover = "cover"; - String no = "no"; - String generator = "generator"; - String duokan = "duokan-body-font"; - } -} \ No newline at end of file diff --git a/book/src/main/java/me/ag2s/epublib/epub/PackageDocumentMetadataWriter.java b/book/src/main/java/me/ag2s/epublib/epub/PackageDocumentMetadataWriter.java deleted file mode 100644 index fc758bc03..000000000 --- a/book/src/main/java/me/ag2s/epublib/epub/PackageDocumentMetadataWriter.java +++ /dev/null @@ -1,187 +0,0 @@ -package me.ag2s.epublib.epub; - -import org.xmlpull.v1.XmlSerializer; - -import java.io.IOException; -import java.util.List; -import java.util.Map; - -import javax.xml.namespace.QName; - -import me.ag2s.epublib.Constants; -import me.ag2s.epublib.domain.Author; -import me.ag2s.epublib.domain.Date; -import me.ag2s.epublib.domain.EpubBook; -import me.ag2s.epublib.domain.Identifier; -import me.ag2s.epublib.util.StringUtil; - -public class PackageDocumentMetadataWriter extends PackageDocumentBase { - - /** - * Writes the book's metadata. - * - * @param book book - * @param serializer serializer - * @throws IOException IOException - * @throws IllegalStateException IllegalStateException - * @throws IllegalArgumentException IllegalArgumentException - */ - public static void writeMetaData(EpubBook book, XmlSerializer serializer) - throws IllegalArgumentException, IllegalStateException, IOException { - serializer.startTag(NAMESPACE_OPF, OPFTags.metadata); - serializer.setPrefix(PREFIX_DUBLIN_CORE, NAMESPACE_DUBLIN_CORE); - serializer.setPrefix(PREFIX_OPF, NAMESPACE_OPF); - - writeIdentifiers(book.getMetadata().getIdentifiers(), serializer); - writeSimpleMetdataElements(DCTags.title, book.getMetadata().getTitles(), - serializer); - writeSimpleMetdataElements(DCTags.subject, book.getMetadata().getSubjects(), - serializer); - writeSimpleMetdataElements(DCTags.description, - book.getMetadata().getDescriptions(), serializer); - writeSimpleMetdataElements(DCTags.publisher, - book.getMetadata().getPublishers(), serializer); - writeSimpleMetdataElements(DCTags.type, book.getMetadata().getTypes(), - serializer); - writeSimpleMetdataElements(DCTags.rights, book.getMetadata().getRights(), - serializer); - - // write authors - for (Author author : book.getMetadata().getAuthors()) { - serializer.startTag(NAMESPACE_DUBLIN_CORE, DCTags.creator); - serializer.attribute(NAMESPACE_OPF, OPFAttributes.role, - author.getRelator().getCode()); - serializer.attribute(NAMESPACE_OPF, OPFAttributes.file_as, - author.getLastname() + ", " + author.getFirstname()); - serializer.text(author.getFirstname() + " " + author.getLastname()); - serializer.endTag(NAMESPACE_DUBLIN_CORE, DCTags.creator); - } - - // write contributors - for (Author author : book.getMetadata().getContributors()) { - serializer.startTag(NAMESPACE_DUBLIN_CORE, DCTags.contributor); - serializer.attribute(NAMESPACE_OPF, OPFAttributes.role, - author.getRelator().getCode()); - serializer.attribute(NAMESPACE_OPF, OPFAttributes.file_as, - author.getLastname() + ", " + author.getFirstname()); - serializer.text(author.getFirstname() + " " + author.getLastname()); - serializer.endTag(NAMESPACE_DUBLIN_CORE, DCTags.contributor); - } - - // write dates - for (Date date : book.getMetadata().getDates()) { - serializer.startTag(NAMESPACE_DUBLIN_CORE, DCTags.date); - if (date.getEvent() != null) { - serializer.attribute(NAMESPACE_OPF, OPFAttributes.event, - date.getEvent().toString()); - } - serializer.text(date.getValue()); - serializer.endTag(NAMESPACE_DUBLIN_CORE, DCTags.date); - } - - // write language - if (StringUtil.isNotBlank(book.getMetadata().getLanguage())) { - serializer.startTag(NAMESPACE_DUBLIN_CORE, "language"); - serializer.text(book.getMetadata().getLanguage()); - serializer.endTag(NAMESPACE_DUBLIN_CORE, "language"); - } - - // write other properties - if (book.getMetadata().getOtherProperties() != null) { - for (Map.Entry mapEntry : book.getMetadata() - .getOtherProperties().entrySet()) { - serializer.startTag(mapEntry.getKey().getNamespaceURI(), OPFTags.meta); - serializer.attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, - OPFAttributes.property, mapEntry.getKey().getLocalPart()); - serializer.text(mapEntry.getValue()); - serializer.endTag(mapEntry.getKey().getNamespaceURI(), OPFTags.meta); - - } - } - - // write coverimage - if (book.getCoverImage() != null) { // write the cover image - serializer.startTag(NAMESPACE_OPF, OPFTags.meta); - serializer - .attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, OPFAttributes.name, - OPFValues.meta_cover); - serializer - .attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, OPFAttributes.content, - book.getCoverImage().getId()); - serializer.endTag(NAMESPACE_OPF, OPFTags.meta); - } - - // write generator - serializer.startTag(NAMESPACE_OPF, OPFTags.meta); - serializer.attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, OPFAttributes.name, - OPFValues.generator); - serializer - .attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, OPFAttributes.content, - Constants.EPUB_GENERATOR_NAME); - serializer.endTag(NAMESPACE_OPF, OPFTags.meta); - - // write duokan - serializer.startTag(NAMESPACE_OPF, OPFTags.meta); - serializer.attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, OPFAttributes.name, - OPFValues.duokan); - serializer - .attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, OPFAttributes.content, - Constants.EPUB_DUOKAN_NAME); - serializer.endTag(NAMESPACE_OPF, OPFTags.meta); - - serializer.endTag(NAMESPACE_OPF, OPFTags.metadata); - } - - private static void writeSimpleMetdataElements(String tagName, - List values, XmlSerializer serializer) - throws IllegalArgumentException, IllegalStateException, IOException { - for (String value : values) { - if (StringUtil.isBlank(value)) { - continue; - } - serializer.startTag(NAMESPACE_DUBLIN_CORE, tagName); - serializer.text(value); - serializer.endTag(NAMESPACE_DUBLIN_CORE, tagName); - } - } - - - /** - * Writes out the complete list of Identifiers to the package document. - * The first identifier for which the bookId is true is made the bookId identifier. - * If no identifier has bookId == true then the first bookId identifier is written as the primary. - * - * @param identifiers identifiers - * @param serializer serializer - * @throws IllegalStateException e - * @throws IllegalArgumentException e - * @ - */ - private static void writeIdentifiers(List identifiers, - XmlSerializer serializer) - throws IllegalArgumentException, IllegalStateException, IOException { - Identifier bookIdIdentifier = Identifier.getBookIdIdentifier(identifiers); - if (bookIdIdentifier == null) { - return; - } - - serializer.startTag(NAMESPACE_DUBLIN_CORE, DCTags.identifier); - serializer.attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, DCAttributes.id, - BOOK_ID_ID); - serializer.attribute(NAMESPACE_OPF, OPFAttributes.scheme, - bookIdIdentifier.getScheme()); - serializer.text(bookIdIdentifier.getValue()); - serializer.endTag(NAMESPACE_DUBLIN_CORE, DCTags.identifier); - - for (Identifier identifier : identifiers.subList(1, identifiers.size())) { - if (identifier == bookIdIdentifier) { - continue; - } - serializer.startTag(NAMESPACE_DUBLIN_CORE, DCTags.identifier); - serializer.attribute(NAMESPACE_OPF, "scheme", identifier.getScheme()); - serializer.text(identifier.getValue()); - serializer.endTag(NAMESPACE_DUBLIN_CORE, DCTags.identifier); - } - } - -} diff --git a/book/src/main/java/me/ag2s/epublib/util/CollectionUtil.java b/book/src/main/java/me/ag2s/epublib/util/CollectionUtil.java deleted file mode 100644 index e367fdc66..000000000 --- a/book/src/main/java/me/ag2s/epublib/util/CollectionUtil.java +++ /dev/null @@ -1,71 +0,0 @@ -package me.ag2s.epublib.util; - -import java.util.Collection; -import java.util.Enumeration; -import java.util.Iterator; -import java.util.List; - -public class CollectionUtil { - - /** - * Wraps an Enumeration around an Iterator - * @author paul.siegmann - * - * @param - */ - private static class IteratorEnumerationAdapter implements Enumeration { - - private final Iterator iterator; - - public IteratorEnumerationAdapter(Iterator iter) { - this.iterator = iter; - } - - @Override - public boolean hasMoreElements() { - return iterator.hasNext(); - } - - @Override - public T nextElement() { - return iterator.next(); - } - } - - /** - * Creates an Enumeration out of the given Iterator. - * @param g - * @param it g - * @return an Enumeration created out of the given Iterator. - */ - @SuppressWarnings("unused") - public static Enumeration createEnumerationFromIterator( - Iterator it) { - return new IteratorEnumerationAdapter<>(it); - } - - - /** - * Returns the first element of the list, null if the list is null or empty. - * - * @param f - * @param list f - * @return the first element of the list, null if the list is null or empty. - */ - public static T first(List list) { - if (list == null || list.isEmpty()) { - return null; - } - return list.get(0); - } - - /** - * Whether the given collection is null or has no elements. - * - * @param collection g - * @return Whether the given collection is null or has no elements. - */ - public static boolean isEmpty(Collection collection) { - return collection == null || collection.isEmpty(); - } -} diff --git a/book/src/main/java/me/ag2s/epublib/util/zip/AndroidZipEntry.java b/book/src/main/java/me/ag2s/epublib/util/zip/AndroidZipEntry.java deleted file mode 100644 index 0263218f1..000000000 --- a/book/src/main/java/me/ag2s/epublib/util/zip/AndroidZipEntry.java +++ /dev/null @@ -1,363 +0,0 @@ - - - -package me.ag2s.epublib.util.zip; - -import java.util.Calendar; -import java.util.Date; -import java.util.zip.ZipOutputStream; - -/** - * This class represents a member of a zip archive. ZipFile and - * ZipInputStream will give you instances of this class as information - * about the members in an archive. On the other hand ZipOutputStream - * needs an instance of this class to create a new member. - * - * @author Jochen Hoenicke - */ -public class AndroidZipEntry implements ZipConstants, Cloneable { - private static final int KNOWN_SIZE = 1; - private static final int KNOWN_CSIZE = 2; - private static final int KNOWN_CRC = 4; - private static final int KNOWN_TIME = 8; - - private static Calendar cal; - - private final String name; - private final int nameLen; - private int size; - private int compressedSize; - private int crc; - private int dostime; - private short known = 0; - private short method = -1; - private byte[] extra = null; - private String comment = null; - - int flags; /* used by ZipOutputStream */ - int offset; /* used by ZipFile and ZipOutputStream */ - - - /** - * Compression method. This method doesn't compress at all. - */ - public final static int STORED = 0; - /** - * Compression method. This method uses the Deflater. - */ - public final static int DEFLATED = 8; - - /** - * Creates a zip entry with the given name. - * - * @param name the name. May include directory components separated - * by '/'. - * @throws NullPointerException when name is null. - * @throws IllegalArgumentException when name is bigger then 65535 chars. - */ - public AndroidZipEntry(String name, int nameLen) { - //int length = name.length(); - this.nameLen = nameLen; - if (nameLen > 65535) - throw new IllegalArgumentException("name length is " + nameLen); - this.name = name; - } - - - /** - * Creates a copy of the given zip entry. - * - * @param e the entry to copy. - */ - public AndroidZipEntry(AndroidZipEntry e) { - name = e.name; - nameLen = e.nameLen; - known = e.known; - size = e.size; - compressedSize = e.compressedSize; - crc = e.crc; - dostime = e.dostime; - method = e.method; - extra = e.extra; - comment = e.comment; - } - - final void setDOSTime(int dostime) { - this.dostime = dostime; - known |= KNOWN_TIME; - } - - final int getDOSTime() { - if ((known & KNOWN_TIME) == 0) - return 0; - else - return dostime; - } - - /** - * Creates a copy of this zip entry. - */ - /** - * Clones the entry. - */ - public Object clone() { - try { - // The JCL says that the `extra' field is also copied. - AndroidZipEntry clone = (AndroidZipEntry) super.clone(); - if (extra != null) - clone.extra = (byte[]) extra.clone(); - return clone; - } catch (CloneNotSupportedException ex) { - throw new InternalError(); - } - } - - /** - * Returns the entry name. The path components in the entry are - * always separated by slashes ('/'). - */ - public String getName() { - return name; - } - - public int getNameLen() { - return nameLen; - } - - /** - * Sets the time of last modification of the entry. - * - * @time the time of last modification of the entry. - */ - public void setTime(long time) { - Calendar cal = getCalendar(); - synchronized (cal) { - cal.setTime(new Date(time * 1000L)); - dostime = (cal.get(Calendar.YEAR) - 1980 & 0x7f) << 25 - | (cal.get(Calendar.MONTH) + 1) << 21 - | (cal.get(Calendar.DAY_OF_MONTH)) << 16 - | (cal.get(Calendar.HOUR_OF_DAY)) << 11 - | (cal.get(Calendar.MINUTE)) << 5 - | (cal.get(Calendar.SECOND)) >> 1; - } - dostime = (int) (dostime / 1000L); - this.known |= KNOWN_TIME; - } - - /** - * Gets the time of last modification of the entry. - * - * @return the time of last modification of the entry, or -1 if unknown. - */ - public long getTime() { - if ((known & KNOWN_TIME) == 0) - return -1; - - int sec = 2 * (dostime & 0x1f); - int min = (dostime >> 5) & 0x3f; - int hrs = (dostime >> 11) & 0x1f; - int day = (dostime >> 16) & 0x1f; - int mon = ((dostime >> 21) & 0xf) - 1; - int year = ((dostime >> 25) & 0x7f) + 1980; /* since 1900 */ - - try { - cal = getCalendar(); - synchronized (cal) { - cal.set(year, mon, day, hrs, min, sec); - return cal.getTime().getTime(); - } - } catch (RuntimeException ex) { - /* Ignore illegal time stamp */ - known &= ~KNOWN_TIME; - return -1; - } - } - - private static synchronized Calendar getCalendar() { - if (cal == null) - cal = Calendar.getInstance(); - - return cal; - } - - /** - * Sets the size of the uncompressed data. - * - * @throws IllegalArgumentException if size is not in 0..0xffffffffL - */ - public void setSize(long size) { - if ((size & 0xffffffff00000000L) != 0) - throw new IllegalArgumentException(); - this.size = (int) size; - this.known |= KNOWN_SIZE; - } - - /** - * Gets the size of the uncompressed data. - * - * @return the size or -1 if unknown. - */ - public long getSize() { - return (known & KNOWN_SIZE) != 0 ? size & 0xffffffffL : -1L; - } - - /** - * Sets the size of the compressed data. - * - * @throws IllegalArgumentException if size is not in 0..0xffffffffL - */ - public void setCompressedSize(long csize) { - if ((csize & 0xffffffff00000000L) != 0) - throw new IllegalArgumentException(); - this.compressedSize = (int) csize; - this.known |= KNOWN_CSIZE; - } - - /** - * Gets the size of the compressed data. - * - * @return the size or -1 if unknown. - */ - public long getCompressedSize() { - return (known & KNOWN_CSIZE) != 0 ? compressedSize & 0xffffffffL : -1L; - } - - /** - * Sets the crc of the uncompressed data. - * - * @throws IllegalArgumentException if crc is not in 0..0xffffffffL - */ - public void setCrc(long crc) { - if ((crc & 0xffffffff00000000L) != 0) - throw new IllegalArgumentException(); - this.crc = (int) crc; - this.known |= KNOWN_CRC; - } - - /** - * Gets the crc of the uncompressed data. - * - * @return the crc or -1 if unknown. - */ - public long getCrc() { - return (known & KNOWN_CRC) != 0 ? crc & 0xffffffffL : -1L; - } - - /** - * Sets the compression method. Only DEFLATED and STORED are - * supported. - * - * @throws IllegalArgumentException if method is not supported. - * @see ZipOutputStream#DEFLATED - * @see ZipOutputStream#STORED - */ - public void setMethod(int method) { - if (method != ZipOutputStream.STORED - && method != ZipOutputStream.DEFLATED) - throw new IllegalArgumentException(); - this.method = (short) method; - } - - /** - * Gets the compression method. - * - * @return the compression method or -1 if unknown. - */ - public int getMethod() { - return method; - } - - /** - * Sets the extra data. - * - * @throws IllegalArgumentException if extra is longer than 0xffff bytes. - */ - public void setExtra(byte[] extra) { - if (extra == null) { - this.extra = null; - return; - } - - if (extra.length > 0xffff) - throw new IllegalArgumentException(); - this.extra = extra; - try { - int pos = 0; - while (pos < extra.length) { - int sig = (extra[pos++] & 0xff) - | (extra[pos++] & 0xff) << 8; - int len = (extra[pos++] & 0xff) - | (extra[pos++] & 0xff) << 8; - if (sig == 0x5455) { - /* extended time stamp */ - int flags = extra[pos]; - if ((flags & 1) != 0) { - long time = ((extra[pos + 1] & 0xff) - | (extra[pos + 2] & 0xff) << 8 - | (extra[pos + 3] & 0xff) << 16 - | (extra[pos + 4] & 0xff) << 24); - setTime(time); - } - } - pos += len; - } - } catch (ArrayIndexOutOfBoundsException ex) { - /* be lenient */ - return; - } - } - - /** - * Gets the extra data. - * - * @return the extra data or null if not set. - */ - public byte[] getExtra() { - return extra; - } - - /** - * Sets the entry comment. - * - * @throws IllegalArgumentException if comment is longer than 0xffff. - */ - public void setComment(String comment) { - if (comment != null && comment.length() > 0xffff) - throw new IllegalArgumentException(); - this.comment = comment; - } - - /** - * Gets the comment. - * - * @return the comment or null if not set. - */ - public String getComment() { - return comment; - } - - /** - * Gets true, if the entry is a directory. This is solely - * determined by the name, a trailing slash '/' marks a directory. - */ - public boolean isDirectory() { - int nlen = name.length(); - return nlen > 0 && name.charAt(nlen - 1) == '/'; - } - - /** - * Gets the string representation of this AndroidZipEntry. This is just - * the name as returned by getName(). - */ - public String toString() { - return name; - } - - /** - * Gets the hashCode of this AndroidZipEntry. This is just the hashCode - * of the name. Note that the equals method isn't changed, though. - */ - public int hashCode() { - return name.hashCode(); - } -} diff --git a/book/src/main/java/me/ag2s/epublib/util/zip/ZipConstants.java b/book/src/main/java/me/ag2s/epublib/util/zip/ZipConstants.java deleted file mode 100644 index a805a5757..000000000 --- a/book/src/main/java/me/ag2s/epublib/util/zip/ZipConstants.java +++ /dev/null @@ -1,61 +0,0 @@ - - -package me.ag2s.epublib.util.zip; - -interface ZipConstants { - /* The local file header */ - int LOCHDR = 30; - int LOCSIG = 'P' | ('K' << 8) | (3 << 16) | (4 << 24); - - int LOCVER = 4; - int LOCFLG = 6; - int LOCHOW = 8; - int LOCTIM = 10; - int LOCCRC = 14; - int LOCSIZ = 18; - int LOCLEN = 22; - int LOCNAM = 26; - int LOCEXT = 28; - - /* The Data descriptor */ - int EXTSIG = 'P' | ('K' << 8) | (7 << 16) | (8 << 24); - int EXTHDR = 16; - - int EXTCRC = 4; - int EXTSIZ = 8; - int EXTLEN = 12; - - /* The central directory file header */ - int CENSIG = 'P' | ('K' << 8) | (1 << 16) | (2 << 24); - int CENHDR = 46; - - int CENVEM = 4; - int CENVER = 6; - int CENFLG = 8; - int CENHOW = 10; - int CENTIM = 12; - int CENCRC = 16; - int CENSIZ = 20; - int CENLEN = 24; - int CENNAM = 28; - int CENEXT = 30; - int CENCOM = 32; - int CENDSK = 34; - int CENATT = 36; - int CENATX = 38; - int CENOFF = 42; - - /* The entries in the end of central directory */ - int ENDSIG = 'P' | ('K' << 8) | (5 << 16) | (6 << 24); - int ENDHDR = 22; - - /* The following two fields are missing in SUN JDK */ - int ENDNRD = 4; - int ENDDCD = 6; - int ENDSUB = 8; - int ENDTOT = 10; - int ENDSIZ = 12; - int ENDOFF = 16; - int ENDCOM = 20; -} - diff --git a/book/src/main/java/me/ag2s/umdlib/domain/UmdChapters.java b/book/src/main/java/me/ag2s/umdlib/domain/UmdChapters.java deleted file mode 100644 index 48cae1583..000000000 --- a/book/src/main/java/me/ag2s/umdlib/domain/UmdChapters.java +++ /dev/null @@ -1,207 +0,0 @@ -package me.ag2s.umdlib.domain; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.zip.DeflaterOutputStream; - -import me.ag2s.umdlib.tool.UmdUtils; -import me.ag2s.umdlib.tool.WrapOutputStream; - -/** - * It includes all titles and contents of each chapter in the UMD file. - * And the content has been compressed by zlib. - * - * @author Ray Liang (liangguanhui@qq.com) - * 2009-12-20 - */ -public class UmdChapters { - - private static final int DEFAULT_CHUNK_INIT_SIZE = 32768; - private int TotalContentLen; - - public List getTitles() { - return titles; - } - - private final List titles = new ArrayList<>(); - public List contentLengths = new ArrayList<>(); - public ByteArrayOutputStream contents = new ByteArrayOutputStream(); - - public void addTitle(String s){ - titles.add(UmdUtils.stringToUnicodeBytes(s)); - } - public void addTitle(byte[] s){ - titles.add(s); - } - public void addContentLength(Integer integer){ - contentLengths.add(integer); - } - public int getContentLength(int index){ - return contentLengths.get(index); - } - - public byte[] getContent(int index) { - int st=contentLengths.get(index); - byte[] b=contents.toByteArray(); - int end=index+1 chunkRbList = new ArrayList<>(); - - while(startPos < allContents.length) { - left = allContents.length - startPos; - len = Math.min(DEFAULT_CHUNK_INIT_SIZE, left); - - bos.reset(); - DeflaterOutputStream zos = new DeflaterOutputStream(bos); - zos.write(allContents, startPos, len); - zos.close(); - byte[] chunk = bos.toByteArray(); - - byte[] rb = UmdUtils.genRandomBytes(4); - wos.writeByte('$'); - wos.writeBytes(rb); // 4 random - chunkRbList.add(rb); - wos.writeInt(chunk.length + 9); - wos.write(chunk); - - // end of each chunk - wos.writeBytes('#', 0xF1, 0, 0, 0x15); - wos.write(zero16); - - startPos += len; - chunkCnt++; - } - - // end of all chunks - wos.writeBytes('#', 0x81, 0, 0x01, 0x09); - wos.writeBytes(0, 0, 0, 0); //random numbers - wos.write('$'); - wos.writeBytes(0, 0, 0, 0); //random numbers - wos.writeInt(chunkCnt * 4 + 9); - for (int i = chunkCnt - 1; i >= 0; i--) { - // random. They are as the same as random numbers in the begin of each chunk - // use desc order to output these random - wos.writeBytes(chunkRbList.get(i)); - } - } - - public void addChapter(String title, String content) { - titles.add(UmdUtils.stringToUnicodeBytes(title)); - byte[] b = UmdUtils.stringToUnicodeBytes(content); - contentLengths.add(b.length); - try { - contents.write(b); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public void addFile(File f, String title) throws IOException { - byte[] temp = UmdUtils.readFile(f); - String s = new String(temp); - addChapter(title, s); - } - - public void addFile(File f) throws IOException { - String s = f.getName(); - int idx = s.lastIndexOf('.'); - if (idx >= 0) { - s = s.substring(0, idx); - } - addFile(f, s); - } - - public void clearChapters() { - titles.clear(); - contentLengths.clear(); - contents.reset(); - } - - public int getTotalContentLen() { - return TotalContentLen; - } - - public void setTotalContentLen(int totalContentLen) { - TotalContentLen = totalContentLen; - } -} diff --git a/book/src/main/java/me/ag2s/umdlib/domain/UmdHeader.java b/book/src/main/java/me/ag2s/umdlib/domain/UmdHeader.java deleted file mode 100644 index 7844646b2..000000000 --- a/book/src/main/java/me/ag2s/umdlib/domain/UmdHeader.java +++ /dev/null @@ -1,165 +0,0 @@ -package me.ag2s.umdlib.domain; - - -import androidx.annotation.NonNull; - -import java.io.IOException; - -import me.ag2s.umdlib.tool.UmdUtils; -import me.ag2s.umdlib.tool.WrapOutputStream; - -/** - * Header of UMD file. - * It includes a lot of properties of header. - * All the properties are String type. - * - * @author Ray Liang (liangguanhui@qq.com) - * 2009-12-20 - */ -public class UmdHeader { - public byte getUmdType() { - return umdType; - } - - public void setUmdType(byte umdType) { - this.umdType = umdType; - } - - private byte umdType; - private String title; - - private String author; - - private String year; - - private String month; - - private String day; - - private String bookType; - - private String bookMan; - - private String shopKeeper; - private final static byte B_type_umd = (byte) 0x01; - private final static byte B_type_title = (byte) 0x02; - private final static byte B_type_author = (byte) 0x03; - private final static byte B_type_year = (byte) 0x04; - private final static byte B_type_month = (byte) 0x05; - private final static byte B_type_day = (byte) 0x06; - private final static byte B_type_bookType = (byte) 0x07; - private final static byte B_type_bookMan = (byte) 0x08; - private final static byte B_type_shopKeeper = (byte) 0x09; - - public void buildHeader(WrapOutputStream wos) throws IOException { - wos.writeBytes(0x89, 0x9b, 0x9a, 0xde); // UMD file type flags - wos.writeByte('#'); - wos.writeBytes(0x01, 0x00, 0x00, 0x08); // Unknown - wos.writeByte(0x01); //0x01 is text type; while 0x02 is Image type. - wos.writeBytes(UmdUtils.genRandomBytes(2)); //random number - - // start properties output - buildType(wos, B_type_title, getTitle()); - buildType(wos, B_type_author, getAuthor()); - buildType(wos, B_type_year, getYear()); - buildType(wos, B_type_month, getMonth()); - buildType(wos, B_type_day, getDay()); - buildType(wos, B_type_bookType, getBookType()); - buildType(wos, B_type_bookMan, getBookMan()); - buildType(wos, B_type_shopKeeper, getShopKeeper()); - } - - public void buildType(WrapOutputStream wos, byte type, String content) throws IOException { - if (content == null || content.length() == 0) { - return; - } - - wos.writeBytes('#', type, 0, 0); - - byte[] temp = UmdUtils.stringToUnicodeBytes(content); - wos.writeByte(temp.length + 5); - wos.write(temp); - } - - - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getAuthor() { - return author; - } - - public void setAuthor(String author) { - this.author = author; - } - - public String getBookMan() { - return bookMan; - } - - public void setBookMan(String bookMan) { - this.bookMan = bookMan; - } - - public String getShopKeeper() { - return shopKeeper; - } - - public void setShopKeeper(String shopKeeper) { - this.shopKeeper = shopKeeper; - } - - public String getYear() { - return year; - } - - public void setYear(String year) { - this.year = year; - } - - public String getMonth() { - return month; - } - - public void setMonth(String month) { - this.month = month; - } - - public String getDay() { - return day; - } - - public void setDay(String day) { - this.day = day; - } - - public String getBookType() { - return bookType; - } - - public void setBookType(String bookType) { - this.bookType = bookType; - } - - @Override - @NonNull - public String toString() { - return "UmdHeader{" + - "umdType=" + umdType + - ", title='" + title + '\'' + - ", author='" + author + '\'' + - ", year='" + year + '\'' + - ", month='" + month + '\'' + - ", day='" + day + '\'' + - ", bookType='" + bookType + '\'' + - ", bookMan='" + bookMan + '\'' + - ", shopKeeper='" + shopKeeper + '\'' + - '}'; - } -} diff --git a/book/src/main/java/me/ag2s/umdlib/tool/UmdUtils.java b/book/src/main/java/me/ag2s/umdlib/tool/UmdUtils.java deleted file mode 100644 index 695c619dd..000000000 --- a/book/src/main/java/me/ag2s/umdlib/tool/UmdUtils.java +++ /dev/null @@ -1,153 +0,0 @@ - -package me.ag2s.umdlib.tool; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Random; -import java.util.zip.InflaterInputStream; - - -public class UmdUtils { - - private static final int EOF = -1; - private static final int BUFFER_SIZE = 8 * 1024; - - - /** - * 将字符串编码成Unicode形式的byte[] - * @param s 要编码的字符串 - * @return 编码好的byte[] - */ - public static byte[] stringToUnicodeBytes(String s) { - if (s == null) { - throw new NullPointerException(); - } - - int len = s.length(); - byte[] ret = new byte[len * 2]; - int a, b, c; - for (int i = 0; i < len; i++) { - c = s.charAt(i); - a = c >> 8; - b = c & 0xFF; - if (a < 0) { - a += 0xFF; - } - if (b < 0) { - b += 0xFF; - } - ret[i * 2] = (byte) b; - ret[i * 2 + 1] = (byte) a; - } - return ret; - } - - /** - * 将编码成Unicode形式的byte[]解码成原始字符串 - * @param bytes 编码成Unicode形式的byte[] - * @return 原始字符串 - */ - public static String unicodeBytesToString(byte[] bytes){ - char[] s=new char[bytes.length/2]; - StringBuilder sb=new StringBuilder(); - int a,b,c; - for(int i=0;i= 0) { - baos.write(ch); - } - baos.flush(); - return baos.toByteArray(); - } - } - - private static final Random random = new Random(); - - public static byte[] genRandomBytes(int len) { - if (len <= 0) { - throw new IllegalArgumentException("Length must > 0: " + len); - } - byte[] ret = new byte[len]; - for (int i = 0; i < ret.length; i++) { - ret[i] = (byte) random.nextInt(256); - } - return ret; - } - -} diff --git a/book/src/main/java/me/ag2s/umdlib/tool/WrapOutputStream.java b/book/src/main/java/me/ag2s/umdlib/tool/WrapOutputStream.java deleted file mode 100644 index bac69ec29..000000000 --- a/book/src/main/java/me/ag2s/umdlib/tool/WrapOutputStream.java +++ /dev/null @@ -1,91 +0,0 @@ -package me.ag2s.umdlib.tool; - -import java.io.IOException; -import java.io.OutputStream; - -public class WrapOutputStream extends OutputStream { - - private final OutputStream os; - private int written; - - public WrapOutputStream(OutputStream os) { - this.os = os; - } - - private void incCount(int value) { - int temp = written + value; - if (temp < 0) { - temp = Integer.MAX_VALUE; - } - written = temp; - } - - // it is different from the writeInt of DataOutputStream - public void writeInt(int v) throws IOException { - os.write((v >>> 0) & 0xFF); - os.write((v >>> 8) & 0xFF); - os.write((v >>> 16) & 0xFF); - os.write((v >>> 24) & 0xFF); - incCount(4); - } - - public void writeByte(byte b) throws IOException { - write(b); - } - - public void writeByte(int n) throws IOException { - write(n); - } - - public void writeBytes(byte ... bytes) throws IOException { - write(bytes); - } - - public void writeBytes(int ... vals) throws IOException { - for (int v : vals) { - write(v); - } - } - - public void write(byte[] b, int off, int len) throws IOException { - os.write(b, off, len); - incCount(len); - } - - public void write(byte[] b) throws IOException { - os.write(b); - incCount(b.length); - } - - public void write(int b) throws IOException { - os.write(b); - incCount(1); - } - - ///////////////////////////////////////////////// - - public void close() throws IOException { - os.close(); - } - - public void flush() throws IOException { - os.flush(); - } - - public boolean equals(Object obj) { - return os.equals(obj); - } - - public int hashCode() { - return os.hashCode(); - } - - public String toString() { - return os.toString(); - } - - public int getWritten() { - return written; - } - -} diff --git a/book/src/main/resources/dtd/openebook.org/dtds/oeb-1.2/oebpkg12.dtd b/book/src/main/resources/dtd/openebook.org/dtds/oeb-1.2/oebpkg12.dtd deleted file mode 100644 index 34cc2b10e..000000000 --- a/book/src/main/resources/dtd/openebook.org/dtds/oeb-1.2/oebpkg12.dtd +++ /dev/null @@ -1,390 +0,0 @@ - - - - - - - - - -%OEBEntities; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/book/src/main/resources/dtd/www.daisy.org/z3986/2005/ncx-2005-1.dtd b/book/src/main/resources/dtd/www.daisy.org/z3986/2005/ncx-2005-1.dtd deleted file mode 100644 index b889c41a5..000000000 --- a/book/src/main/resources/dtd/www.daisy.org/z3986/2005/ncx-2005-1.dtd +++ /dev/null @@ -1,269 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/ruby/xhtml-ruby-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/ruby/xhtml-ruby-1.mod deleted file mode 100644 index a44bb3fa9..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/ruby/xhtml-ruby-1.mod +++ /dev/null @@ -1,242 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - -]]> - -]]> - - - -]]> - - - - - - - - - - - - - -]]> - - - - - - -]]> - - - - - - -]]> -]]> - - - - - - - -]]> - - - - - - - - -]]> - - - - -]]> -]]> - - - - - - -]]> -]]> - - - - - - - - - - -]]> - - - - - -]]> - - - - - -]]> -]]> - - - - - -]]> - - - - - -]]> - - - - - -]]> -]]> -]]> - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-arch-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-arch-1.mod deleted file mode 100644 index 4a4fa6caa..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-arch-1.mod +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-attribs-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-attribs-1.mod deleted file mode 100644 index 104e57002..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-attribs-1.mod +++ /dev/null @@ -1,142 +0,0 @@ - - - - - - - - - -]]> - - - - -]]> - - - - -]]> - - - - - - - - -]]> - - - - - - - - - - - -]]> - - -]]> - - - - - - - - - - - - - - - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-base-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-base-1.mod deleted file mode 100644 index dca21ca07..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-base-1.mod +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - - - -]]> - - - -]]> - - - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-bdo-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-bdo-1.mod deleted file mode 100644 index fcd67bf6b..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-bdo-1.mod +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - - - -]]> - - - -]]> - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-blkphras-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-blkphras-1.mod deleted file mode 100644 index 0eeb16419..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-blkphras-1.mod +++ /dev/null @@ -1,164 +0,0 @@ - - - - - - - - - - -]]> - - - -]]> - - - - - -]]> - - - -]]> - - - - - -]]> - - - -]]> - - - - - - - - -]]> - - - -]]> - - - - -]]> - - - -]]> - - - - -]]> - - - -]]> - - - - -]]> - - - -]]> - - - - -]]> - - - -]]> - - - - -]]> - - - -]]> - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-blkpres-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-blkpres-1.mod deleted file mode 100644 index 30968bb7a..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-blkpres-1.mod +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - -]]> - - - -]]> - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-blkstruct-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-blkstruct-1.mod deleted file mode 100644 index ab37c73c0..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-blkstruct-1.mod +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - - - - - -]]> - - - -]]> - - - - - -]]> - - - -]]> - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-charent-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-charent-1.mod deleted file mode 100644 index b1faf15cc..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-charent-1.mod +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - -%xhtml-lat1; - - -%xhtml-symbol; - - -%xhtml-special; - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-csismap-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-csismap-1.mod deleted file mode 100644 index 5977f038b..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-csismap-1.mod +++ /dev/null @@ -1,114 +0,0 @@ - - - - - - - - - - -]]> - - - - - - -]]> - - - - - - - - - - - - - - - - - - - -]]> - - - -]]> - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-datatypes-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-datatypes-1.mod deleted file mode 100644 index a2ea3ae85..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-datatypes-1.mod +++ /dev/null @@ -1,103 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-edit-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-edit-1.mod deleted file mode 100644 index 2d3d43f1c..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-edit-1.mod +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - - - - -]]> - - - -]]> - - - - - - - -]]> - - - -]]> - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-events-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-events-1.mod deleted file mode 100644 index ad8a798cf..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-events-1.mod +++ /dev/null @@ -1,135 +0,0 @@ - - - - - - - - - - -]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-form-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-form-1.mod deleted file mode 100644 index 98b0b926a..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-form-1.mod +++ /dev/null @@ -1,292 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - -]]> - - - -]]> - - - - - - - - -]]> - - - -]]> - - - - - - -]]> - - - - - -]]> - - - - - - -]]> - - - -]]> - - - - - - -]]> - - - -]]> - - - - - - -]]> - - - -]]> - - - - - - -]]> - - - -]]> - - - - - - - - -]]> - - - -]]> - - - - - - -]]> - - - -]]> - - - - - - -]]> - - - -]]> - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-framework-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-framework-1.mod deleted file mode 100644 index f37976a6c..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-framework-1.mod +++ /dev/null @@ -1,97 +0,0 @@ - - - - - - - - -%xhtml-arch.mod;]]> - - - -%xhtml-notations.mod;]]> - - - -%xhtml-datatypes.mod;]]> - - - -%xhtml-xlink.mod; - - - -%xhtml-qname.mod;]]> - - - -%xhtml-events.mod;]]> - - - -%xhtml-attribs.mod;]]> - - - -%xhtml-model.redecl; - - - -%xhtml-model.mod;]]> - - - -%xhtml-charent.mod;]]> - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-hypertext-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-hypertext-1.mod deleted file mode 100644 index 85d8348fb..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-hypertext-1.mod +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - - -]]> - - - -]]> - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-image-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-image-1.mod deleted file mode 100644 index 7eea4f9a2..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-image-1.mod +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - -]]> - - - -]]> - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlphras-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlphras-1.mod deleted file mode 100644 index ebada109f..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlphras-1.mod +++ /dev/null @@ -1,203 +0,0 @@ - - - - - - - - - - -]]> - - - -]]> - - - - - -]]> - - - -]]> - - - - - -]]> - - - -]]> - - - - - -]]> - - - -]]> - - - - - -]]> - - - -]]> - - - - - -]]> - - - -]]> - - - - - -]]> - - - -]]> - - - - - -]]> - - - -]]> - - - - - -]]> - - - -]]> - - - - - -]]> - - - -]]> - - - - - -]]> - - - -]]> - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlpres-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlpres-1.mod deleted file mode 100644 index 3e41322c4..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlpres-1.mod +++ /dev/null @@ -1,138 +0,0 @@ - - - - - - - - - - -]]> - - - -]]> - - - - - -]]> - - - -]]> - - - - - -]]> - - - -]]> - - - - - -]]> - - - -]]> - - - - - -]]> - - - -]]> - - - - - -]]> - - - -]]> - - - - - -]]> - - - -]]> - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlstruct-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlstruct-1.mod deleted file mode 100644 index 4d6bd01a6..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlstruct-1.mod +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - -]]> - - - -]]> - - - - - - - -]]> - - - -]]> - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlstyle-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlstyle-1.mod deleted file mode 100644 index 6d526cd17..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlstyle-1.mod +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-lat1.ent b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-lat1.ent deleted file mode 100644 index ffee223eb..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-lat1.ent +++ /dev/null @@ -1,196 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-link-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-link-1.mod deleted file mode 100644 index 4a15f1dd8..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-link-1.mod +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - - - -]]> - - - -]]> - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-list-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-list-1.mod deleted file mode 100644 index 72bdb25c5..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-list-1.mod +++ /dev/null @@ -1,129 +0,0 @@ - - - - - - - - - - - - - - - - - - -]]> - - - -]]> - - - - - - -]]> - - - -]]> - - - - - - -]]> - - - -]]> - - - - - - -]]> - - - -]]> - - - - - - -]]> - - - -]]> - - - - - - -]]> - - - -]]> - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-meta-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-meta-1.mod deleted file mode 100644 index d2f6d2c65..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-meta-1.mod +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - - - - - -]]> - - - -]]> - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-notations-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-notations-1.mod deleted file mode 100644 index 2da12d023..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-notations-1.mod +++ /dev/null @@ -1,114 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-object-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-object-1.mod deleted file mode 100644 index bee7aeb02..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-object-1.mod +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - -]]> - - - -]]> - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-param-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-param-1.mod deleted file mode 100644 index 4ba079160..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-param-1.mod +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - - - -]]> - - - -]]> - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-pres-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-pres-1.mod deleted file mode 100644 index 42a0d6dfe..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-pres-1.mod +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - -%xhtml-inlpres.mod;]]> - - - -%xhtml-blkpres.mod;]]> - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-qname-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-qname-1.mod deleted file mode 100644 index 35c180a68..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-qname-1.mod +++ /dev/null @@ -1,318 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - -]]> - - - - -%xhtml-qname-extra.mod; - - - - - - - - - -]]> - - - - - - - - - - - - - - - - - - - -]]> - - - - - - - -]]> - - - - -%xhtml-qname.redecl; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-script-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-script-1.mod deleted file mode 100644 index 0152ab02f..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-script-1.mod +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - -]]> - - - -]]> - - - - - - - -]]> - - - -]]> - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-special.ent b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-special.ent deleted file mode 100644 index ca358b2fe..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-special.ent +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-ssismap-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-ssismap-1.mod deleted file mode 100644 index 45da878fd..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-ssismap-1.mod +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-struct-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-struct-1.mod deleted file mode 100644 index c826f0f07..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-struct-1.mod +++ /dev/null @@ -1,136 +0,0 @@ - - - - - - - - - - - - - - -]]> - - - -]]> - - - - - - - -]]> - - - - - - -]]> - - - - - - - -]]> - - - -]]> - - - - - - - -]]> - - - -]]> - - - - - - - - -]]> - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-style-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-style-1.mod deleted file mode 100644 index dc85a9e6e..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-style-1.mod +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - - - -]]> - - - -]]> - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-symbol.ent b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-symbol.ent deleted file mode 100644 index 63c2abfa6..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-symbol.ent +++ /dev/null @@ -1,237 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-table-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-table-1.mod deleted file mode 100644 index 540b7346e..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-table-1.mod +++ /dev/null @@ -1,333 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -]]> - - - -]]> - - - - - - -]]> - - - -]]> - - - - - - - - -]]> - - - -]]> - - - - - - - - -]]> - - - -]]> - - - - - - - - -]]> - - - -]]> - - - - - - - - -]]> - - - -]]> - - - - - - - - -]]> - - - -]]> - - - - - - -]]> - - - -]]> - - - - - - - - -]]> - - - -]]> - - - - - - -]]> - - - -]]> - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-text-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-text-1.mod deleted file mode 100644 index a461e1e14..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml-text-1.mod +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - -%xhtml-inlstruct.mod;]]> - - - -%xhtml-inlphras.mod;]]> - - - -%xhtml-blkstruct.mod;]]> - - - -%xhtml-blkphras.mod;]]> - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml11-model-1.mod b/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml11-model-1.mod deleted file mode 100644 index eb834f3d3..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml-modularization/DTD/xhtml11-model-1.mod +++ /dev/null @@ -1,252 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent b/book/src/main/resources/dtd/www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent deleted file mode 100644 index ffee223eb..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent +++ /dev/null @@ -1,196 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml1/DTD/xhtml-special.ent b/book/src/main/resources/dtd/www.w3.org/TR/xhtml1/DTD/xhtml-special.ent deleted file mode 100644 index ca358b2fe..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml1/DTD/xhtml-special.ent +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent b/book/src/main/resources/dtd/www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent deleted file mode 100644 index 63c2abfa6..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent +++ /dev/null @@ -1,237 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd b/book/src/main/resources/dtd/www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd deleted file mode 100644 index 2927b9ece..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd +++ /dev/null @@ -1,978 +0,0 @@ - - - - - -%HTMLlat1; - - -%HTMLsymbol; - - -%HTMLspecial; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd b/book/src/main/resources/dtd/www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd deleted file mode 100644 index 628f27ac5..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd +++ /dev/null @@ -1,1201 +0,0 @@ - - - - - -%HTMLlat1; - - -%HTMLsymbol; - - -%HTMLspecial; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/book/src/main/resources/dtd/www.w3.org/TR/xhtml11/DTD/xhtml11.dtd b/book/src/main/resources/dtd/www.w3.org/TR/xhtml11/DTD/xhtml11.dtd deleted file mode 100644 index 2a999b5b3..000000000 --- a/book/src/main/resources/dtd/www.w3.org/TR/xhtml11/DTD/xhtml11.dtd +++ /dev/null @@ -1,294 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -]]> - - - - - - -%xhtml-inlstyle.mod;]]> - - - - - - - -%xhtml-framework.mod;]]> - - - - -]]> - - - - -%xhtml-text.mod;]]> - - - - -%xhtml-hypertext.mod;]]> - - - - -%xhtml-list.mod;]]> - - - - - - -%xhtml-edit.mod;]]> - - - - -%xhtml-bdo.mod;]]> - - - - - - -%xhtml-ruby.mod;]]> - - - - -%xhtml-pres.mod;]]> - - - - -%xhtml-link.mod;]]> - - - - -%xhtml-meta.mod;]]> - - - - -%xhtml-base.mod;]]> - - - - -%xhtml-script.mod;]]> - - - - -%xhtml-style.mod;]]> - - - - -%xhtml-image.mod;]]> - - - - -%xhtml-csismap.mod;]]> - - - - -%xhtml-ssismap.mod;]]> - - - - -%xhtml-param.mod;]]> - - - - -%xhtml-object.mod;]]> - - - - -%xhtml-table.mod;]]> - - - - -%xhtml-form.mod;]]> - - - - -%xhtml-legacy.mod;]]> - - - - -%xhtml-struct.mod;]]> - - - diff --git a/book/.gitignore b/modules/book/.gitignore similarity index 100% rename from book/.gitignore rename to modules/book/.gitignore diff --git a/book/build.gradle b/modules/book/build.gradle similarity index 78% rename from book/build.gradle rename to modules/book/build.gradle index 199d0094b..bfa4befa2 100644 --- a/book/build.gradle +++ b/modules/book/build.gradle @@ -15,13 +15,6 @@ android { consumerProguardFiles "consumer-rules.pro" } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - - } compileOptions { sourceCompatibility JavaVersion.VERSION_11 targetCompatibility JavaVersion.VERSION_11 diff --git a/book/consumer-rules.pro b/modules/book/consumer-rules.pro similarity index 100% rename from book/consumer-rules.pro rename to modules/book/consumer-rules.pro diff --git a/book/src/main/AndroidManifest.xml b/modules/book/src/main/AndroidManifest.xml similarity index 100% rename from book/src/main/AndroidManifest.xml rename to modules/book/src/main/AndroidManifest.xml diff --git a/book/src/main/java/me/ag2s/base/PfdHelper.java b/modules/book/src/main/java/me/ag2s/base/PfdHelper.java similarity index 100% rename from book/src/main/java/me/ag2s/base/PfdHelper.java rename to modules/book/src/main/java/me/ag2s/base/PfdHelper.java diff --git a/book/src/main/java/me/ag2s/base/ThrowableUtils.java b/modules/book/src/main/java/me/ag2s/base/ThrowableUtils.java similarity index 85% rename from book/src/main/java/me/ag2s/base/ThrowableUtils.java rename to modules/book/src/main/java/me/ag2s/base/ThrowableUtils.java index 6b5555304..ff8978c1a 100644 --- a/book/src/main/java/me/ag2s/base/ThrowableUtils.java +++ b/modules/book/src/main/java/me/ag2s/base/ThrowableUtils.java @@ -9,8 +9,7 @@ public class ThrowableUtils { public static @NonNull IOException rethrowAsIOException(Throwable throwable) throws IOException { - IOException newException = new IOException(throwable.getMessage()); - newException.initCause(throwable); + IOException newException = new IOException(throwable.getMessage(), throwable); throw newException; } } diff --git a/modules/book/src/main/java/me/ag2s/epublib/Constants.java b/modules/book/src/main/java/me/ag2s/epublib/Constants.java new file mode 100644 index 000000000..9d16b8789 --- /dev/null +++ b/modules/book/src/main/java/me/ag2s/epublib/Constants.java @@ -0,0 +1,13 @@ +package me.ag2s.epublib; + + +public interface Constants { + + String CHARACTER_ENCODING = "UTF-8"; + String DOCTYPE_XHTML = ""; + String NAMESPACE_XHTML = "http://www.w3.org/1999/xhtml"; + String EPUB_GENERATOR_NAME = "Ag2S EpubLib"; + String EPUB_DUOKAN_NAME = "DK-SONGTI"; + char FRAGMENT_SEPARATOR_CHAR = '#'; + String DEFAULT_TOC_ID = "toc"; +} diff --git a/modules/book/src/main/java/me/ag2s/epublib/browsersupport/NavigationEvent.java b/modules/book/src/main/java/me/ag2s/epublib/browsersupport/NavigationEvent.java new file mode 100644 index 000000000..fc509f8e0 --- /dev/null +++ b/modules/book/src/main/java/me/ag2s/epublib/browsersupport/NavigationEvent.java @@ -0,0 +1,157 @@ +package me.ag2s.epublib.browsersupport; + +import java.util.EventObject; + +import me.ag2s.epublib.domain.EpubBook; +import me.ag2s.epublib.domain.Resource; +import me.ag2s.epublib.util.StringUtil; + +/** + * Used to tell NavigationEventListener just what kind of navigation action + * the user just did. + * + * @author paul + */ +@SuppressWarnings("unused") +public class NavigationEvent extends EventObject { + + private static final long serialVersionUID = -6346750144308952762L; + + private Resource oldResource; + private int oldSpinePos; + private Navigator navigator; + private EpubBook oldBook; + private int oldSectionPos; + private String oldFragmentId; + + public NavigationEvent(Object source) { + super(source); + } + + public NavigationEvent(Object source, Navigator navigator) { + super(source); + this.navigator = navigator; + this.oldBook = navigator.getBook(); + this.oldFragmentId = navigator.getCurrentFragmentId(); + this.oldSectionPos = navigator.getCurrentSectionPos(); + this.oldResource = navigator.getCurrentResource(); + this.oldSpinePos = navigator.getCurrentSpinePos(); + } + + /** + * The previous position within the section. + * + * @return The previous position within the section. + */ + public int getOldSectionPos() { + return oldSectionPos; + } + + public Navigator getNavigator() { + return navigator; + } + + public String getOldFragmentId() { + return oldFragmentId; + } + + // package + void setOldFragmentId(String oldFragmentId) { + this.oldFragmentId = oldFragmentId; + } + + public EpubBook getOldBook() { + return oldBook; + } + + // package + void setOldPagePos(int oldPagePos) { + this.oldSectionPos = oldPagePos; + } + + public int getCurrentSectionPos() { + return navigator.getCurrentSectionPos(); + } + + public int getOldSpinePos() { + return oldSpinePos; + } + + public int getCurrentSpinePos() { + return navigator.getCurrentSpinePos(); + } + + public String getCurrentFragmentId() { + return navigator.getCurrentFragmentId(); + } + + public boolean isBookChanged() { + if (oldBook == null) { + return true; + } + return oldBook != navigator.getBook(); + } + + public boolean isSpinePosChanged() { + return getOldSpinePos() != getCurrentSpinePos(); + } + + public boolean isFragmentChanged() { + return StringUtil.equals(getOldFragmentId(), getCurrentFragmentId()); + } + + public Resource getOldResource() { + return oldResource; + } + + public Resource getCurrentResource() { + return navigator.getCurrentResource(); + } + + public void setOldResource(Resource oldResource) { + this.oldResource = oldResource; + } + + + public void setOldSpinePos(int oldSpinePos) { + this.oldSpinePos = oldSpinePos; + } + + + public void setNavigator(Navigator navigator) { + this.navigator = navigator; + } + + + public void setOldBook(EpubBook oldBook) { + this.oldBook = oldBook; + } + + public EpubBook getCurrentBook() { + return getNavigator().getBook(); + } + + public boolean isResourceChanged() { + return oldResource != getCurrentResource(); + } + + @SuppressWarnings("NullableProblems") + public String toString() { + return StringUtil.toString( + "oldSectionPos", oldSectionPos, + "oldResource", oldResource, + "oldBook", oldBook, + "oldFragmentId", oldFragmentId, + "oldSpinePos", oldSpinePos, + "currentPagePos", getCurrentSectionPos(), + "currentResource", getCurrentResource(), + "currentBook", getCurrentBook(), + "currentFragmentId", getCurrentFragmentId(), + "currentSpinePos", getCurrentSpinePos() + ); + } + + public boolean isSectionPosChanged() { + return oldSectionPos != getCurrentSectionPos(); + } +} diff --git a/book/src/main/java/me/ag2s/epublib/browsersupport/NavigationEventListener.java b/modules/book/src/main/java/me/ag2s/epublib/browsersupport/NavigationEventListener.java similarity index 53% rename from book/src/main/java/me/ag2s/epublib/browsersupport/NavigationEventListener.java rename to modules/book/src/main/java/me/ag2s/epublib/browsersupport/NavigationEventListener.java index a856347ce..54c08ef04 100644 --- a/book/src/main/java/me/ag2s/epublib/browsersupport/NavigationEventListener.java +++ b/modules/book/src/main/java/me/ag2s/epublib/browsersupport/NavigationEventListener.java @@ -5,14 +5,13 @@ package me.ag2s.epublib.browsersupport; * another location in the book. * * @author paul - * */ public interface NavigationEventListener { - /** - * Called whenever the user navigates to another position in the book. - * - * @param navigationEvent f - */ - void navigationPerformed(NavigationEvent navigationEvent); + /** + * Called whenever the user navigates to another position in the book. + * + * @param navigationEvent f + */ + void navigationPerformed(NavigationEvent navigationEvent); } \ No newline at end of file diff --git a/modules/book/src/main/java/me/ag2s/epublib/browsersupport/NavigationHistory.java b/modules/book/src/main/java/me/ag2s/epublib/browsersupport/NavigationHistory.java new file mode 100644 index 000000000..a3d1dd89c --- /dev/null +++ b/modules/book/src/main/java/me/ag2s/epublib/browsersupport/NavigationHistory.java @@ -0,0 +1,207 @@ +package me.ag2s.epublib.browsersupport; + +import java.util.ArrayList; +import java.util.List; + +import me.ag2s.epublib.domain.EpubBook; +import me.ag2s.epublib.domain.Resource; + +/** + * A history of the user's locations with the epub. + * + * @author paul.siegmann + */ +public class NavigationHistory implements NavigationEventListener { + + public static final int DEFAULT_MAX_HISTORY_SIZE = 1000; + private static final long DEFAULT_HISTORY_WAIT_TIME = 1000; + + private static class Location { + + private String href; + + public Location(String href) { + super(); + this.href = href; + } + + @SuppressWarnings("unused") + public void setHref(String href) { + this.href = href; + } + + public String getHref() { + return href; + } + } + + private long lastUpdateTime = 0; + private List locations = new ArrayList<>(); + private final Navigator navigator; + private int currentPos = -1; + private int currentSize = 0; + private int maxHistorySize = DEFAULT_MAX_HISTORY_SIZE; + private long historyWaitTime = DEFAULT_HISTORY_WAIT_TIME; + + public NavigationHistory(Navigator navigator) { + this.navigator = navigator; + navigator.addNavigationEventListener(this); + initBook(navigator.getBook()); + } + + public int getCurrentPos() { + return currentPos; + } + + + public int getCurrentSize() { + return currentSize; + } + + public void initBook(EpubBook book) { + if (book == null) { + return; + } + locations = new ArrayList<>(); + currentPos = -1; + currentSize = 0; + if (navigator.getCurrentResource() != null) { + addLocation(navigator.getCurrentResource().getHref()); + } + } + + /** + * If the time between a navigation event is less than the historyWaitTime + * then the new location is not added to the history. + *

+ * When a user is rapidly viewing many pages using the slider we do not + * want all of them to be added to the history. + * + * @return the time we wait before adding the page to the history + */ + public long getHistoryWaitTime() { + return historyWaitTime; + } + + public void setHistoryWaitTime(long historyWaitTime) { + this.historyWaitTime = historyWaitTime; + } + + public void addLocation(Resource resource) { + if (resource == null) { + return; + } + addLocation(resource.getHref()); + } + + /** + * Adds the location after the current position. + * If the currentposition is not the end of the list then the elements + * between the current element and the end of the list will be discarded. + *

+ * Does nothing if the new location matches the current location. + *
+ * If this nr of locations becomes larger then the historySize then the + * first item(s) will be removed. + * v + * + * @param location d + */ + public void addLocation(Location location) { + // do nothing if the new location matches the current location + if (!(locations.isEmpty()) && + location.getHref().equals(locations.get(currentPos).getHref())) { + return; + } + currentPos++; + if (currentPos != currentSize) { + locations.set(currentPos, location); + } else { + locations.add(location); + checkHistorySize(); + } + currentSize = currentPos + 1; + } + + /** + * Removes all elements that are too much for the maxHistorySize + * out of the history. + */ + private void checkHistorySize() { + while (locations.size() > maxHistorySize) { + locations.remove(0); + currentSize--; + currentPos--; + } + } + + public void addLocation(String href) { + addLocation(new Location(href)); + } + + private String getLocationHref(int pos) { + if (pos < 0 || pos >= locations.size()) { + return null; + } + return locations.get(currentPos).getHref(); + } + + /** + * Moves the current positions delta positions. + *

+ * move(-1) to go one position back in history.
+ * move(1) to go one position forward.
发 + * + * @param delta f + * @return Whether we actually moved. If the requested value is illegal + * it will return false, true otherwise. + */ + public boolean move(int delta) { + if (((currentPos + delta) < 0) + || ((currentPos + delta) >= currentSize)) { + return false; + } + currentPos += delta; + navigator.gotoResource(getLocationHref(currentPos), this); + return true; + } + + + /** + * If this is not the source of the navigationEvent then the addLocation + * will be called with the href of the currentResource in the navigationEvent. + */ + @Override + public void navigationPerformed(NavigationEvent navigationEvent) { + if (this == navigationEvent.getSource()) { + return; + } + if (navigationEvent.getCurrentResource() == null) { + return; + } + + if ((System.currentTimeMillis() - this.lastUpdateTime) > historyWaitTime) { + // if the user scrolled rapidly through the pages then the last page + // will not be added to the history. We fix that here: + addLocation(navigationEvent.getOldResource()); + + addLocation(navigationEvent.getCurrentResource().getHref()); + } + lastUpdateTime = System.currentTimeMillis(); + } + + public String getCurrentHref() { + if (currentPos < 0 || currentPos >= locations.size()) { + return null; + } + return locations.get(currentPos).getHref(); + } + + public void setMaxHistorySize(int maxHistorySize) { + this.maxHistorySize = maxHistorySize; + } + + public int getMaxHistorySize() { + return maxHistorySize; + } +} diff --git a/modules/book/src/main/java/me/ag2s/epublib/browsersupport/Navigator.java b/modules/book/src/main/java/me/ag2s/epublib/browsersupport/Navigator.java new file mode 100644 index 000000000..1b85f5db3 --- /dev/null +++ b/modules/book/src/main/java/me/ag2s/epublib/browsersupport/Navigator.java @@ -0,0 +1,219 @@ +package me.ag2s.epublib.browsersupport; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import me.ag2s.epublib.domain.EpubBook; +import me.ag2s.epublib.domain.Resource; + +/** + * A helper class for epub browser applications. + *

+ * It helps moving from one resource to the other, from one resource + * to the other and keeping other elements of the application up-to-date + * by calling the NavigationEventListeners. + * + * @author paul + */ +public class Navigator implements Serializable { + + private static final long serialVersionUID = 1076126986424925474L; + private EpubBook book; + private int currentSpinePos; + private Resource currentResource; + private int currentPagePos; + private String currentFragmentId; + + private final List eventListeners = new ArrayList<>(); + + public Navigator() { + this(null); + } + + public Navigator(EpubBook book) { + this.book = book; + this.currentSpinePos = 0; + if (book != null) { + this.currentResource = book.getCoverPage(); + } + this.currentPagePos = 0; + } + + private synchronized void handleEventListeners( + NavigationEvent navigationEvent) { + for (int i = 0; i < eventListeners.size(); i++) { + NavigationEventListener navigationEventListener = eventListeners.get(i); + navigationEventListener.navigationPerformed(navigationEvent); + } + } + + public boolean addNavigationEventListener( + NavigationEventListener navigationEventListener) { + return this.eventListeners.add(navigationEventListener); + } + + public boolean removeNavigationEventListener( + NavigationEventListener navigationEventListener) { + return this.eventListeners.remove(navigationEventListener); + } + + public int gotoFirstSpineSection(Object source) { + return gotoSpineSection(0, source); + } + + public int gotoPreviousSpineSection(Object source) { + return gotoPreviousSpineSection(0, source); + } + + public int gotoPreviousSpineSection(int pagePos, Object source) { + if (currentSpinePos < 0) { + return gotoSpineSection(0, pagePos, source); + } else { + return gotoSpineSection(currentSpinePos - 1, pagePos, source); + } + } + + public boolean hasNextSpineSection() { + return (currentSpinePos < (book.getSpine().size() - 1)); + } + + public boolean hasPreviousSpineSection() { + return (currentSpinePos > 0); + } + + public int gotoNextSpineSection(Object source) { + if (currentSpinePos < 0) { + return gotoSpineSection(0, source); + } else { + return gotoSpineSection(currentSpinePos + 1, source); + } + } + + public int gotoResource(String resourceHref, Object source) { + Resource resource = book.getResources().getByHref(resourceHref); + return gotoResource(resource, source); + } + + + public int gotoResource(Resource resource, Object source) { + return gotoResource(resource, 0, null, source); + } + + public int gotoResource(Resource resource, String fragmentId, Object source) { + return gotoResource(resource, 0, fragmentId, source); + } + + public int gotoResource(Resource resource, int pagePos, Object source) { + return gotoResource(resource, pagePos, null, source); + } + + public int gotoResource(Resource resource, int pagePos, String fragmentId, + Object source) { + if (resource == null) { + return -1; + } + NavigationEvent navigationEvent = new NavigationEvent(source, this); + this.currentResource = resource; + this.currentSpinePos = book.getSpine().getResourceIndex(currentResource); + this.currentPagePos = pagePos; + this.currentFragmentId = fragmentId; + handleEventListeners(navigationEvent); + + return currentSpinePos; + } + + public int gotoResourceId(String resourceId, Object source) { + return gotoSpineSection(book.getSpine().findFirstResourceById(resourceId), + source); + } + + public int gotoSpineSection(int newSpinePos, Object source) { + return gotoSpineSection(newSpinePos, 0, source); + } + + /** + * Go to a specific section. + * Illegal spine positions are silently ignored. + * + * @param newSpinePos f + * @param source f + * @return The current position within the spine + */ + public int gotoSpineSection(int newSpinePos, int newPagePos, Object source) { + if (newSpinePos == currentSpinePos) { + return currentSpinePos; + } + if (newSpinePos < 0 || newSpinePos >= book.getSpine().size()) { + return currentSpinePos; + } + NavigationEvent navigationEvent = new NavigationEvent(source, this); + currentSpinePos = newSpinePos; + currentPagePos = newPagePos; + currentResource = book.getSpine().getResource(currentSpinePos); + handleEventListeners(navigationEvent); + return currentSpinePos; + } + + public int gotoLastSpineSection(Object source) { + return gotoSpineSection(book.getSpine().size() - 1, source); + } + + public void gotoBook(EpubBook book, Object source) { + NavigationEvent navigationEvent = new NavigationEvent(source, this); + this.book = book; + this.currentFragmentId = null; + this.currentPagePos = 0; + this.currentResource = null; + this.currentSpinePos = book.getSpine().getResourceIndex(currentResource); + handleEventListeners(navigationEvent); + } + + /** + * The current position within the spine. + * + * @return something < 0 if the current position is not within the spine. + */ + public int getCurrentSpinePos() { + return currentSpinePos; + } + + public Resource getCurrentResource() { + return currentResource; + } + + /** + * Sets the current index and resource without calling the eventlisteners. + *

+ * If you want the eventListeners called use gotoSection(index); + * + * @param currentIndex f + */ + public void setCurrentSpinePos(int currentIndex) { + this.currentSpinePos = currentIndex; + this.currentResource = book.getSpine().getResource(currentIndex); + } + + public EpubBook getBook() { + return book; + } + + /** + * Sets the current index and resource without calling the eventlisteners. + *

+ * If you want the eventListeners called use gotoSection(index); + */ + public int setCurrentResource(Resource currentResource) { + this.currentSpinePos = book.getSpine().getResourceIndex(currentResource); + this.currentResource = currentResource; + return currentSpinePos; + } + + public String getCurrentFragmentId() { + return currentFragmentId; + } + + public int getCurrentSectionPos() { + return currentPagePos; + } +} diff --git a/book/src/main/java/me/ag2s/epublib/browsersupport/package-info.java b/modules/book/src/main/java/me/ag2s/epublib/browsersupport/package-info.java similarity index 97% rename from book/src/main/java/me/ag2s/epublib/browsersupport/package-info.java rename to modules/book/src/main/java/me/ag2s/epublib/browsersupport/package-info.java index 1ca74f1e4..db3b466fe 100644 --- a/book/src/main/java/me/ag2s/epublib/browsersupport/package-info.java +++ b/modules/book/src/main/java/me/ag2s/epublib/browsersupport/package-info.java @@ -1,6 +1,6 @@ /** * Provides classes that help make an epub reader application. - * + *

* These classes have no dependencies on graphic toolkits, they're purely * to help with the browsing/navigation logic. */ diff --git a/book/src/main/java/me/ag2s/epublib/domain/Author.java b/modules/book/src/main/java/me/ag2s/epublib/domain/Author.java similarity index 100% rename from book/src/main/java/me/ag2s/epublib/domain/Author.java rename to modules/book/src/main/java/me/ag2s/epublib/domain/Author.java diff --git a/book/src/main/java/me/ag2s/epublib/domain/Date.java b/modules/book/src/main/java/me/ag2s/epublib/domain/Date.java similarity index 100% rename from book/src/main/java/me/ag2s/epublib/domain/Date.java rename to modules/book/src/main/java/me/ag2s/epublib/domain/Date.java diff --git a/book/src/main/java/me/ag2s/epublib/domain/EpubBook.java b/modules/book/src/main/java/me/ag2s/epublib/domain/EpubBook.java similarity index 100% rename from book/src/main/java/me/ag2s/epublib/domain/EpubBook.java rename to modules/book/src/main/java/me/ag2s/epublib/domain/EpubBook.java diff --git a/modules/book/src/main/java/me/ag2s/epublib/domain/EpubResourceProvider.java b/modules/book/src/main/java/me/ag2s/epublib/domain/EpubResourceProvider.java new file mode 100644 index 000000000..35406259e --- /dev/null +++ b/modules/book/src/main/java/me/ag2s/epublib/domain/EpubResourceProvider.java @@ -0,0 +1,37 @@ +package me.ag2s.epublib.domain; + +import androidx.annotation.NonNull; + +import java.io.IOException; +import java.io.InputStream; + +import me.ag2s.epublib.util.zip.ZipEntryWrapper; +import me.ag2s.epublib.util.zip.ZipFileWrapper; + +/** + * @author jake + */ +public class EpubResourceProvider implements LazyResourceProvider { + + + private final ZipFileWrapper zipFileWrapper; + + + public EpubResourceProvider(ZipFileWrapper zipFileWrapper) { + this.zipFileWrapper = zipFileWrapper; + } + + + @Override + public InputStream getResourceStream(@NonNull String href) throws IOException { + + //ZipFile zipFile = new ZipFile(epubFilename); + ZipEntryWrapper zipEntry = zipFileWrapper.getEntry(href); + if (zipEntry == null) { + //zipFile.close(); + throw new IllegalStateException( + "Cannot find entry " + href + " in epub file " + zipFileWrapper); + } + return new ResourceInputStream(zipFileWrapper.getInputStream(zipEntry)); + } +} diff --git a/book/src/main/java/me/ag2s/epublib/domain/FileResourceProvider.java b/modules/book/src/main/java/me/ag2s/epublib/domain/FileResourceProvider.java similarity index 98% rename from book/src/main/java/me/ag2s/epublib/domain/FileResourceProvider.java rename to modules/book/src/main/java/me/ag2s/epublib/domain/FileResourceProvider.java index e273712d6..5a178dc99 100644 --- a/book/src/main/java/me/ag2s/epublib/domain/FileResourceProvider.java +++ b/modules/book/src/main/java/me/ag2s/epublib/domain/FileResourceProvider.java @@ -7,7 +7,6 @@ import java.io.InputStream; /** * 用于创建epub,添加大文件(如大量图片)时容易OOM,使用LazyResource,避免OOM. - * */ public class FileResourceProvider implements LazyResourceProvider { @@ -16,6 +15,7 @@ public class FileResourceProvider implements LazyResourceProvider { /** * 创建一个文件夹里面文件夹的LazyResourceProvider,用于LazyResource。 + * * @param parentDir 文件的目录 */ public FileResourceProvider(String parentDir) { @@ -24,6 +24,7 @@ public class FileResourceProvider implements LazyResourceProvider { /** * 创建一个文件夹里面文件夹的LazyResourceProvider,用于LazyResource。 + * * @param parentFile 文件夹 */ @SuppressWarnings("unused") @@ -33,6 +34,7 @@ public class FileResourceProvider implements LazyResourceProvider { /** * 根据子文件名href,再父目录下读取文件获取FileInputStream + * * @param href 子文件名href * @return 对应href的FileInputStream * @throws IOException 抛出IOException diff --git a/modules/book/src/main/java/me/ag2s/epublib/domain/Guide.java b/modules/book/src/main/java/me/ag2s/epublib/domain/Guide.java new file mode 100644 index 000000000..7d661f1f4 --- /dev/null +++ b/modules/book/src/main/java/me/ag2s/epublib/domain/Guide.java @@ -0,0 +1,128 @@ +package me.ag2s.epublib.domain; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * The guide is a selection of special pages of the book. + * Examples of these are the cover, list of illustrations, etc. + *

+ * It is an optional part of an epub, and support for the various types + * of references varies by reader. + *

+ * The only part of this that is heavily used is the cover page. + * + * @author paul + */ +public class Guide implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -6256645339915751189L; + + public static final String DEFAULT_COVER_TITLE = GuideReference.COVER; + + private List references = new ArrayList<>(); + private static final int COVERPAGE_NOT_FOUND = -1; + private static final int COVERPAGE_UNITIALIZED = -2; + + private int coverPageIndex = -1; + + public List getReferences() { + return references; + } + + public void setReferences(List references) { + this.references = references; + uncheckCoverPage(); + } + + private void uncheckCoverPage() { + coverPageIndex = COVERPAGE_UNITIALIZED; + } + + public GuideReference getCoverReference() { + checkCoverPage(); + if (coverPageIndex >= 0) { + return references.get(coverPageIndex); + } + return null; + } + + @SuppressWarnings("UnusedReturnValue") + public int setCoverReference(GuideReference guideReference) { + if (coverPageIndex >= 0) { + references.set(coverPageIndex, guideReference); + } else { + references.add(0, guideReference); + coverPageIndex = 0; + } + return coverPageIndex; + } + + private void checkCoverPage() { + if (coverPageIndex == COVERPAGE_UNITIALIZED) { + initCoverPage(); + } + } + + + private void initCoverPage() { + int result = COVERPAGE_NOT_FOUND; + for (int i = 0; i < references.size(); i++) { + GuideReference guideReference = references.get(i); + if (guideReference.getType().equals(GuideReference.COVER)) { + result = i; + break; + } + } + coverPageIndex = result; + } + + /** + * The coverpage of the book. + * + * @return The coverpage of the book. + */ + public Resource getCoverPage() { + GuideReference guideReference = getCoverReference(); + if (guideReference == null) { + return null; + } + return guideReference.getResource(); + } + + public void setCoverPage(Resource coverPage) { + GuideReference coverpageGuideReference = new GuideReference(coverPage, + GuideReference.COVER, DEFAULT_COVER_TITLE); + setCoverReference(coverpageGuideReference); + } + + @SuppressWarnings("UnusedReturnValue") + public ResourceReference addReference(GuideReference reference) { + this.references.add(reference); + uncheckCoverPage(); + return reference; + } + + /** + * A list of all GuideReferences that have the given + * referenceTypeName (ignoring case). + * + * @param referenceTypeName referenceTypeName + * @return A list of all GuideReferences that have the given + * referenceTypeName (ignoring case). + */ + public List getGuideReferencesByType( + String referenceTypeName) { + List result = new ArrayList<>(); + for (GuideReference guideReference : references) { + if (referenceTypeName.equalsIgnoreCase(guideReference.getType())) { + result.add(guideReference); + } + } + return result; + } +} diff --git a/modules/book/src/main/java/me/ag2s/epublib/domain/GuideReference.java b/modules/book/src/main/java/me/ag2s/epublib/domain/GuideReference.java new file mode 100644 index 000000000..eb8d0e806 --- /dev/null +++ b/modules/book/src/main/java/me/ag2s/epublib/domain/GuideReference.java @@ -0,0 +1,100 @@ +package me.ag2s.epublib.domain; + +import java.io.Serializable; + +import me.ag2s.epublib.util.StringUtil; + + +/** + * These are references to elements of the book's guide. + * + * @author paul + * @see Guide + */ +public class GuideReference extends TitledResourceReference + implements Serializable { + + private static final long serialVersionUID = -316179702440631834L; + + /** + * the book cover(s), jacket information, etc. + */ + public static final String COVER = "cover"; + + /** + * human-readable page with title, author, publisher, and other metadata + */ + public static String TITLE_PAGE = "title-page"; + + /** + * Human-readable table of contents. + * Not to be confused the epub file table of contents + */ + public static String TOC = "toc"; + + /** + * back-of-book style index + */ + public static String INDEX = "index"; + public static String GLOSSARY = "glossary"; + public static String ACKNOWLEDGEMENTS = "acknowledgements"; + public static String BIBLIOGRAPHY = "bibliography"; + public static String COLOPHON = "colophon"; + public static String COPYRIGHT_PAGE = "copyright-page"; + public static String DEDICATION = "dedication"; + + /** + * an epigraph is a phrase, quotation, or poem that is set at the + * beginning of a document or component. + *

+ * source: http://en.wikipedia.org/wiki/Epigraph_%28literature%29 + */ + public static String EPIGRAPH = "epigraph"; + + public static String FOREWORD = "foreword"; + + /** + * list of illustrations + */ + public static String LOI = "loi"; + + /** + * list of tables + */ + public static String LOT = "lot"; + public static String NOTES = "notes"; + public static String PREFACE = "preface"; + + /** + * A page of content (e.g. "Chapter 1") + */ + public static String TEXT = "text"; + + private String type; + + public GuideReference(Resource resource) { + this(resource, null); + } + + public GuideReference(Resource resource, String title) { + super(resource, title); + } + + public GuideReference(Resource resource, String type, String title) { + this(resource, type, title, null); + } + + public GuideReference(Resource resource, String type, String title, + String fragmentId) { + super(resource, title, fragmentId); + this.type = StringUtil.isNotBlank(type) ? type.toLowerCase() : null; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} diff --git a/modules/book/src/main/java/me/ag2s/epublib/domain/Identifier.java b/modules/book/src/main/java/me/ag2s/epublib/domain/Identifier.java new file mode 100644 index 000000000..b8f60e846 --- /dev/null +++ b/modules/book/src/main/java/me/ag2s/epublib/domain/Identifier.java @@ -0,0 +1,133 @@ +package me.ag2s.epublib.domain; + +import java.io.Serializable; +import java.util.List; +import java.util.UUID; + +import me.ag2s.epublib.util.StringUtil; + +/** + * A Book's identifier. + *

+ * Defaults to a random UUID and scheme "UUID" + * + * @author paul + */ +public class Identifier implements Serializable { + + private static final long serialVersionUID = 955949951416391810L; + + @SuppressWarnings("unused") + public interface Scheme { + + String UUID = "UUID"; + String ISBN = "ISBN"; + String URL = "URL"; + String URI = "URI"; + } + + private boolean bookId = false; + private String scheme; + private String value; + + /** + * Creates an Identifier with as value a random UUID and scheme "UUID" + */ + public Identifier() { + this(Scheme.UUID, UUID.randomUUID().toString()); + } + + + public Identifier(String scheme, String value) { + this.scheme = scheme; + this.value = value; + } + + /** + * The first identifier for which the bookId is true is made the + * bookId identifier. + *

+ * If no identifier has bookId == true then the first bookId identifier + * is written as the primary. + * + * @param identifiers i + * @return The first identifier for which the bookId is true is made + * the bookId identifier. + */ + public static Identifier getBookIdIdentifier(List identifiers) { + if (identifiers == null || identifiers.isEmpty()) { + return null; + } + + Identifier result = null; + for (Identifier identifier : identifiers) { + if (identifier.isBookId()) { + result = identifier; + break; + } + } + + if (result == null) { + result = identifiers.get(0); + } + + return result; + } + + public String getScheme() { + return scheme; + } + + public void setScheme(String scheme) { + this.scheme = scheme; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + + public void setBookId(boolean bookId) { + this.bookId = bookId; + } + + + /** + * This bookId property allows the book creator to add multiple ids and + * tell the epubwriter which one to write out as the bookId. + *

+ * The Dublin Core metadata spec allows multiple identifiers for a Book. + * The epub spec requires exactly one identifier to be marked as the book id. + * + * @return whether this is the unique book id. + */ + public boolean isBookId() { + return bookId; + } + + public int hashCode() { + return StringUtil.defaultIfNull(scheme).hashCode() ^ StringUtil + .defaultIfNull(value).hashCode(); + } + + public boolean equals(Object otherIdentifier) { + if (!(otherIdentifier instanceof Identifier)) { + return false; + } + return StringUtil.equals(scheme, ((Identifier) otherIdentifier).scheme) + && StringUtil.equals(value, ((Identifier) otherIdentifier).value); + } + + @SuppressWarnings("NullableProblems") + @Override + public String toString() { + if (StringUtil.isBlank(scheme)) { + return "" + value; + } + return "" + scheme + ":" + value; + } +} diff --git a/modules/book/src/main/java/me/ag2s/epublib/domain/LazyResource.java b/modules/book/src/main/java/me/ag2s/epublib/domain/LazyResource.java new file mode 100644 index 000000000..3492007f4 --- /dev/null +++ b/modules/book/src/main/java/me/ag2s/epublib/domain/LazyResource.java @@ -0,0 +1,145 @@ +package me.ag2s.epublib.domain; + +import android.util.Log; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import me.ag2s.epublib.util.IOUtil; + +/** + * A Resource that loads its data only on-demand from a EPUB book file. + * This way larger books can fit into memory and can be opened faster. + */ +public class LazyResource extends Resource { + + private static final long serialVersionUID = 5089400472352002866L; + private final String TAG = getClass().getName(); + + private final LazyResourceProvider resourceProvider; + private final long cachedSize; + + /** + * Creates a lazy resource, when the size is unknown. + * + * @param resourceProvider The resource provider loads data on demand. + * @param href The resource's href within the epub. + */ + public LazyResource(LazyResourceProvider resourceProvider, String href) { + this(resourceProvider, -1, href); + } + + public LazyResource(LazyResourceProvider resourceProvider, String href, String originalHref) { + this(resourceProvider, -1, href, originalHref); + } + + /** + * Creates a Lazy resource, by not actually loading the data for this entry. + *

+ * The data will be loaded on the first call to getData() + * + * @param resourceProvider The resource provider loads data on demand. + * @param size The size of this resource. + * @param href The resource's href within the epub. + */ + public LazyResource( + LazyResourceProvider resourceProvider, long size, String href) { + super(null, null, href, MediaTypes.determineMediaType(href)); + this.resourceProvider = resourceProvider; + this.cachedSize = size; + } + + public LazyResource( + LazyResourceProvider resourceProvider, long size, String href, String originalHref) { + super(null, null, href, originalHref, MediaTypes.determineMediaType(href)); + this.resourceProvider = resourceProvider; + this.cachedSize = size; + } + + /** + * Gets the contents of the Resource as an InputStream. + * + * @return The contents of the Resource. + * @throws IOException IOException + */ + public InputStream getInputStream() throws IOException { + if (isInitialized()) { + return new ByteArrayInputStream(getData()); + } else { + return resourceProvider.getResourceStream(this.originalHref); + } + } + + /** + * Initializes the resource by loading its data into memory. + * + * @throws IOException IOException + */ + public void initialize() throws IOException { + getData(); + } + + /** + * The contents of the resource as a byte[] + *

+ * If this resource was lazy-loaded and the data was not yet loaded, + * it will be loaded into memory at this point. + * This included opening the zip file, so expect a first load to be slow. + * + * @return The contents of the resource + */ + public byte[] getData() throws IOException { + + if (data == null) { + + Log.d(TAG, "Initializing lazy resource: " + this.getHref()); + + InputStream in = resourceProvider.getResourceStream(this.originalHref); + byte[] readData = IOUtil.toByteArray(in, (int) this.cachedSize); + if (readData == null) { + throw new IOException( + "Could not load the contents of resource: " + this.getHref()); + } else { + this.data = readData; + } + + in.close(); + } + + return data; + } + + /** + * Tells this resource to release its cached data. + *

+ * If this resource was not lazy-loaded, this is a no-op. + */ + public void close() { + if (this.resourceProvider != null) { + this.data = null; + } + } + + /** + * Returns if the data for this resource has been loaded into memory. + * + * @return true if data was loaded. + */ + public boolean isInitialized() { + return data != null; + } + + /** + * Returns the size of this resource in bytes. + * + * @return the size. + */ + public long getSize() { + if (data != null) { + return data.length; + } + + return cachedSize; + } +} diff --git a/book/src/main/java/me/ag2s/epublib/domain/LazyResourceProvider.java b/modules/book/src/main/java/me/ag2s/epublib/domain/LazyResourceProvider.java similarity index 70% rename from book/src/main/java/me/ag2s/epublib/domain/LazyResourceProvider.java rename to modules/book/src/main/java/me/ag2s/epublib/domain/LazyResourceProvider.java index 09b60e596..08e93e1a9 100644 --- a/book/src/main/java/me/ag2s/epublib/domain/LazyResourceProvider.java +++ b/modules/book/src/main/java/me/ag2s/epublib/domain/LazyResourceProvider.java @@ -8,5 +8,5 @@ import java.io.InputStream; */ public interface LazyResourceProvider { - InputStream getResourceStream(String href) throws IOException; + InputStream getResourceStream(String href) throws IOException; } diff --git a/modules/book/src/main/java/me/ag2s/epublib/domain/ManifestItemProperties.java b/modules/book/src/main/java/me/ag2s/epublib/domain/ManifestItemProperties.java new file mode 100644 index 000000000..ce8e91192 --- /dev/null +++ b/modules/book/src/main/java/me/ag2s/epublib/domain/ManifestItemProperties.java @@ -0,0 +1,22 @@ +package me.ag2s.epublib.domain; + +@SuppressWarnings("unused") +public enum ManifestItemProperties implements ManifestProperties { + COVER_IMAGE("cover-image"), + MATHML("mathml"), + NAV("nav"), + REMOTE_RESOURCES("remote-resources"), + SCRIPTED("scripted"), + SVG("svg"), + SWITCH("switch"); + + private final String name; + + ManifestItemProperties(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/modules/book/src/main/java/me/ag2s/epublib/domain/ManifestItemRefProperties.java b/modules/book/src/main/java/me/ag2s/epublib/domain/ManifestItemRefProperties.java new file mode 100644 index 000000000..d2143c49c --- /dev/null +++ b/modules/book/src/main/java/me/ag2s/epublib/domain/ManifestItemRefProperties.java @@ -0,0 +1,17 @@ +package me.ag2s.epublib.domain; + +@SuppressWarnings("unused") +public enum ManifestItemRefProperties implements ManifestProperties { + PAGE_SPREAD_LEFT("page-spread-left"), + PAGE_SPREAD_RIGHT("page-spread-right"); + + private final String name; + + ManifestItemRefProperties(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/book/src/main/java/me/ag2s/epublib/domain/ManifestProperties.java b/modules/book/src/main/java/me/ag2s/epublib/domain/ManifestProperties.java similarity index 77% rename from book/src/main/java/me/ag2s/epublib/domain/ManifestProperties.java rename to modules/book/src/main/java/me/ag2s/epublib/domain/ManifestProperties.java index 26892d7b0..5f57d67e7 100644 --- a/book/src/main/java/me/ag2s/epublib/domain/ManifestProperties.java +++ b/modules/book/src/main/java/me/ag2s/epublib/domain/ManifestProperties.java @@ -2,5 +2,5 @@ package me.ag2s.epublib.domain; public interface ManifestProperties { - String getName(); + String getName(); } diff --git a/modules/book/src/main/java/me/ag2s/epublib/domain/MediaType.java b/modules/book/src/main/java/me/ag2s/epublib/domain/MediaType.java new file mode 100644 index 000000000..26b9c1794 --- /dev/null +++ b/modules/book/src/main/java/me/ag2s/epublib/domain/MediaType.java @@ -0,0 +1,73 @@ +package me.ag2s.epublib.domain; + +import java.io.Serializable; +import java.util.Arrays; +import java.util.Collection; + +/** + * MediaType is used to tell the type of content a resource is. + *

+ * Examples of mediatypes are image/gif, text/css and application/xhtml+xml + *

+ * All allowed mediaTypes are maintained bye the MediaTypeService. + * + * @author paul + * @see MediaTypes + */ +public class MediaType implements Serializable { + + private static final long serialVersionUID = -7256091153727506788L; + private final String name; + private final String defaultExtension; + private final Collection extensions; + + public MediaType(String name, String defaultExtension) { + this(name, defaultExtension, new String[]{defaultExtension}); + } + + public MediaType(String name, String defaultExtension, + String[] extensions) { + this(name, defaultExtension, Arrays.asList(extensions)); + } + + public int hashCode() { + if (name == null) { + return 0; + } + return name.hashCode(); + } + + public MediaType(String name, String defaultExtension, + Collection mextensions) { + super(); + this.name = name; + this.defaultExtension = defaultExtension; + this.extensions = mextensions; + } + + public String getName() { + return name; + } + + + public String getDefaultExtension() { + return defaultExtension; + } + + + public Collection getExtensions() { + return extensions; + } + + public boolean equals(Object otherMediaType) { + if (!(otherMediaType instanceof MediaType)) { + return false; + } + return name.equals(((MediaType) otherMediaType).getName()); + } + + @SuppressWarnings("NullableProblems") + public String toString() { + return name; + } +} diff --git a/modules/book/src/main/java/me/ag2s/epublib/domain/MediaTypes.java b/modules/book/src/main/java/me/ag2s/epublib/domain/MediaTypes.java new file mode 100644 index 000000000..630545136 --- /dev/null +++ b/modules/book/src/main/java/me/ag2s/epublib/domain/MediaTypes.java @@ -0,0 +1,95 @@ +package me.ag2s.epublib.domain; + +import java.util.HashMap; +import java.util.Map; + +import me.ag2s.epublib.util.StringUtil; + + +/** + * Manages mediatypes that are used by epubs + * + * @author paul + */ +public class MediaTypes { + + public static final MediaType XHTML = new MediaType("application/xhtml+xml", + ".xhtml", new String[]{".htm", ".html", ".xhtml"}); + public static final MediaType EPUB = new MediaType("application/epub+zip", + ".epub"); + public static final MediaType NCX = new MediaType("application/x-dtbncx+xml", + ".ncx"); + + public static final MediaType JAVASCRIPT = new MediaType("text/javascript", + ".js"); + public static final MediaType CSS = new MediaType("text/css", ".css"); + + // images + public static final MediaType JPG = new MediaType("image/jpeg", ".jpg", + new String[]{".jpg", ".jpeg"}); + public static final MediaType PNG = new MediaType("image/png", ".png"); + public static final MediaType GIF = new MediaType("image/gif", ".gif"); + + public static final MediaType SVG = new MediaType("image/svg+xml", ".svg"); + + // fonts + public static final MediaType TTF = new MediaType( + "application/x-truetype-font", ".ttf"); + public static final MediaType OPENTYPE = new MediaType( + "application/vnd.ms-opentype", ".otf"); + public static final MediaType WOFF = new MediaType("application/font-woff", + ".woff"); + + // audio + public static final MediaType MP3 = new MediaType("audio/mpeg", ".mp3"); + public static final MediaType OGG = new MediaType("audio/ogg", ".ogg"); + + // video + public static final MediaType MP4 = new MediaType("video/mp4", ".mp4"); + + public static final MediaType SMIL = new MediaType("application/smil+xml", + ".smil"); + public static final MediaType XPGT = new MediaType( + "application/adobe-page-template+xml", ".xpgt"); + public static final MediaType PLS = new MediaType("application/pls+xml", + ".pls"); + + public static final MediaType[] mediaTypes = new MediaType[]{ + XHTML, EPUB, JPG, PNG, GIF, CSS, SVG, TTF, NCX, XPGT, OPENTYPE, WOFF, + SMIL, PLS, JAVASCRIPT, MP3, MP4, OGG + }; + + public static final Map mediaTypesByName = new HashMap<>(); + + static { + for (MediaType mediaType : mediaTypes) { + mediaTypesByName.put(mediaType.getName(), mediaType); + } + } + + public static boolean isBitmapImage(MediaType mediaType) { + return mediaType == JPG || mediaType == PNG || mediaType == GIF; + } + + /** + * Gets the MediaType based on the file extension. + * Null of no matching extension found. + * + * @param filename filename + * @return the MediaType based on the file extension. + */ + public static MediaType determineMediaType(String filename) { + for (MediaType mediaType : mediaTypesByName.values()) { + for (String extension : mediaType.getExtensions()) { + if (StringUtil.endsWithIgnoreCase(filename, extension)) { + return mediaType; + } + } + } + return null; + } + + public static MediaType getMediaTypeByName(String mediaTypeName) { + return mediaTypesByName.get(mediaTypeName); + } +} diff --git a/book/src/main/java/me/ag2s/epublib/domain/Metadata.java b/modules/book/src/main/java/me/ag2s/epublib/domain/Metadata.java similarity index 100% rename from book/src/main/java/me/ag2s/epublib/domain/Metadata.java rename to modules/book/src/main/java/me/ag2s/epublib/domain/Metadata.java diff --git a/modules/book/src/main/java/me/ag2s/epublib/domain/Relator.java b/modules/book/src/main/java/me/ag2s/epublib/domain/Relator.java new file mode 100644 index 000000000..8198bcf22 --- /dev/null +++ b/modules/book/src/main/java/me/ag2s/epublib/domain/Relator.java @@ -0,0 +1,1143 @@ +package me.ag2s.epublib.domain; + + +/** + * A relator denotes which role a certain individual had in the creation/modification of the ebook. + *

+ * Examples are 'creator', 'blurb writer', etc. + *

+ * This is contains the complete Library of Concress relator list. + * + * @author paul + * @see MARC Code List for Relators + */ +public enum Relator { + + /** + * Use for a person or organization who principally exhibits acting skills in a musical or dramatic presentation or entertainment. + */ + ACTOR("act", "Actor"), + + /** + * Use for a person or organization who 1) reworks a musical composition, usually for a different medium, or 2) rewrites novels or stories for motion pictures or other audiovisual medium. + */ + ADAPTER("adp", "Adapter"), + + /** + * Use for a person or organization that reviews, examines and interprets data or information in a specific area. + */ + ANALYST("anl", "Analyst"), + + /** + * Use for a person or organization who draws the two-dimensional figures, manipulates the three dimensional objects and/or also programs the computer to move objects and images for the purpose of animated film processing. Animation cameras, stands, celluloid screens, transparencies and inks are some of the tools of the animator. + */ + ANIMATOR("anm", "Animator"), + + /** + * Use for a person who writes manuscript annotations on a printed item. + */ + ANNOTATOR("ann", "Annotator"), + + /** + * Use for a person or organization responsible for the submission of an application or who is named as eligible for the results of the processing of the application (e.g., bestowing of rights, reward, title, position). + */ + APPLICANT("app", "Applicant"), + + /** + * Use for a person or organization who designs structures or oversees their construction. + */ + ARCHITECT("arc", "Architect"), + + /** + * Use for a person or organization who transcribes a musical composition, usually for a different medium from that of the original; in an arrangement the musical substance remains essentially unchanged. + */ + ARRANGER("arr", "Arranger"), + + /** + * Use for a person (e.g., a painter or sculptor) who makes copies of works of visual art. + */ + ART_COPYIST("acp", "Art copyist"), + + /** + * Use for a person (e.g., a painter) or organization who conceives, and perhaps also implements, an original graphic design or work of art, if specific codes (e.g., [egr], [etr]) are not desired. For book illustrators, prefer Illustrator [ill]. + */ + ARTIST("art", "Artist"), + + /** + * Use for a person responsible for controlling the development of the artistic style of an entire production, including the choice of works to be presented and selection of senior production staff. + */ + ARTISTIC_DIRECTOR("ard", "Artistic director"), + + /** + * Use for a person or organization to whom a license for printing or publishing has been transferred. + */ + ASSIGNEE("asg", "Assignee"), + + /** + * Use for a person or organization associated with or found in an item or collection, which cannot be determined to be that of a Former owner [fmo] or other designated relator indicative of provenance. + */ + ASSOCIATED_NAME("asn", "Associated name"), + + /** + * Use for an author, artist, etc., relating him/her to a work for which there is or once was substantial authority for designating that person as author, creator, etc. of the work. + */ + ATTRIBUTED_NAME("att", "Attributed name"), + + /** + * Use for a person or organization in charge of the estimation and public auctioning of goods, particularly books, artistic works, etc. + */ + AUCTIONEER("auc", "Auctioneer"), + + /** + * Use for a person or organization chiefly responsible for the intellectual or artistic content of a work, usually printed text. This term may also be used when more than one person or body bears such responsibility. + */ + AUTHOR("aut", "Author"), + + /** + * Use for a person or organization whose work is largely quoted or extracted in works to which he or she did not contribute directly. Such quotations are found particularly in exhibition catalogs, collections of photographs, etc. + */ + AUTHOR_IN_QUOTATIONS_OR_TEXT_EXTRACTS("aqt", + "Author in quotations or text extracts"), + + /** + * Use for a person or organization responsible for an afterword, postface, colophon, etc. but who is not the chief author of a work. + */ + AUTHOR_OF_AFTERWORD_COLOPHON_ETC("aft", + "Author of afterword, colophon, etc."), + + /** + * Use for a person or organization responsible for the dialog or spoken commentary for a screenplay or sound recording. + */ + AUTHOR_OF_DIALOG("aud", "Author of dialog"), + + /** + * Use for a person or organization responsible for an introduction, preface, foreword, or other critical introductory matter, but who is not the chief author. + */ + AUTHOR_OF_INTRODUCTION_ETC("aui", "Author of introduction, etc."), + + /** + * Use for a person or organization responsible for a motion picture screenplay, dialog, spoken commentary, etc. + */ + AUTHOR_OF_SCREENPLAY_ETC("aus", "Author of screenplay, etc."), + + /** + * Use for a person or organization responsible for a work upon which the work represented by the catalog record is based. This may be appropriate for adaptations, sequels, continuations, indexes, etc. + */ + BIBLIOGRAPHIC_ANTECEDENT("ant", "Bibliographic antecedent"), + + /** + * Use for a person or organization responsible for the binding of printed or manuscript materials. + */ + BINDER("bnd", "Binder"), + + /** + * Use for a person or organization responsible for the binding design of a book, including the type of binding, the type of materials used, and any decorative aspects of the binding. + */ + BINDING_DESIGNER("bdd", "Binding designer"), + + /** + * Use for the named entity responsible for writing a commendation or testimonial for a work, which appears on or within the publication itself, frequently on the back or dust jacket of print publications or on advertising material for all media. + */ + BLURB_WRITER("blw", "Blurb writer"), + + /** + * Use for a person or organization responsible for the entire graphic design of a book, including arrangement of type and illustration, choice of materials, and process used. + */ + BOOK_DESIGNER("bkd", "Book designer"), + + /** + * Use for a person or organization responsible for the production of books and other print media, if specific codes (e.g., [bkd], [egr], [tyd], [prt]) are not desired. + */ + BOOK_PRODUCER("bkp", "Book producer"), + + /** + * Use for a person or organization responsible for the design of flexible covers designed for or published with a book, including the type of materials used, and any decorative aspects of the bookjacket. + */ + BOOKJACKET_DESIGNER("bjd", "Bookjacket designer"), + + /** + * Use for a person or organization responsible for the design of a book owner's identification label that is most commonly pasted to the inside front cover of a book. + */ + BOOKPLATE_DESIGNER("bpd", "Bookplate designer"), + + /** + * Use for a person or organization who makes books and other bibliographic materials available for purchase. Interest in the materials is primarily lucrative. + */ + BOOKSELLER("bsl", "Bookseller"), + + /** + * Use for a person or organization who writes in an artistic hand, usually as a copyist and or engrosser. + */ + CALLIGRAPHER("cll", "Calligrapher"), + + /** + * Use for a person or organization responsible for the creation of maps and other cartographic materials. + */ + CARTOGRAPHER("ctg", "Cartographer"), + + /** + * Use for a censor, bowdlerizer, expurgator, etc., official or private. + */ + CENSOR("cns", "Censor"), + + /** + * Use for a person or organization who composes or arranges dances or other movements (e.g., "master of swords") for a musical or dramatic presentation or entertainment. + */ + CHOREOGRAPHER("chr", "Choreographer"), + + /** + * Use for a person or organization who is in charge of the images captured for a motion picture film. The cinematographer works under the supervision of a director, and may also be referred to as director of photography. Do not confuse with videographer. + */ + CINEMATOGRAPHER("cng", "Cinematographer"), + + /** + * Use for a person or organization for whom another person or organization is acting. + */ + CLIENT("cli", "Client"), + + /** + * Use for a person or organization that takes a limited part in the elaboration of a work of another person or organization that brings complements (e.g., appendices, notes) to the work. + */ + COLLABORATOR("clb", "Collaborator"), + + /** + * Use for a person or organization who has brought together material from various sources that has been arranged, described, and cataloged as a collection. A collector is neither the creator of the material nor a person to whom manuscripts in the collection may have been addressed. + */ + COLLECTOR("col", "Collector"), + + /** + * Use for a person or organization responsible for the production of photographic prints from film or other colloid that has ink-receptive and ink-repellent surfaces. + */ + COLLOTYPER("clt", "Collotyper"), + + /** + * Use for the named entity responsible for applying color to drawings, prints, photographs, maps, moving images, etc. + */ + COLORIST("clr", "Colorist"), + + /** + * Use for a person or organization who provides interpretation, analysis, or a discussion of the subject matter on a recording, motion picture, or other audiovisual medium. + */ + COMMENTATOR("cmm", "Commentator"), + + /** + * Use for a person or organization responsible for the commentary or explanatory notes about a text. For the writer of manuscript annotations in a printed book, use Annotator [ann]. + */ + COMMENTATOR_FOR_WRITTEN_TEXT("cwt", "Commentator for written text"), + + /** + * Use for a person or organization who produces a work or publication by selecting and putting together material from the works of various persons or bodies. + */ + COMPILER("com", "Compiler"), + + /** + * Use for the party who applies to the courts for redress, usually in an equity proceeding. + */ + COMPLAINANT("cpl", "Complainant"), + + /** + * Use for a complainant who takes an appeal from one court or jurisdiction to another to reverse the judgment, usually in an equity proceeding. + */ + COMPLAINANT_APPELLANT("cpt", "Complainant-appellant"), + + /** + * Use for a complainant against whom an appeal is taken from one court or jurisdiction to another to reverse the judgment, usually in an equity proceeding. + */ + COMPLAINANT_APPELLEE("cpe", "Complainant-appellee"), + + /** + * Use for a person or organization who creates a musical work, usually a piece of music in manuscript or printed form. + */ + COMPOSER("cmp", "Composer"), + + /** + * Use for a person or organization responsible for the creation of metal slug, or molds made of other materials, used to produce the text and images in printed matter. + */ + COMPOSITOR("cmt", "Compositor"), + + /** + * Use for a person or organization responsible for the original idea on which a work is based, this includes the scientific author of an audio-visual item and the conceptor of an advertisement. + */ + CONCEPTOR("ccp", "Conceptor"), + + /** + * Use for a person who directs a performing group (orchestra, chorus, opera, etc.) in a musical or dramatic presentation or entertainment. + */ + CONDUCTOR("cnd", "Conductor"), + + /** + * Use for the named entity responsible for documenting, preserving, or treating printed or manuscript material, works of art, artifacts, or other media. + */ + CONSERVATOR("con", "Conservator"), + + /** + * Use for a person or organization relevant to a resource, who is called upon for professional advice or services in a specialized field of knowledge or training. + */ + CONSULTANT("csl", "Consultant"), + + /** + * Use for a person or organization relevant to a resource, who is engaged specifically to provide an intellectual overview of a strategic or operational task and by analysis, specification, or instruction, to create or propose a cost-effective course of action or solution. + */ + CONSULTANT_TO_A_PROJECT("csp", "Consultant to a project"), + + /** + * Use for the party who opposes, resists, or disputes, in a court of law, a claim, decision, result, etc. + */ + CONTESTANT("cos", "Contestant"), + + /** + * Use for a contestant who takes an appeal from one court of law or jurisdiction to another to reverse the judgment. + */ + CONTESTANT_APPELLANT("cot", "Contestant-appellant"), + + /** + * Use for a contestant against whom an appeal is taken from one court of law or jurisdiction to another to reverse the judgment. + */ + CONTESTANT_APPELLEE("coe", "Contestant-appellee"), + + /** + * Use for the party defending a claim, decision, result, etc. being opposed, resisted, or disputed in a court of law. + */ + CONTESTEE("cts", "Contestee"), + + /** + * Use for a contestee who takes an appeal from one court or jurisdiction to another to reverse the judgment. + */ + CONTESTEE_APPELLANT("ctt", "Contestee-appellant"), + + /** + * Use for a contestee against whom an appeal is taken from one court or jurisdiction to another to reverse the judgment. + */ + CONTESTEE_APPELLEE("cte", "Contestee-appellee"), + + /** + * Use for a person or organization relevant to a resource, who enters into a contract with another person or organization to perform a specific task. + */ + CONTRACTOR("ctr", "Contractor"), + + /** + * Use for a person or organization one whose work has been contributed to a larger work, such as an anthology, serial publication, or other compilation of individual works. Do not use if the sole function in relation to a work is as author, editor, compiler or translator. + */ + CONTRIBUTOR("ctb", "Contributor"), + + /** + * Use for a person or organization listed as a copyright owner at the time of registration. Copyright can be granted or later transferred to another person or organization, at which time the claimant becomes the copyright holder. + */ + COPYRIGHT_CLAIMANT("cpc", "Copyright claimant"), + + /** + * Use for a person or organization to whom copy and legal rights have been granted or transferred for the intellectual content of a work. The copyright holder, although not necessarily the creator of the work, usually has the exclusive right to benefit financially from the sale and use of the work to which the associated copyright protection applies. + */ + COPYRIGHT_HOLDER("cph", "Copyright holder"), + + /** + * Use for a person or organization who is a corrector of manuscripts, such as the scriptorium official who corrected the work of a scribe. For printed matter, use Proofreader. + */ + CORRECTOR("crr", "Corrector"), + + /** + * Use for a person or organization who was either the writer or recipient of a letter or other communication. + */ + CORRESPONDENT("crp", "Correspondent"), + + /** + * Use for a person or organization who designs or makes costumes, fixes hair, etc., for a musical or dramatic presentation or entertainment. + */ + COSTUME_DESIGNER("cst", "Costume designer"), + + /** + * Use for a person or organization responsible for the graphic design of a book cover, album cover, slipcase, box, container, etc. For a person or organization responsible for the graphic design of an entire book, use Book designer; for book jackets, use Bookjacket designer. + */ + COVER_DESIGNER("cov", "Cover designer"), + + /** + * Use for a person or organization responsible for the intellectual or artistic content of a work. + */ + CREATOR("cre", "Creator"), + + /** + * Use for a person or organization responsible for conceiving and organizing an exhibition. + */ + CURATOR_OF_AN_EXHIBITION("cur", "Curator of an exhibition"), + + /** + * Use for a person or organization who principally exhibits dancing skills in a musical or dramatic presentation or entertainment. + */ + DANCER("dnc", "Dancer"), + + /** + * Use for a person or organization that submits data for inclusion in a database or other collection of data. + */ + DATA_CONTRIBUTOR("dtc", "Data contributor"), + + /** + * Use for a person or organization responsible for managing databases or other data sources. + */ + DATA_MANAGER("dtm", "Data manager"), + + /** + * Use for a person or organization to whom a book, manuscript, etc., is dedicated (not the recipient of a gift). + */ + DEDICATEE("dte", "Dedicatee"), + + /** + * Use for the author of a dedication, which may be a formal statement or in epistolary or verse form. + */ + DEDICATOR("dto", "Dedicator"), + + /** + * Use for the party defending or denying allegations made in a suit and against whom relief or recovery is sought in the courts, usually in a legal action. + */ + DEFENDANT("dfd", "Defendant"), + + /** + * Use for a defendant who takes an appeal from one court or jurisdiction to another to reverse the judgment, usually in a legal action. + */ + DEFENDANT_APPELLANT("dft", "Defendant-appellant"), + + /** + * Use for a defendant against whom an appeal is taken from one court or jurisdiction to another to reverse the judgment, usually in a legal action. + */ + DEFENDANT_APPELLEE("dfe", "Defendant-appellee"), + + /** + * Use for the organization granting a degree for which the thesis or dissertation described was presented. + */ + DEGREE_GRANTOR("dgg", "Degree grantor"), + + /** + * Use for a person or organization executing technical drawings from others' designs. + */ + DELINEATOR("dln", "Delineator"), + + /** + * Use for an entity depicted or portrayed in a work, particularly in a work of art. + */ + DEPICTED("dpc", "Depicted"), + + /** + * Use for a person or organization placing material in the physical custody of a library or repository without transferring the legal title. + */ + DEPOSITOR("dpt", "Depositor"), + + /** + * Use for a person or organization responsible for the design if more specific codes (e.g., [bkd], [tyd]) are not desired. + */ + DESIGNER("dsr", "Designer"), + + /** + * Use for a person or organization who is responsible for the general management of a work or who supervises the production of a performance for stage, screen, or sound recording. + */ + DIRECTOR("drt", "Director"), + + /** + * Use for a person who presents a thesis for a university or higher-level educational degree. + */ + DISSERTANT("dis", "Dissertant"), + + /** + * Use for the name of a place from which a resource, e.g., a serial, is distributed. + */ + DISTRIBUTION_PLACE("dbp", "Distribution place"), + + /** + * Use for a person or organization that has exclusive or shared marketing rights for an item. + */ + DISTRIBUTOR("dst", "Distributor"), + + /** + * Use for a person or organization who is the donor of a book, manuscript, etc., to its present owner. Donors to previous owners are designated as Former owner [fmo] or Inscriber [ins]. + */ + DONOR("dnr", "Donor"), + + /** + * Use for a person or organization who prepares artistic or technical drawings. + */ + DRAFTSMAN("drm", "Draftsman"), + + /** + * Use for a person or organization to which authorship has been dubiously or incorrectly ascribed. + */ + DUBIOUS_AUTHOR("dub", "Dubious author"), + + /** + * Use for a person or organization who prepares for publication a work not primarily his/her own, such as by elucidating text, adding introductory or other critical matter, or technically directing an editorial staff. + */ + EDITOR("edt", "Editor"), + + /** + * Use for a person responsible for setting up a lighting rig and focusing the lights for a production, and running the lighting at a performance. + */ + ELECTRICIAN("elg", "Electrician"), + + /** + * Use for a person or organization who creates a duplicate printing surface by pressure molding and electrodepositing of metal that is then backed up with lead for printing. + */ + ELECTROTYPER("elt", "Electrotyper"), + + /** + * Use for a person or organization that is responsible for technical planning and design, particularly with construction. + */ + ENGINEER("eng", "Engineer"), + + /** + * Use for a person or organization who cuts letters, figures, etc. on a surface, such as a wooden or metal plate, for printing. + */ + ENGRAVER("egr", "Engraver"), + + /** + * Use for a person or organization who produces text or images for printing by subjecting metal, glass, or some other surface to acid or the corrosive action of some other substance. + */ + ETCHER("etr", "Etcher"), + + /** + * Use for the name of the place where an event such as a conference or a concert took place. + */ + EVENT_PLACE("evp", "Event place"), + + /** + * Use for a person or organization in charge of the description and appraisal of the value of goods, particularly rare items, works of art, etc. + */ + EXPERT("exp", "Expert"), + + /** + * Use for a person or organization that executed the facsimile. + */ + FACSIMILIST("fac", "Facsimilist"), + + /** + * Use for a person or organization that manages or supervises the work done to collect raw data or do research in an actual setting or environment (typically applies to the natural and social sciences). + */ + FIELD_DIRECTOR("fld", "Field director"), + + /** + * Use for a person or organization who is an editor of a motion picture film. This term is used regardless of the medium upon which the motion picture is produced or manufactured (e.g., acetate film, video tape). + */ + FILM_EDITOR("flm", "Film editor"), + + /** + * Use for a person or organization who is identified as the only party or the party of the first part. In the case of transfer of right, this is the assignor, transferor, licensor, grantor, etc. Multiple parties can be named jointly as the first party + */ + FIRST_PARTY("fpy", "First party"), + + /** + * Use for a person or organization who makes or imitates something of value or importance, especially with the intent to defraud. + */ + FORGER("frg", "Forger"), + + /** + * Use for a person or organization who owned an item at any time in the past. Includes those to whom the material was once presented. A person or organization giving the item to the present owner is designated as Donor [dnr] + */ + FORMER_OWNER("fmo", "Former owner"), + + /** + * Use for a person or organization that furnished financial support for the production of the work. + */ + FUNDER("fnd", "Funder"), + + /** + * Use for a person responsible for geographic information system (GIS) development and integration with global positioning system data. + */ + GEOGRAPHIC_INFORMATION_SPECIALIST("gis", "Geographic information specialist"), + + /** + * Use for a person or organization in memory or honor of whom a book, manuscript, etc. is donated. + */ + HONOREE("hnr", "Honoree"), + + /** + * Use for a person who is invited or regularly leads a program (often broadcast) that includes other guests, performers, etc. (e.g., talk show host). + */ + HOST("hst", "Host"), + + /** + * Use for a person or organization responsible for the decoration of a work (especially manuscript material) with precious metals or color, usually with elaborate designs and motifs. + */ + ILLUMINATOR("ilu", "Illuminator"), + + /** + * Use for a person or organization who conceives, and perhaps also implements, a design or illustration, usually to accompany a written text. + */ + ILLUSTRATOR("ill", "Illustrator"), + + /** + * Use for a person who signs a presentation statement. + */ + INSCRIBER("ins", "Inscriber"), + + /** + * Use for a person or organization who principally plays an instrument in a musical or dramatic presentation or entertainment. + */ + INSTRUMENTALIST("itr", "Instrumentalist"), + + /** + * Use for a person or organization who is interviewed at a consultation or meeting, usually by a reporter, pollster, or some other information gathering agent. + */ + INTERVIEWEE("ive", "Interviewee"), + + /** + * Use for a person or organization who acts as a reporter, pollster, or other information gathering agent in a consultation or meeting involving one or more individuals. + */ + INTERVIEWER("ivr", "Interviewer"), + + /** + * Use for a person or organization who first produces a particular useful item, or develops a new process for obtaining a known item or result. + */ + INVENTOR("inv", "Inventor"), + + /** + * Use for an institution that provides scientific analyses of material samples. + */ + LABORATORY("lbr", "Laboratory"), + + /** + * Use for a person or organization that manages or supervises work done in a controlled setting or environment. + */ + LABORATORY_DIRECTOR("ldr", "Laboratory director"), + + /** + * Use for a person or organization whose work involves coordinating the arrangement of existing and proposed land features and structures. + */ + LANDSCAPE_ARCHITECT("lsa", "Landscape architect"), + + /** + * Use to indicate that a person or organization takes primary responsibility for a particular activity or endeavor. Use with another relator term or code to show the greater importance this person or organization has regarding that particular role. If more than one relator is assigned to a heading, use the Lead relator only if it applies to all the relators. + */ + LEAD("led", "Lead"), + + /** + * Use for a person or organization permitting the temporary use of a book, manuscript, etc., such as for photocopying or microfilming. + */ + LENDER("len", "Lender"), + + /** + * Use for the party who files a libel in an ecclesiastical or admiralty case. + */ + LIBELANT("lil", "Libelant"), + + /** + * Use for a libelant who takes an appeal from one ecclesiastical court or admiralty to another to reverse the judgment. + */ + LIBELANT_APPELLANT("lit", "Libelant-appellant"), + + /** + * Use for a libelant against whom an appeal is taken from one ecclesiastical court or admiralty to another to reverse the judgment. + */ + LIBELANT_APPELLEE("lie", "Libelant-appellee"), + + /** + * Use for a party against whom a libel has been filed in an ecclesiastical court or admiralty. + */ + LIBELEE("lel", "Libelee"), + + /** + * Use for a libelee who takes an appeal from one ecclesiastical court or admiralty to another to reverse the judgment. + */ + LIBELEE_APPELLANT("let", "Libelee-appellant"), + + /** + * Use for a libelee against whom an appeal is taken from one ecclesiastical court or admiralty to another to reverse the judgment. + */ + LIBELEE_APPELLEE("lee", "Libelee-appellee"), + + /** + * Use for a person or organization who is a writer of the text of an opera, oratorio, etc. + */ + LIBRETTIST("lbt", "Librettist"), + + /** + * Use for a person or organization who is an original recipient of the right to print or publish. + */ + LICENSEE("lse", "Licensee"), + + /** + * Use for person or organization who is a signer of the license, imprimatur, etc. + */ + LICENSOR("lso", "Licensor"), + + /** + * Use for a person or organization who designs the lighting scheme for a theatrical presentation, entertainment, motion picture, etc. + */ + LIGHTING_DESIGNER("lgd", "Lighting designer"), + + /** + * Use for a person or organization who prepares the stone or plate for lithographic printing, including a graphic artist creating a design directly on the surface from which printing will be done. + */ + LITHOGRAPHER("ltg", "Lithographer"), + + /** + * Use for a person or organization who is a writer of the text of a song. + */ + LYRICIST("lyr", "Lyricist"), + + /** + * Use for a person or organization that makes an artifactual work (an object made or modified by one or more persons). Examples of artifactual works include vases, cannons or pieces of furniture. + */ + MANUFACTURER("mfr", "Manufacturer"), + + /** + * Use for the named entity responsible for marbling paper, cloth, leather, etc. used in construction of a resource. + */ + MARBLER("mrb", "Marbler"), + + /** + * Use for a person or organization performing the coding of SGML, HTML, or XML markup of metadata, text, etc. + */ + MARKUP_EDITOR("mrk", "Markup editor"), + + /** + * Use for a person or organization primarily responsible for compiling and maintaining the original description of a metadata set (e.g., geospatial metadata set). + */ + METADATA_CONTACT("mdc", "Metadata contact"), + + /** + * Use for a person or organization responsible for decorations, illustrations, letters, etc. cut on a metal surface for printing or decoration. + */ + METAL_ENGRAVER("mte", "Metal-engraver"), + + /** + * Use for a person who leads a program (often broadcast) where topics are discussed, usually with participation of experts in fields related to the discussion. + */ + MODERATOR("mod", "Moderator"), + + /** + * Use for a person or organization that supervises compliance with the contract and is responsible for the report and controls its distribution. Sometimes referred to as the grantee, or controlling agency. + */ + MONITOR("mon", "Monitor"), + + /** + * Use for a person who transcribes or copies musical notation + */ + MUSIC_COPYIST("mcp", "Music copyist"), + + /** + * Use for a person responsible for basic music decisions about a production, including coordinating the work of the composer, the sound editor, and sound mixers, selecting musicians, and organizing and/or conducting sound for rehearsals and performances. + */ + MUSICAL_DIRECTOR("msd", "Musical director"), + + /** + * Use for a person or organization who performs music or contributes to the musical content of a work when it is not possible or desirable to identify the function more precisely. + */ + MUSICIAN("mus", "Musician"), + + /** + * Use for a person who is a speaker relating the particulars of an act, occurrence, or course of events. + */ + NARRATOR("nrt", "Narrator"), + + /** + * Use for a person or organization responsible for opposing a thesis or dissertation. + */ + OPPONENT("opn", "Opponent"), + + /** + * Use for a person or organization responsible for organizing a meeting for which an item is the report or proceedings. + */ + ORGANIZER_OF_MEETING("orm", "Organizer of meeting"), + + /** + * Use for a person or organization performing the work, i.e., the name of a person or organization associated with the intellectual content of the work. This category does not include the publisher or personal affiliation, or sponsor except where it is also the corporate author. + */ + ORIGINATOR("org", "Originator"), + + /** + * Use for relator codes from other lists which have no equivalent in the MARC list or for terms which have not been assigned a code. + */ + OTHER("oth", "Other"), + + /** + * Use for a person or organization that currently owns an item or collection. + */ + OWNER("own", "Owner"), + + /** + * Use for a person or organization responsible for the production of paper, usually from wood, cloth, or other fibrous material. + */ + PAPERMAKER("ppm", "Papermaker"), + + /** + * Use for a person or organization that applied for a patent. + */ + PATENT_APPLICANT("pta", "Patent applicant"), + + /** + * Use for a person or organization that was granted the patent referred to by the item. + */ + PATENT_HOLDER("pth", "Patent holder"), + + /** + * Use for a person or organization responsible for commissioning a work. Usually a patron uses his or her means or influence to support the work of artists, writers, etc. This includes those who commission and pay for individual works. + */ + PATRON("pat", "Patron"), + + /** + * Use for a person or organization who exhibits musical or acting skills in a musical or dramatic presentation or entertainment, if specific codes for those functions ([act], [dnc], [itr], [voc], etc.) are not used. If specific codes are used, [prf] is used for a person whose principal skill is not known or specified. + */ + PERFORMER("prf", "Performer"), + + /** + * Use for an authority (usually a government agency) that issues permits under which work is accomplished. + */ + PERMITTING_AGENCY("pma", "Permitting agency"), + + /** + * Use for a person or organization responsible for taking photographs, whether they are used in their original form or as reproductions. + */ + PHOTOGRAPHER("pht", "Photographer"), + + /** + * Use for the party who complains or sues in court in a personal action, usually in a legal proceeding. + */ + PLAINTIFF("ptf", "Plaintiff"), + + /** + * Use for a plaintiff who takes an appeal from one court or jurisdiction to another to reverse the judgment, usually in a legal proceeding. + */ + PLAINTIFF_APPELLANT("ptt", "Plaintiff-appellant"), + + /** + * Use for a plaintiff against whom an appeal is taken from one court or jurisdiction to another to reverse the judgment, usually in a legal proceeding. + */ + PLAINTIFF_APPELLEE("pte", "Plaintiff-appellee"), + + /** + * Use for a person or organization responsible for the production of plates, usually for the production of printed images and/or text. + */ + PLATEMAKER("plt", "Platemaker"), + + /** + * Use for a person or organization who prints texts, whether from type or plates. + */ + PRINTER("prt", "Printer"), + + /** + * Use for a person or organization who prints illustrations from plates. + */ + PRINTER_OF_PLATES("pop", "Printer of plates"), + + /** + * Use for a person or organization who makes a relief, intaglio, or planographic printing surface. + */ + PRINTMAKER("prm", "Printmaker"), + + /** + * Use for a person or organization primarily responsible for performing or initiating a process, such as is done with the collection of metadata sets. + */ + PROCESS_CONTACT("prc", "Process contact"), + + /** + * Use for a person or organization responsible for the making of a motion picture, including business aspects, management of the productions, and the commercial success of the work. + */ + PRODUCER("pro", "Producer"), + + /** + * Use for a person responsible for all technical and business matters in a production. + */ + PRODUCTION_MANAGER("pmn", "Production manager"), + + /** + * Use for a person or organization associated with the production (props, lighting, special effects, etc.) of a musical or dramatic presentation or entertainment. + */ + PRODUCTION_PERSONNEL("prd", "Production personnel"), + + /** + * Use for a person or organization responsible for the creation and/or maintenance of computer program design documents, source code, and machine-executable digital files and supporting documentation. + */ + PROGRAMMER("prg", "Programmer"), + + /** + * Use for a person or organization with primary responsibility for all essential aspects of a project, or that manages a very large project that demands senior level responsibility, or that has overall responsibility for managing projects, or provides overall direction to a project manager. + */ + PROJECT_DIRECTOR("pdr", "Project director"), + + /** + * Use for a person who corrects printed matter. For manuscripts, use Corrector [crr]. + */ + PROOFREADER("pfr", "Proofreader"), + + /** + * Use for the name of the place where a resource is published. + */ + PUBLICATION_PLACE("pup", "Publication place"), + + /** + * Use for a person or organization that makes printed matter, often text, but also printed music, artwork, etc. available to the public. + */ + PUBLISHER("pbl", "Publisher"), + + /** + * Use for a person or organization who presides over the elaboration of a collective work to ensure its coherence or continuity. This includes editors-in-chief, literary editors, editors of series, etc. + */ + PUBLISHING_DIRECTOR("pbd", "Publishing director"), + + /** + * Use for a person or organization who manipulates, controls, or directs puppets or marionettes in a musical or dramatic presentation or entertainment. + */ + PUPPETEER("ppt", "Puppeteer"), + + /** + * Use for a person or organization to whom correspondence is addressed. + */ + RECIPIENT("rcp", "Recipient"), + + /** + * Use for a person or organization who supervises the technical aspects of a sound or video recording session. + */ + RECORDING_ENGINEER("rce", "Recording engineer"), + + /** + * Use for a person or organization who writes or develops the framework for an item without being intellectually responsible for its content. + */ + REDACTOR("red", "Redactor"), + + /** + * Use for a person or organization who prepares drawings of architectural designs (i.e., renderings) in accurate, representational perspective to show what the project will look like when completed. + */ + RENDERER("ren", "Renderer"), + + /** + * Use for a person or organization who writes or presents reports of news or current events on air or in print. + */ + REPORTER("rpt", "Reporter"), + + /** + * Use for an agency that hosts data or material culture objects and provides services to promote long term, consistent and shared use of those data or objects. + */ + REPOSITORY("rps", "Repository"), + + /** + * Use for a person who directed or managed a research project. + */ + RESEARCH_TEAM_HEAD("rth", "Research team head"), + + /** + * Use for a person who participated in a research project but whose role did not involve direction or management of it. + */ + RESEARCH_TEAM_MEMBER("rtm", "Research team member"), + + /** + * Use for a person or organization responsible for performing research. + */ + RESEARCHER("res", "Researcher"), + + /** + * Use for the party who makes an answer to the courts pursuant to an application for redress, usually in an equity proceeding. + */ + RESPONDENT("rsp", "Respondent"), + + /** + * Use for a respondent who takes an appeal from one court or jurisdiction to another to reverse the judgment, usually in an equity proceeding. + */ + RESPONDENT_APPELLANT("rst", "Respondent-appellant"), + + /** + * Use for a respondent against whom an appeal is taken from one court or jurisdiction to another to reverse the judgment, usually in an equity proceeding. + */ + RESPONDENT_APPELLEE("rse", "Respondent-appellee"), + + /** + * Use for a person or organization legally responsible for the content of the published material. + */ + RESPONSIBLE_PARTY("rpy", "Responsible party"), + + /** + * Use for a person or organization, other than the original choreographer or director, responsible for restaging a choreographic or dramatic work and who contributes minimal new content. + */ + RESTAGER("rsg", "Restager"), + + /** + * Use for a person or organization responsible for the review of a book, motion picture, performance, etc. + */ + REVIEWER("rev", "Reviewer"), + + /** + * Use for a person or organization responsible for parts of a work, often headings or opening parts of a manuscript, that appear in a distinctive color, usually red. + */ + RUBRICATOR("rbr", "Rubricator"), + + /** + * Use for a person or organization who is the author of a motion picture screenplay. + */ + SCENARIST("sce", "Scenarist"), + + /** + * Use for a person or organization who brings scientific, pedagogical, or historical competence to the conception and realization on a work, particularly in the case of audio-visual items. + */ + SCIENTIFIC_ADVISOR("sad", "Scientific advisor"), + + /** + * Use for a person who is an amanuensis and for a writer of manuscripts proper. For a person who makes pen-facsimiles, use Facsimilist [fac]. + */ + SCRIBE("scr", "Scribe"), + + /** + * Use for a person or organization who models or carves figures that are three-dimensional representations. + */ + SCULPTOR("scl", "Sculptor"), + + /** + * Use for a person or organization who is identified as the party of the second part. In the case of transfer of right, this is the assignee, transferee, licensee, grantee, etc. Multiple parties can be named jointly as the second party. + */ + SECOND_PARTY("spy", "Second party"), + + /** + * Use for a person or organization who is a recorder, redactor, or other person responsible for expressing the views of a organization. + */ + SECRETARY("sec", "Secretary"), + + /** + * Use for a person or organization who translates the rough sketches of the art director into actual architectural structures for a theatrical presentation, entertainment, motion picture, etc. Set designers draw the detailed guides and specifications for building the set. + */ + SET_DESIGNER("std", "Set designer"), + + /** + * Use for a person whose signature appears without a presentation or other statement indicative of provenance. When there is a presentation statement, use Inscriber [ins]. + */ + SIGNER("sgn", "Signer"), + + /** + * Use for a person or organization who uses his/her/their voice with or without instrumental accompaniment to produce music. A performance may or may not include actual words. + */ + SINGER("sng", "Singer"), + + /** + * Use for a person who produces and reproduces the sound score (both live and recorded), the installation of microphones, the setting of sound levels, and the coordination of sources of sound for a production. + */ + SOUND_DESIGNER("sds", "Sound designer"), + + /** + * Use for a person who participates in a program (often broadcast) and makes a formalized contribution or presentation generally prepared in advance. + */ + SPEAKER("spk", "Speaker"), + + /** + * Use for a person or organization that issued a contract or under the auspices of which a work has been written, printed, published, etc. + */ + SPONSOR("spn", "Sponsor"), + + /** + * Use for a person who is in charge of everything that occurs on a performance stage, and who acts as chief of all crews and assistant to a director during rehearsals. + */ + STAGE_MANAGER("stm", "Stage manager"), + + /** + * Use for an organization responsible for the development or enforcement of a standard. + */ + STANDARDS_BODY("stn", "Standards body"), + + /** + * Use for a person or organization who creates a new plate for printing by molding or copying another printing surface. + */ + STEREOTYPER("str", "Stereotyper"), + + /** + * Use for a person relaying a story with creative and/or theatrical interpretation. + */ + STORYTELLER("stl", "Storyteller"), + + /** + * Use for a person or organization that supports (by allocating facilities, staff, or other resources) a project, program, meeting, event, data objects, material culture objects, or other entities capable of support. + */ + SUPPORTING_HOST("sht", "Supporting host"), + + /** + * Use for a person or organization who does measurements of tracts of land, etc. to determine location, forms, and boundaries. + */ + SURVEYOR("srv", "Surveyor"), + + /** + * Use for a person who, in the context of a resource, gives instruction in an intellectual subject or demonstrates while teaching physical skills. + */ + TEACHER("tch", "Teacher"), + + /** + * Use for a person who is ultimately in charge of scenery, props, lights and sound for a production. + */ + TECHNICAL_DIRECTOR("tcd", "Technical director"), + + /** + * Use for a person under whose supervision a degree candidate develops and presents a thesis, mémoire, or text of a dissertation. + */ + THESIS_ADVISOR("ths", "Thesis advisor"), + + /** + * Use for a person who prepares a handwritten or typewritten copy from original material, including from dictated or orally recorded material. For makers of pen-facsimiles, use Facsimilist [fac]. + */ + TRANSCRIBER("trc", "Transcriber"), + + /** + * Use for a person or organization who renders a text from one language into another, or from an older form of a language into the modern form. + */ + TRANSLATOR("trl", "Translator"), + + /** + * Use for a person or organization who designed the type face used in a particular item. + */ + TYPE_DESIGNER("tyd", "Type designer"), + + /** + * Use for a person or organization primarily responsible for choice and arrangement of type used in an item. If the typographer is also responsible for other aspects of the graphic design of a book (e.g., Book designer [bkd]), codes for both functions may be needed. + */ + TYPOGRAPHER("tyg", "Typographer"), + + /** + * Use for the name of a place where a university that is associated with a resource is located, for example, a university where an academic dissertation or thesis was presented. + */ + UNIVERSITY_PLACE("uvp", "University place"), + + /** + * Use for a person or organization in charge of a video production, e.g. the video recording of a stage production as opposed to a commercial motion picture. The videographer may be the camera operator or may supervise one or more camera operators. Do not confuse with cinematographer. + */ + VIDEOGRAPHER("vdg", "Videographer"), + + /** + * Use for a person or organization who principally exhibits singing skills in a musical or dramatic presentation or entertainment. + */ + VOCALIST("voc", "Vocalist"), + + /** + * Use for a person who verifies the truthfulness of an event or action. + */ + WITNESS("wit", "Witness"), + + /** + * Use for a person or organization who makes prints by cutting the image in relief on the end-grain of a wood block. + */ + WOOD_ENGRAVER("wde", "Wood-engraver"), + + /** + * Use for a person or organization who makes prints by cutting the image in relief on the plank side of a wood block. + */ + WOODCUTTER("wdc", "Woodcutter"), + + /** + * Use for a person or organization who writes significant material which accompanies a sound recording or other audiovisual material. + */ + WRITER_OF_ACCOMPANYING_MATERIAL("wam", "Writer of accompanying material"); + + private final String code; + private final String name; + + Relator(String code, String name) { + this.code = code; + this.name = name; + } + + public String getCode() { + return code; + } + + public String getName() { + return name; + } + + public static Relator byCode(String code) { + for (Relator relator : Relator.values()) { + if (relator.getCode().equalsIgnoreCase(code)) { + return relator; + } + } + return null; + } + +} diff --git a/modules/book/src/main/java/me/ag2s/epublib/domain/Resource.java b/modules/book/src/main/java/me/ag2s/epublib/domain/Resource.java new file mode 100644 index 000000000..74434830e --- /dev/null +++ b/modules/book/src/main/java/me/ag2s/epublib/domain/Resource.java @@ -0,0 +1,336 @@ +package me.ag2s.epublib.domain; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; +import java.io.Serializable; + +import me.ag2s.epublib.Constants; +import me.ag2s.epublib.util.IOUtil; +import me.ag2s.epublib.util.StringUtil; +import me.ag2s.epublib.util.commons.io.XmlStreamReader; + +/** + * Represents a resource that is part of the epub. + * A resource can be a html file, image, xml, etc. + * + * @author paul + */ +public class Resource implements Serializable { + + private static final long serialVersionUID = 1043946707835004037L; + private String id; + private String title; + private String href; + + + private String properties; + protected final String originalHref; + private MediaType mediaType; + private String inputEncoding; + protected byte[] data; + + /** + * Creates an empty Resource with the given href. + *

+ * Assumes that if the data is of a text type (html/css/etc) then the encoding will be UTF-8 + * + * @param href The location of the resource within the epub. Example: "chapter1.html". + */ + public Resource(String href) { + this(null, new byte[0], href, MediaTypes.determineMediaType(href)); + } + + /** + * Creates a Resource with the given data and MediaType. + * The href will be automatically generated. + *

+ * Assumes that if the data is of a text type (html/css/etc) then the encoding will be UTF-8 + * + * @param data The Resource's contents + * @param mediaType The MediaType of the Resource + */ + public Resource(byte[] data, MediaType mediaType) { + this(null, data, null, mediaType); + } + + /** + * Creates a resource with the given data at the specified href. + * The MediaType will be determined based on the href extension. + *

+ * Assumes that if the data is of a text type (html/css/etc) then the encoding will be UTF-8 + * + * @param data The Resource's contents + * @param href The location of the resource within the epub. Example: "chapter1.html". + * @see MediaTypes#determineMediaType(String) + */ + public Resource(byte[] data, String href) { + this(null, data, href, MediaTypes.determineMediaType(href), + Constants.CHARACTER_ENCODING); + } + + /** + * Creates a resource with the data from the given Reader at the specified href. + * The MediaType will be determined based on the href extension. + * + * @param in The Resource's contents + * @param href The location of the resource within the epub. Example: "cover.jpg". + * @see MediaTypes#determineMediaType(String) + */ + public Resource(Reader in, String href) throws IOException { + this(null, IOUtil.toByteArray(in, Constants.CHARACTER_ENCODING), href, + MediaTypes.determineMediaType(href), + Constants.CHARACTER_ENCODING); + } + + /** + * Creates a resource with the data from the given InputStream at the specified href. + * The MediaType will be determined based on the href extension. + * + * @param in The Resource's contents + * @param href The location of the resource within the epub. Example: "cover.jpg". + * @see MediaTypes#determineMediaType(String) + *

+ * Assumes that if the data is of a text type (html/css/etc) then the encoding will be UTF-8 + *

+ * It is recommended to us the {@link #Resource(Reader, String)} method for creating textual + * (html/css/etc) resources to prevent encoding problems. + * Use this method only for binary Resources like images, fonts, etc. + */ + public Resource(InputStream in, String href) throws IOException { + this(null, IOUtil.toByteArray(in), href, + MediaTypes.determineMediaType(href)); + } + + /** + * Creates a resource with the given id, data, mediatype at the specified href. + * Assumes that if the data is of a text type (html/css/etc) then the encoding will be UTF-8 + * + * @param id The id of the Resource. Internal use only. Will be auto-generated if it has a null-value. + * @param data The Resource's contents + * @param href The location of the resource within the epub. Example: "chapter1.html". + * @param mediaType The resources MediaType + */ + public Resource(String id, byte[] data, String href, MediaType mediaType) { + this(id, data, href, mediaType, Constants.CHARACTER_ENCODING); + } + + public Resource(String id, byte[] data, String href, String originalHref, MediaType mediaType) { + this(id, data, href, originalHref, mediaType, Constants.CHARACTER_ENCODING); + } + + + /** + * Creates a resource with the given id, data, mediatype at the specified href. + * If the data is of a text type (html/css/etc) then it will use the given inputEncoding. + * + * @param id The id of the Resource. Internal use only. Will be auto-generated if it has a null-value. + * @param data The Resource's contents + * @param href The location of the resource within the epub. Example: "chapter1.html". + * @param mediaType The resources MediaType + * @param inputEncoding If the data is of a text type (html/css/etc) then it will use the given inputEncoding. + */ + public Resource(String id, byte[] data, String href, MediaType mediaType, + String inputEncoding) { + this.id = id; + this.href = href; + this.originalHref = href; + this.mediaType = mediaType; + this.inputEncoding = inputEncoding; + this.data = data; + } + + public Resource(String id, byte[] data, String href, String originalHref, MediaType mediaType, + String inputEncoding) { + this.id = id; + this.href = href; + this.originalHref = originalHref; + this.mediaType = mediaType; + this.inputEncoding = inputEncoding; + this.data = data; + } + + /** + * Gets the contents of the Resource as an InputStream. + * + * @return The contents of the Resource. + * @throws IOException IOException + */ + public InputStream getInputStream() throws IOException { + return new ByteArrayInputStream(getData()); + } + + /** + * The contents of the resource as a byte[] + * + * @return The contents of the resource + */ + public byte[] getData() throws IOException { + return data; + } + + /** + * Tells this resource to release its cached data. + *

+ * If this resource was not lazy-loaded, this is a no-op. + */ + public void close() { + } + + /** + * Sets the data of the Resource. + * If the data is a of a different type then the original data then make sure to change the MediaType. + * + * @param data the data of the Resource + */ + public void setData(byte[] data) { + this.data = data; + } + + /** + * Returns the size of this resource in bytes. + * + * @return the size. + */ + public long getSize() { + return data.length; + } + + /** + * If the title is found by scanning the underlying html document then it is cached here. + * + * @return the title + */ + public String getTitle() { + return title; + } + + /** + * Sets the Resource's id: Make sure it is unique and a valid identifier. + * + * @param id Resource's id + */ + public void setId(String id) { + this.id = id; + } + + /** + * The resources Id. + *

+ * Must be both unique within all the resources of this book and a valid identifier. + * + * @return The resources Id. + */ + public String getId() { + return id; + } + + /** + * The location of the resource within the contents folder of the epub file. + *

+ * Example:
+ * images/cover.jpg
+ * content/chapter1.xhtml
+ * + * @return The location of the resource within the contents folder of the epub file. + */ + public String getHref() { + return href; + } + + /** + * Sets the Resource's href. + * + * @param href Resource's href. + */ + public void setHref(String href) { + this.href = href; + } + + /** + * The character encoding of the resource. + * Is allowed to be null for non-text resources like images. + * + * @return The character encoding of the resource. + */ + public String getInputEncoding() { + return inputEncoding; + } + + /** + * Sets the Resource's input character encoding. + * + * @param encoding Resource's input character encoding. + */ + public void setInputEncoding(String encoding) { + this.inputEncoding = encoding; + } + + /** + * Gets the contents of the Resource as Reader. + *

+ * Does all sorts of smart things (courtesy of apache commons io XMLStreamREader) to handle encodings, byte order markers, etc. + * + * @return the contents of the Resource as Reader. + * @throws IOException IOException + */ + public Reader getReader() throws IOException { + return new XmlStreamReader(new ByteArrayInputStream(getData()), + getInputEncoding()); + } + + /** + * Gets the hashCode of the Resource's href. + */ + public int hashCode() { + return href.hashCode(); + } + + /** + * Checks to see of the given resourceObject is a resource and whether its href is equal to this one. + * + * @return whether the given resourceObject is a resource and whether its href is equal to this one. + */ + public boolean equals(Object resourceObject) { + if (!(resourceObject instanceof Resource)) { + return false; + } + return href.equals(((Resource) resourceObject).getHref()); + } + + /** + * This resource's mediaType. + * + * @return This resource's mediaType. + */ + public MediaType getMediaType() { + return mediaType; + } + + public void setMediaType(MediaType mediaType) { + this.mediaType = mediaType; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getProperties() { + return properties; + } + + public void setProperties(String properties) { + this.properties = properties; + } + + @SuppressWarnings("NullableProblems") + public String toString() { + return StringUtil.toString("id", id, + "title", title, + "encoding", inputEncoding, + "mediaType", mediaType, + "href", href, + "size", (data == null ? 0 : data.length)); + } +} diff --git a/book/src/main/java/me/ag2s/epublib/domain/ResourceInputStream.java b/modules/book/src/main/java/me/ag2s/epublib/domain/ResourceInputStream.java similarity index 82% rename from book/src/main/java/me/ag2s/epublib/domain/ResourceInputStream.java rename to modules/book/src/main/java/me/ag2s/epublib/domain/ResourceInputStream.java index b8b8b9953..6975ee81c 100644 --- a/book/src/main/java/me/ag2s/epublib/domain/ResourceInputStream.java +++ b/modules/book/src/main/java/me/ag2s/epublib/domain/ResourceInputStream.java @@ -24,10 +24,10 @@ public class ResourceInputStream extends FilterInputStream { //this.zipFile = zipFile; } - @Override - public void close() throws IOException { - super.close(); + @Override + public void close() throws IOException { + super.close(); - //zipFile.close(); - } + //zipFile.close(); + } } diff --git a/modules/book/src/main/java/me/ag2s/epublib/domain/ResourceReference.java b/modules/book/src/main/java/me/ag2s/epublib/domain/ResourceReference.java new file mode 100644 index 000000000..b6b3b6146 --- /dev/null +++ b/modules/book/src/main/java/me/ag2s/epublib/domain/ResourceReference.java @@ -0,0 +1,43 @@ +package me.ag2s.epublib.domain; + +import java.io.Serializable; + +public class ResourceReference implements Serializable { + + private static final long serialVersionUID = 2596967243557743048L; + + protected Resource resource; + + public ResourceReference(Resource resource) { + this.resource = resource; + } + + + public Resource getResource() { + return resource; + } + + /** + * Besides setting the resource it also sets the fragmentId to null. + * + * @param resource resource + */ + public void setResource(Resource resource) { + this.resource = resource; + } + + + /** + * The id of the reference referred to. + *

+ * null of the reference is null or has a null id itself. + * + * @return The id of the reference referred to. + */ + public String getResourceId() { + if (resource != null) { + return resource.getId(); + } + return null; + } +} diff --git a/book/src/main/java/me/ag2s/epublib/domain/Resources.java b/modules/book/src/main/java/me/ag2s/epublib/domain/Resources.java similarity index 99% rename from book/src/main/java/me/ag2s/epublib/domain/Resources.java rename to modules/book/src/main/java/me/ag2s/epublib/domain/Resources.java index 81c643e6f..5848855f9 100644 --- a/book/src/main/java/me/ag2s/epublib/domain/Resources.java +++ b/modules/book/src/main/java/me/ag2s/epublib/domain/Resources.java @@ -247,6 +247,7 @@ public class Resources implements Serializable { StringUtil.substringBefore(href, Constants.FRAGMENT_SEPARATOR_CHAR)); } } + /** * Whether there exists a resource with the given href * diff --git a/modules/book/src/main/java/me/ag2s/epublib/domain/Spine.java b/modules/book/src/main/java/me/ag2s/epublib/domain/Spine.java new file mode 100644 index 000000000..5ef1fc975 --- /dev/null +++ b/modules/book/src/main/java/me/ag2s/epublib/domain/Spine.java @@ -0,0 +1,190 @@ +package me.ag2s.epublib.domain; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import me.ag2s.epublib.util.StringUtil; + +/** + * The spine sections are the sections of the book in the order in which the book should be read. + *

+ * This contrasts with the Table of Contents sections which is an index into the Book's sections. + * + * @author paul + * @see TableOfContents + */ +public class Spine implements Serializable { + + private static final long serialVersionUID = 3878483958947357246L; + private Resource tocResource; + private List spineReferences; + + public Spine() { + this(new ArrayList<>()); + } + + /** + * Creates a spine out of all the resources in the table of contents. + * + * @param tableOfContents tableOfContents + */ + public Spine(TableOfContents tableOfContents) { + this.spineReferences = createSpineReferences( + tableOfContents.getAllUniqueResources()); + } + + public Spine(List spineReferences) { + this.spineReferences = spineReferences; + } + + public static List createSpineReferences( + Collection resources) { + List result = new ArrayList<>( + resources.size()); + for (Resource resource : resources) { + result.add(new SpineReference(resource)); + } + return result; + } + + public List getSpineReferences() { + return spineReferences; + } + + public void setSpineReferences(List spineReferences) { + this.spineReferences = spineReferences; + } + + /** + * Gets the resource at the given index. + * Null if not found. + * + * @param index index + * @return the resource at the given index. + */ + public Resource getResource(int index) { + if (index < 0 || index >= spineReferences.size()) { + return null; + } + return spineReferences.get(index).getResource(); + } + + /** + * Finds the first resource that has the given resourceId. + *

+ * Null if not found. + * + * @param resourceId resourceId + * @return the first resource that has the given resourceId. + */ + public int findFirstResourceById(String resourceId) { + if (StringUtil.isBlank(resourceId)) { + return -1; + } + + for (int i = 0; i < spineReferences.size(); i++) { + SpineReference spineReference = spineReferences.get(i); + if (resourceId.equals(spineReference.getResourceId())) { + return i; + } + } + return -1; + } + + /** + * Adds the given spineReference to the spine references and returns it. + * + * @param spineReference spineReference + * @return the given spineReference + */ + public SpineReference addSpineReference(SpineReference spineReference) { + if (spineReferences == null) { + this.spineReferences = new ArrayList<>(); + } + spineReferences.add(spineReference); + return spineReference; + } + + /** + * Adds the given resource to the spine references and returns it. + * + * @return the given spineReference + */ + @SuppressWarnings("unused") + public SpineReference addResource(Resource resource) { + return addSpineReference(new SpineReference(resource)); + } + + /** + * The number of elements in the spine. + * + * @return The number of elements in the spine. + */ + public int size() { + return spineReferences.size(); + } + + /** + * As per the epub file format the spine officially maintains a reference to the Table of Contents. + * The epubwriter will look for it here first, followed by some clever tricks to find it elsewhere if not found. + * Put it here to be sure of the expected behaviours. + * + * @param tocResource tocResource + */ + public void setTocResource(Resource tocResource) { + this.tocResource = tocResource; + } + + /** + * The resource containing the XML for the tableOfContents. + * When saving an epub file this resource needs to be in this place. + * + * @return The resource containing the XML for the tableOfContents. + */ + public Resource getTocResource() { + return tocResource; + } + + /** + * The position within the spine of the given resource. + * + * @param currentResource currentResource + * @return something < 0 if not found. + */ + public int getResourceIndex(Resource currentResource) { + if (currentResource == null) { + return -1; + } + return getResourceIndex(currentResource.getHref()); + } + + /** + * The first position within the spine of a resource with the given href. + * + * @return something < 0 if not found. + */ + public int getResourceIndex(String resourceHref) { + int result = -1; + if (StringUtil.isBlank(resourceHref)) { + return result; + } + for (int i = 0; i < spineReferences.size(); i++) { + if (resourceHref.equals(spineReferences.get(i).getResource().getHref())) { + result = i; + break; + } + } + return result; + } + + /** + * Whether the spine has any references + * + * @return Whether the spine has any references + */ + public boolean isEmpty() { + return spineReferences.isEmpty(); + } +} diff --git a/book/src/main/java/me/ag2s/epublib/domain/SpineReference.java b/modules/book/src/main/java/me/ag2s/epublib/domain/SpineReference.java similarity index 100% rename from book/src/main/java/me/ag2s/epublib/domain/SpineReference.java rename to modules/book/src/main/java/me/ag2s/epublib/domain/SpineReference.java diff --git a/modules/book/src/main/java/me/ag2s/epublib/domain/TOCReference.java b/modules/book/src/main/java/me/ag2s/epublib/domain/TOCReference.java new file mode 100644 index 000000000..146e95363 --- /dev/null +++ b/modules/book/src/main/java/me/ag2s/epublib/domain/TOCReference.java @@ -0,0 +1,57 @@ +package me.ag2s.epublib.domain; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +/** + * An item in the Table of Contents. + * + * @author paul + * @see TableOfContents + */ +public class TOCReference extends TitledResourceReference + implements Serializable { + + private static final long serialVersionUID = 5787958246077042456L; + private List children; + private static final Comparator COMPARATOR_BY_TITLE_IGNORE_CASE = (tocReference1, tocReference2) -> String.CASE_INSENSITIVE_ORDER.compare(tocReference1.getTitle(), tocReference2.getTitle()); + + @Deprecated + public TOCReference() { + this(null, null, null); + } + + public TOCReference(String name, Resource resource) { + this(name, resource, null); + } + + public TOCReference(String name, Resource resource, String fragmentId) { + this(name, resource, fragmentId, new ArrayList<>()); + } + + public TOCReference(String title, Resource resource, String fragmentId, + List children) { + super(resource, title, fragmentId); + this.children = children; + } + + @SuppressWarnings("unused") + public static Comparator getComparatorByTitleIgnoreCase() { + return COMPARATOR_BY_TITLE_IGNORE_CASE; + } + + public List getChildren() { + return children; + } + + public TOCReference addChildSection(TOCReference childSection) { + this.children.add(childSection); + return childSection; + } + + public void setChildren(List children) { + this.children = children; + } +} diff --git a/book/src/main/java/me/ag2s/epublib/domain/TableOfContents.java b/modules/book/src/main/java/me/ag2s/epublib/domain/TableOfContents.java similarity index 100% rename from book/src/main/java/me/ag2s/epublib/domain/TableOfContents.java rename to modules/book/src/main/java/me/ag2s/epublib/domain/TableOfContents.java diff --git a/book/src/main/java/me/ag2s/epublib/domain/TitledResourceReference.java b/modules/book/src/main/java/me/ag2s/epublib/domain/TitledResourceReference.java similarity index 97% rename from book/src/main/java/me/ag2s/epublib/domain/TitledResourceReference.java rename to modules/book/src/main/java/me/ag2s/epublib/domain/TitledResourceReference.java index e7fe769ad..684540724 100644 --- a/book/src/main/java/me/ag2s/epublib/domain/TitledResourceReference.java +++ b/modules/book/src/main/java/me/ag2s/epublib/domain/TitledResourceReference.java @@ -70,7 +70,7 @@ public class TitledResourceReference extends ResourceReference @Override public Resource getResource() { //resource为null时不设置标题 - if(this.resource!=null&&this.title!=null){ + if (this.resource != null && this.title != null) { resource.setTitle(title); } diff --git a/book/src/main/java/me/ag2s/epublib/epub/BookProcessor.java b/modules/book/src/main/java/me/ag2s/epublib/epub/BookProcessor.java similarity index 65% rename from book/src/main/java/me/ag2s/epublib/epub/BookProcessor.java rename to modules/book/src/main/java/me/ag2s/epublib/epub/BookProcessor.java index d45b9d891..cab3fe1b8 100644 --- a/book/src/main/java/me/ag2s/epublib/epub/BookProcessor.java +++ b/modules/book/src/main/java/me/ag2s/epublib/epub/BookProcessor.java @@ -4,17 +4,17 @@ import me.ag2s.epublib.domain.EpubBook; /** * Post-processes a book. - * + *

* Can be used to clean up a book after reading or before writing. * * @author paul */ public interface BookProcessor { - /** - * A BookProcessor that returns the input book unchanged. - */ - BookProcessor IDENTITY_BOOKPROCESSOR = book -> book; + /** + * A BookProcessor that returns the input book unchanged. + */ + BookProcessor IDENTITY_BOOKPROCESSOR = book -> book; EpubBook processBook(EpubBook book); } diff --git a/modules/book/src/main/java/me/ag2s/epublib/epub/BookProcessorPipeline.java b/modules/book/src/main/java/me/ag2s/epublib/epub/BookProcessorPipeline.java new file mode 100644 index 000000000..55867e50f --- /dev/null +++ b/modules/book/src/main/java/me/ag2s/epublib/epub/BookProcessorPipeline.java @@ -0,0 +1,73 @@ +package me.ag2s.epublib.epub; + +import android.util.Log; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import me.ag2s.epublib.domain.EpubBook; + +/** + * A book processor that combines several other bookprocessors + *

+ * Fixes coverpage/coverimage. + * Cleans up the XHTML. + * + * @author paul.siegmann + */ +@SuppressWarnings("unused declaration") +public class BookProcessorPipeline implements BookProcessor { + + private static final String TAG = BookProcessorPipeline.class.getName(); + private List bookProcessors; + + public BookProcessorPipeline() { + this(null); + } + + public BookProcessorPipeline(List bookProcessingPipeline) { + this.bookProcessors = bookProcessingPipeline; + } + + @Override + public EpubBook processBook(EpubBook book) { + if (bookProcessors == null) { + return book; + } + for (BookProcessor bookProcessor : bookProcessors) { + try { + book = bookProcessor.processBook(book); + } catch (Exception e) { + Log.e(TAG, e.getMessage(), e); + } + } + return book; + } + + public void addBookProcessor(BookProcessor bookProcessor) { + if (this.bookProcessors == null) { + bookProcessors = new ArrayList<>(); + } + this.bookProcessors.add(bookProcessor); + } + + public void addBookProcessors(Collection bookProcessors) { + if (this.bookProcessors == null) { + this.bookProcessors = new ArrayList<>(); + } + this.bookProcessors.addAll(bookProcessors); + } + + + public List getBookProcessors() { + return bookProcessors; + } + + + public void setBookProcessingPipeline( + List bookProcessingPipeline) { + this.bookProcessors = bookProcessingPipeline; + } + +} diff --git a/book/src/main/java/me/ag2s/epublib/epub/DOMUtil.java b/modules/book/src/main/java/me/ag2s/epublib/epub/DOMUtil.java similarity index 99% rename from book/src/main/java/me/ag2s/epublib/epub/DOMUtil.java rename to modules/book/src/main/java/me/ag2s/epublib/epub/DOMUtil.java index e6ae05b3d..72fdf249f 100644 --- a/book/src/main/java/me/ag2s/epublib/epub/DOMUtil.java +++ b/modules/book/src/main/java/me/ag2s/epublib/epub/DOMUtil.java @@ -104,6 +104,7 @@ class DOMUtil { } return nodes; } + /** * Gets the first element that is a child of the parentElement and has the given namespace and tagName * diff --git a/book/src/main/java/me/ag2s/epublib/epub/EpubProcessorSupport.java b/modules/book/src/main/java/me/ag2s/epublib/epub/EpubProcessorSupport.java similarity index 100% rename from book/src/main/java/me/ag2s/epublib/epub/EpubProcessorSupport.java rename to modules/book/src/main/java/me/ag2s/epublib/epub/EpubProcessorSupport.java diff --git a/book/src/main/java/me/ag2s/epublib/epub/EpubReader.java b/modules/book/src/main/java/me/ag2s/epublib/epub/EpubReader.java similarity index 100% rename from book/src/main/java/me/ag2s/epublib/epub/EpubReader.java rename to modules/book/src/main/java/me/ag2s/epublib/epub/EpubReader.java diff --git a/modules/book/src/main/java/me/ag2s/epublib/epub/EpubWriter.java b/modules/book/src/main/java/me/ag2s/epublib/epub/EpubWriter.java new file mode 100644 index 000000000..6c4fa1a8a --- /dev/null +++ b/modules/book/src/main/java/me/ag2s/epublib/epub/EpubWriter.java @@ -0,0 +1,190 @@ +package me.ag2s.epublib.epub; + +import android.util.Log; + +import org.xmlpull.v1.XmlSerializer; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.util.zip.CRC32; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +import me.ag2s.epublib.domain.EpubBook; +import me.ag2s.epublib.domain.MediaTypes; +import me.ag2s.epublib.domain.Resource; +import me.ag2s.epublib.util.IOUtil; + +/** + * Generates an epub file. Not thread-safe, single use object. + * + * @author paul + */ +public class EpubWriter { + + private static final String TAG = EpubWriter.class.getName(); + + // package + static final String EMPTY_NAMESPACE_PREFIX = ""; + + private BookProcessor bookProcessor; + + public EpubWriter() { + this(BookProcessor.IDENTITY_BOOKPROCESSOR); + } + + + public EpubWriter(BookProcessor bookProcessor) { + this.bookProcessor = bookProcessor; + } + + + public void write(EpubBook book, OutputStream out) throws IOException { + book = processBook(book); + ZipOutputStream resultStream = new ZipOutputStream(out); + writeMimeType(resultStream); + writeContainer(resultStream); + initTOCResource(book); + writeResources(book, resultStream); + writePackageDocument(book, resultStream); + resultStream.close(); + } + + private EpubBook processBook(EpubBook book) { + if (bookProcessor != null) { + book = bookProcessor.processBook(book); + } + return book; + } + + private void initTOCResource(EpubBook book) { + Resource tocResource; + try { + if (book.isEpub3()) { + tocResource = NCXDocumentV3.createNCXResource(book); + } else { + tocResource = NCXDocumentV2.createNCXResource(book); + } + + Resource currentTocResource = book.getSpine().getTocResource(); + if (currentTocResource != null) { + book.getResources().remove(currentTocResource.getHref()); + } + book.getSpine().setTocResource(tocResource); + book.getResources().add(tocResource); + } catch (Exception ex) { + Log.e(TAG, + "Error writing table of contents: " + + ex.getClass().getName() + ": " + ex.getMessage(), ex); + } + } + + + private void writeResources(EpubBook book, ZipOutputStream resultStream) { + for (Resource resource : book.getResources().getAll()) { + writeResource(resource, resultStream); + } + } + + /** + * Writes the resource to the resultStream. + * + * @param resource resource + * @param resultStream resultStream + */ + private void writeResource(Resource resource, ZipOutputStream resultStream) { + if (resource == null) { + return; + } + try { + resultStream.putNextEntry(new ZipEntry("OEBPS/" + resource.getHref())); + InputStream inputStream = resource.getInputStream(); + + IOUtil.copy(inputStream, resultStream); + inputStream.close(); + } catch (Exception e) { + Log.e(TAG, e.getMessage(), e); + } + } + + + private void writePackageDocument(EpubBook book, ZipOutputStream resultStream) + throws IOException { + resultStream.putNextEntry(new ZipEntry("OEBPS/content.opf")); + XmlSerializer xmlSerializer = EpubProcessorSupport + .createXmlSerializer(resultStream); + PackageDocumentWriter.write(this, xmlSerializer, book); + xmlSerializer.flush(); +// String resultAsString = result.toString(); +// resultStream.write(resultAsString.getBytes(Constants.ENCODING)); + } + + /** + * Writes the META-INF/container.xml file. + * + * @param resultStream resultStream + * @throws IOException IOException + */ + private void writeContainer(ZipOutputStream resultStream) throws IOException { + resultStream.putNextEntry(new ZipEntry("META-INF/container.xml")); + Writer out = new OutputStreamWriter(resultStream); + out.write("\n"); + out.write( + "\n"); + out.write("\t\n"); + out.write( + "\t\t\n"); + out.write("\t\n"); + out.write(""); + out.flush(); + } + + /** + * Stores the mimetype as an uncompressed file in the ZipOutputStream. + * + * @param resultStream resultStream + * @throws IOException IOException + */ + private void writeMimeType(ZipOutputStream resultStream) throws IOException { + ZipEntry mimetypeZipEntry = new ZipEntry("mimetype"); + mimetypeZipEntry.setMethod(ZipEntry.STORED); + byte[] mimetypeBytes = MediaTypes.EPUB.getName().getBytes(); + mimetypeZipEntry.setSize(mimetypeBytes.length); + mimetypeZipEntry.setCrc(calculateCrc(mimetypeBytes)); + resultStream.putNextEntry(mimetypeZipEntry); + resultStream.write(mimetypeBytes); + } + + private long calculateCrc(byte[] data) { + CRC32 crc = new CRC32(); + crc.update(data); + return crc.getValue(); + } + + String getNcxId() { + return "ncx"; + } + + String getNcxHref() { + return "toc.ncx"; + } + + String getNcxMediaType() { + return MediaTypes.NCX.getName(); + } + + + @SuppressWarnings("unused") + public BookProcessor getBookProcessor() { + return bookProcessor; + } + + @SuppressWarnings("unused") + public void setBookProcessor(BookProcessor bookProcessor) { + this.bookProcessor = bookProcessor; + } + +} diff --git a/book/src/main/java/me/ag2s/epublib/epub/HtmlProcessor.java b/modules/book/src/main/java/me/ag2s/epublib/epub/HtmlProcessor.java similarity index 71% rename from book/src/main/java/me/ag2s/epublib/epub/HtmlProcessor.java rename to modules/book/src/main/java/me/ag2s/epublib/epub/HtmlProcessor.java index afd5801b7..c0e2e4eec 100644 --- a/book/src/main/java/me/ag2s/epublib/epub/HtmlProcessor.java +++ b/modules/book/src/main/java/me/ag2s/epublib/epub/HtmlProcessor.java @@ -3,8 +3,9 @@ package me.ag2s.epublib.epub; import java.io.OutputStream; import me.ag2s.epublib.domain.Resource; + @SuppressWarnings("unused") public interface HtmlProcessor { - void processHtmlResource(Resource resource, OutputStream out); + void processHtmlResource(Resource resource, OutputStream out); } diff --git a/book/src/main/java/me/ag2s/epublib/epub/NCXDocumentV2.java b/modules/book/src/main/java/me/ag2s/epublib/epub/NCXDocumentV2.java similarity index 99% rename from book/src/main/java/me/ag2s/epublib/epub/NCXDocumentV2.java rename to modules/book/src/main/java/me/ag2s/epublib/epub/NCXDocumentV2.java index 2bf47de51..982c2e8eb 100644 --- a/book/src/main/java/me/ag2s/epublib/epub/NCXDocumentV2.java +++ b/modules/book/src/main/java/me/ag2s/epublib/epub/NCXDocumentV2.java @@ -334,6 +334,7 @@ public class NCXDocumentV2 { tocReference.getCompleteHref()); serializer.endTag(NAMESPACE_NCX, NCXTags.content); } + @SuppressWarnings("unused") private static void writeNavPointEnd(TOCReference tocReference, XmlSerializer serializer) diff --git a/book/src/main/java/me/ag2s/epublib/epub/NCXDocumentV3.java b/modules/book/src/main/java/me/ag2s/epublib/epub/NCXDocumentV3.java similarity index 98% rename from book/src/main/java/me/ag2s/epublib/epub/NCXDocumentV3.java rename to modules/book/src/main/java/me/ag2s/epublib/epub/NCXDocumentV3.java index 845b999d1..3cce0dd6e 100644 --- a/book/src/main/java/me/ag2s/epublib/epub/NCXDocumentV3.java +++ b/modules/book/src/main/java/me/ag2s/epublib/epub/NCXDocumentV3.java @@ -108,8 +108,8 @@ public class NCXDocumentV3 { return null; } //一些epub 3 文件没有按照epub3的标准使用删除掉ncx目录文件 - if (ncxResource.getHref().endsWith(".ncx")){ - Log.v(TAG,"该epub文件不标准,使用了epub2的目录文件"); + if (ncxResource.getHref().endsWith(".ncx")) { + Log.v(TAG, "该epub文件不标准,使用了epub2的目录文件"); return NCXDocumentV2.read(book, epubReader); } Log.d(TAG, ncxResource.getHref()); @@ -118,8 +118,8 @@ public class NCXDocumentV3 { Log.d(TAG, ncxDocument.getNodeName()); Element navMapElement = (Element) ncxDocument.getElementsByTagName(XHTMLTgs.nav).item(0); - if(navMapElement==null){ - Log.d(TAG,"epub3目录文件未发现nav节点,尝试使用epub2的规则解析"); + if (navMapElement == null) { + Log.d(TAG, "epub3目录文件未发现nav节点,尝试使用epub2的规则解析"); return NCXDocumentV2.read(book, epubReader); } navMapElement = (Element) navMapElement.getElementsByTagName(XHTMLTgs.ol).item(0); diff --git a/modules/book/src/main/java/me/ag2s/epublib/epub/PackageDocumentBase.java b/modules/book/src/main/java/me/ag2s/epublib/epub/PackageDocumentBase.java new file mode 100644 index 000000000..045e8347d --- /dev/null +++ b/modules/book/src/main/java/me/ag2s/epublib/epub/PackageDocumentBase.java @@ -0,0 +1,96 @@ +package me.ag2s.epublib.epub; + + +/** + * Functionality shared by the PackageDocumentReader and the PackageDocumentWriter + * + * @author paul + */ +public class PackageDocumentBase { + + public static final String BOOK_ID_ID = "duokan-book-id"; + public static final String NAMESPACE_OPF = "http://www.idpf.org/2007/opf"; + public static final String NAMESPACE_DUBLIN_CORE = "http://purl.org/dc/elements/1.1/"; + public static final String PREFIX_DUBLIN_CORE = "dc"; + //public static final String PREFIX_OPF = "opf"; + //在EPUB3标准中,packge前面没有opf头,一些epub阅读器也不支持opf头。 + //Some Epub Reader not reconize op:packge,So just let it empty; + public static final String PREFIX_OPF = ""; + //添加 version 变量来区分Epub文件的版本 + //Add the version field to distinguish the version of EPUB file + public static final String version = "version"; + public static final String dateFormat = "yyyy-MM-dd"; + + protected interface DCTags { + + String title = "title"; + String creator = "creator"; + String subject = "subject"; + String description = "description"; + String publisher = "publisher"; + String contributor = "contributor"; + String date = "date"; + String type = "type"; + String format = "format"; + String identifier = "identifier"; + String source = "source"; + String language = "language"; + String relation = "relation"; + String coverage = "coverage"; + String rights = "rights"; + } + + protected interface DCAttributes { + + String scheme = "scheme"; + String id = "id"; + } + + protected interface OPFTags { + + String metadata = "metadata"; + String meta = "meta"; + String manifest = "manifest"; + String packageTag = "package"; + String itemref = "itemref"; + String spine = "spine"; + String reference = "reference"; + String guide = "guide"; + String item = "item"; + } + + protected interface OPFAttributes { + + String uniqueIdentifier = "unique-identifier"; + String idref = "idref"; + String name = "name"; + String content = "content"; + String type = "type"; + String href = "href"; + String linear = "linear"; + String event = "event"; + String role = "role"; + String file_as = "file-as"; + String id = "id"; + String media_type = "media-type"; + String title = "title"; + String toc = "toc"; + String version = "version"; + String scheme = "scheme"; + String property = "property"; + //add for epub3 + /** + * add for epub3 + */ + String properties = "properties"; + } + + protected interface OPFValues { + + String meta_cover = "cover"; + String reference_cover = "cover"; + String no = "no"; + String generator = "generator"; + String duokan = "duokan-body-font"; + } +} \ No newline at end of file diff --git a/book/src/main/java/me/ag2s/epublib/epub/PackageDocumentMetadataReader.java b/modules/book/src/main/java/me/ag2s/epublib/epub/PackageDocumentMetadataReader.java similarity index 100% rename from book/src/main/java/me/ag2s/epublib/epub/PackageDocumentMetadataReader.java rename to modules/book/src/main/java/me/ag2s/epublib/epub/PackageDocumentMetadataReader.java diff --git a/modules/book/src/main/java/me/ag2s/epublib/epub/PackageDocumentMetadataWriter.java b/modules/book/src/main/java/me/ag2s/epublib/epub/PackageDocumentMetadataWriter.java new file mode 100644 index 000000000..91f58272b --- /dev/null +++ b/modules/book/src/main/java/me/ag2s/epublib/epub/PackageDocumentMetadataWriter.java @@ -0,0 +1,187 @@ +package me.ag2s.epublib.epub; + +import org.xmlpull.v1.XmlSerializer; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; + +import me.ag2s.epublib.Constants; +import me.ag2s.epublib.domain.Author; +import me.ag2s.epublib.domain.Date; +import me.ag2s.epublib.domain.EpubBook; +import me.ag2s.epublib.domain.Identifier; +import me.ag2s.epublib.util.StringUtil; + +public class PackageDocumentMetadataWriter extends PackageDocumentBase { + + /** + * Writes the book's metadata. + * + * @param book book + * @param serializer serializer + * @throws IOException IOException + * @throws IllegalStateException IllegalStateException + * @throws IllegalArgumentException IllegalArgumentException + */ + public static void writeMetaData(EpubBook book, XmlSerializer serializer) + throws IllegalArgumentException, IllegalStateException, IOException { + serializer.startTag(NAMESPACE_OPF, OPFTags.metadata); + serializer.setPrefix(PREFIX_DUBLIN_CORE, NAMESPACE_DUBLIN_CORE); + serializer.setPrefix(PREFIX_OPF, NAMESPACE_OPF); + + writeIdentifiers(book.getMetadata().getIdentifiers(), serializer); + writeSimpleMetdataElements(DCTags.title, book.getMetadata().getTitles(), + serializer); + writeSimpleMetdataElements(DCTags.subject, book.getMetadata().getSubjects(), + serializer); + writeSimpleMetdataElements(DCTags.description, + book.getMetadata().getDescriptions(), serializer); + writeSimpleMetdataElements(DCTags.publisher, + book.getMetadata().getPublishers(), serializer); + writeSimpleMetdataElements(DCTags.type, book.getMetadata().getTypes(), + serializer); + writeSimpleMetdataElements(DCTags.rights, book.getMetadata().getRights(), + serializer); + + // write authors + for (Author author : book.getMetadata().getAuthors()) { + serializer.startTag(NAMESPACE_DUBLIN_CORE, DCTags.creator); + serializer.attribute(NAMESPACE_OPF, OPFAttributes.role, + author.getRelator().getCode()); + serializer.attribute(NAMESPACE_OPF, OPFAttributes.file_as, + author.getLastname() + ", " + author.getFirstname()); + serializer.text(author.getFirstname() + " " + author.getLastname()); + serializer.endTag(NAMESPACE_DUBLIN_CORE, DCTags.creator); + } + + // write contributors + for (Author author : book.getMetadata().getContributors()) { + serializer.startTag(NAMESPACE_DUBLIN_CORE, DCTags.contributor); + serializer.attribute(NAMESPACE_OPF, OPFAttributes.role, + author.getRelator().getCode()); + serializer.attribute(NAMESPACE_OPF, OPFAttributes.file_as, + author.getLastname() + ", " + author.getFirstname()); + serializer.text(author.getFirstname() + " " + author.getLastname()); + serializer.endTag(NAMESPACE_DUBLIN_CORE, DCTags.contributor); + } + + // write dates + for (Date date : book.getMetadata().getDates()) { + serializer.startTag(NAMESPACE_DUBLIN_CORE, DCTags.date); + if (date.getEvent() != null) { + serializer.attribute(NAMESPACE_OPF, OPFAttributes.event, + date.getEvent().toString()); + } + serializer.text(date.getValue()); + serializer.endTag(NAMESPACE_DUBLIN_CORE, DCTags.date); + } + + // write language + if (StringUtil.isNotBlank(book.getMetadata().getLanguage())) { + serializer.startTag(NAMESPACE_DUBLIN_CORE, "language"); + serializer.text(book.getMetadata().getLanguage()); + serializer.endTag(NAMESPACE_DUBLIN_CORE, "language"); + } + + // write other properties + if (book.getMetadata().getOtherProperties() != null) { + for (Map.Entry mapEntry : book.getMetadata() + .getOtherProperties().entrySet()) { + serializer.startTag(mapEntry.getKey().getNamespaceURI(), OPFTags.meta); + serializer.attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, + OPFAttributes.property, mapEntry.getKey().getLocalPart()); + serializer.text(mapEntry.getValue()); + serializer.endTag(mapEntry.getKey().getNamespaceURI(), OPFTags.meta); + + } + } + + // write coverimage + if (book.getCoverImage() != null) { // write the cover image + serializer.startTag(NAMESPACE_OPF, OPFTags.meta); + serializer + .attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, OPFAttributes.name, + OPFValues.meta_cover); + serializer + .attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, OPFAttributes.content, + book.getCoverImage().getId()); + serializer.endTag(NAMESPACE_OPF, OPFTags.meta); + } + + // write generator + serializer.startTag(NAMESPACE_OPF, OPFTags.meta); + serializer.attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, OPFAttributes.name, + OPFValues.generator); + serializer + .attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, OPFAttributes.content, + Constants.EPUB_GENERATOR_NAME); + serializer.endTag(NAMESPACE_OPF, OPFTags.meta); + + // write duokan + serializer.startTag(NAMESPACE_OPF, OPFTags.meta); + serializer.attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, OPFAttributes.name, + OPFValues.duokan); + serializer + .attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, OPFAttributes.content, + Constants.EPUB_DUOKAN_NAME); + serializer.endTag(NAMESPACE_OPF, OPFTags.meta); + + serializer.endTag(NAMESPACE_OPF, OPFTags.metadata); + } + + private static void writeSimpleMetdataElements(String tagName, + List values, XmlSerializer serializer) + throws IllegalArgumentException, IllegalStateException, IOException { + for (String value : values) { + if (StringUtil.isBlank(value)) { + continue; + } + serializer.startTag(NAMESPACE_DUBLIN_CORE, tagName); + serializer.text(value); + serializer.endTag(NAMESPACE_DUBLIN_CORE, tagName); + } + } + + + /** + * Writes out the complete list of Identifiers to the package document. + * The first identifier for which the bookId is true is made the bookId identifier. + * If no identifier has bookId == true then the first bookId identifier is written as the primary. + * + * @param identifiers identifiers + * @param serializer serializer + * @throws IllegalStateException e + * @throws IllegalArgumentException e + * @ + */ + private static void writeIdentifiers(List identifiers, + XmlSerializer serializer) + throws IllegalArgumentException, IllegalStateException, IOException { + Identifier bookIdIdentifier = Identifier.getBookIdIdentifier(identifiers); + if (bookIdIdentifier == null) { + return; + } + + serializer.startTag(NAMESPACE_DUBLIN_CORE, DCTags.identifier); + serializer.attribute(EpubWriter.EMPTY_NAMESPACE_PREFIX, DCAttributes.id, + BOOK_ID_ID); + serializer.attribute(NAMESPACE_OPF, OPFAttributes.scheme, + bookIdIdentifier.getScheme()); + serializer.text(bookIdIdentifier.getValue()); + serializer.endTag(NAMESPACE_DUBLIN_CORE, DCTags.identifier); + + for (Identifier identifier : identifiers.subList(1, identifiers.size())) { + if (identifier == bookIdIdentifier) { + continue; + } + serializer.startTag(NAMESPACE_DUBLIN_CORE, DCTags.identifier); + serializer.attribute(NAMESPACE_OPF, "scheme", identifier.getScheme()); + serializer.text(identifier.getValue()); + serializer.endTag(NAMESPACE_DUBLIN_CORE, DCTags.identifier); + } + } + +} diff --git a/book/src/main/java/me/ag2s/epublib/epub/PackageDocumentReader.java b/modules/book/src/main/java/me/ag2s/epublib/epub/PackageDocumentReader.java similarity index 97% rename from book/src/main/java/me/ag2s/epublib/epub/PackageDocumentReader.java rename to modules/book/src/main/java/me/ag2s/epublib/epub/PackageDocumentReader.java index d6982e189..db6f429ea 100644 --- a/book/src/main/java/me/ag2s/epublib/epub/PackageDocumentReader.java +++ b/modules/book/src/main/java/me/ag2s/epublib/epub/PackageDocumentReader.java @@ -73,13 +73,13 @@ public class PackageDocumentReader extends PackageDocumentBase { } /** - * * 修复一些非标准epub格式由于 opf 文件内容不全而读取不到图片的问题 - * @author qianfanguojin + * * @return ,修复图片路径后的一个Element列表 + * @author qianfanguojin */ private static ArrayList ensureImageInfo(Resources resources, - Element manifestElement){ + Element manifestElement) { ArrayList fixedElements = new ArrayList<>(); //加入当前所有的 item 标签 NodeList originItemElements = manifestElement @@ -91,12 +91,12 @@ public class PackageDocumentReader extends PackageDocumentBase { //如果有图片资源未定义在 originItemElements ,则加入该图片信息得到 fixedElements 中 for (Resource resource : resources.getAll()) { MediaType currentMediaType = resource.getMediaType(); - if ( currentMediaType == MediaTypes.JPG || currentMediaType == MediaTypes.PNG){ + if (currentMediaType == MediaTypes.JPG || currentMediaType == MediaTypes.PNG) { String imageHref = resource.getHref(); //确保该图片信息 resource 在原 originItemElements 列表中没有出现过 boolean flag = false; int i; - for (i = 0; i < originItemElements.getLength(); i++){ + for (i = 0; i < originItemElements.getLength(); i++) { Element itemElement = (Element) originItemElements.item(i); String href = DOMUtil .getAttribute(itemElement, NAMESPACE_OPF, OPFAttributes.href); @@ -105,18 +105,18 @@ public class PackageDocumentReader extends PackageDocumentBase { } catch (UnsupportedEncodingException e) { Log.e(TAG, e.getMessage()); } - if (href.equals(imageHref)){ + if (href.equals(imageHref)) { break; } } - if (i == originItemElements.getLength()){ + if (i == originItemElements.getLength()) { flag = true; } - if (flag){ + if (flag) { //由于暂时无法实例化一个Element,则选择克隆一个已存在的节点来修改以达到新增 Element 的效果,作为临时解决方案 - Element tempElement = (Element) manifestElement.getElementsByTagNameNS(NAMESPACE_OPF,OPFTags.item).item(0).cloneNode(true); - tempElement.setAttribute("id",imageHref.replace("/","")); - tempElement.setAttribute("href",imageHref); + Element tempElement = (Element) manifestElement.getElementsByTagNameNS(NAMESPACE_OPF, OPFTags.item).item(0).cloneNode(true); + tempElement.setAttribute("id", imageHref.replace("/", "")); + tempElement.setAttribute("href", imageHref); tempElement.setAttribute("media-type", currentMediaType.getName()); fixedElements.add(tempElement); } @@ -126,6 +126,7 @@ public class PackageDocumentReader extends PackageDocumentBase { } return fixedElements; } + /** * Reads the manifest containing the resource ids, hrefs and mediatypes. * @@ -150,7 +151,7 @@ public class PackageDocumentReader extends PackageDocumentBase { "Package document does not contain element " + OPFTags.manifest); return result; } - List ensuredElements = ensureImageInfo(resources,manifestElement); + List ensuredElements = ensureImageInfo(resources, manifestElement); for (Element itemElement : ensuredElements) { // Element itemElement = ; String id = DOMUtil diff --git a/book/src/main/java/me/ag2s/epublib/epub/PackageDocumentWriter.java b/modules/book/src/main/java/me/ag2s/epublib/epub/PackageDocumentWriter.java similarity index 100% rename from book/src/main/java/me/ag2s/epublib/epub/PackageDocumentWriter.java rename to modules/book/src/main/java/me/ag2s/epublib/epub/PackageDocumentWriter.java diff --git a/book/src/main/java/me/ag2s/epublib/epub/ResourcesLoader.java b/modules/book/src/main/java/me/ag2s/epublib/epub/ResourcesLoader.java similarity index 100% rename from book/src/main/java/me/ag2s/epublib/epub/ResourcesLoader.java rename to modules/book/src/main/java/me/ag2s/epublib/epub/ResourcesLoader.java diff --git a/modules/book/src/main/java/me/ag2s/epublib/util/CollectionUtil.java b/modules/book/src/main/java/me/ag2s/epublib/util/CollectionUtil.java new file mode 100644 index 000000000..4c9462f38 --- /dev/null +++ b/modules/book/src/main/java/me/ag2s/epublib/util/CollectionUtil.java @@ -0,0 +1,72 @@ +package me.ag2s.epublib.util; + +import java.util.Collection; +import java.util.Enumeration; +import java.util.Iterator; +import java.util.List; + +public class CollectionUtil { + + /** + * Wraps an Enumeration around an Iterator + * + * @param + * @author paul.siegmann + */ + private static class IteratorEnumerationAdapter implements Enumeration { + + private final Iterator iterator; + + public IteratorEnumerationAdapter(Iterator iter) { + this.iterator = iter; + } + + @Override + public boolean hasMoreElements() { + return iterator.hasNext(); + } + + @Override + public T nextElement() { + return iterator.next(); + } + } + + /** + * Creates an Enumeration out of the given Iterator. + * + * @param g + * @param it g + * @return an Enumeration created out of the given Iterator. + */ + @SuppressWarnings("unused") + public static Enumeration createEnumerationFromIterator( + Iterator it) { + return new IteratorEnumerationAdapter<>(it); + } + + + /** + * Returns the first element of the list, null if the list is null or empty. + * + * @param f + * @param list f + * @return the first element of the list, null if the list is null or empty. + */ + public static T first(List list) { + if (list == null || list.isEmpty()) { + return null; + } + return list.get(0); + } + + /** + * Whether the given collection is null or has no elements. + * + * @param collection g + * @return Whether the given collection is null or has no elements. + */ + public static boolean isEmpty(Collection collection) { + return collection == null || collection.isEmpty(); + } +} diff --git a/book/src/main/java/me/ag2s/epublib/util/IOUtil.java b/modules/book/src/main/java/me/ag2s/epublib/util/IOUtil.java similarity index 99% rename from book/src/main/java/me/ag2s/epublib/util/IOUtil.java rename to modules/book/src/main/java/me/ag2s/epublib/util/IOUtil.java index c1a980ce7..d5e675505 100644 --- a/book/src/main/java/me/ag2s/epublib/util/IOUtil.java +++ b/modules/book/src/main/java/me/ag2s/epublib/util/IOUtil.java @@ -143,7 +143,7 @@ public class IOUtil { // public static void copy(InputStream in, OutputStream result) throws IOException { - copy(in, result,DEFAULT_BUFFER_SIZE); + copy(in, result, DEFAULT_BUFFER_SIZE); } /** diff --git a/book/src/main/java/me/ag2s/epublib/util/NoCloseOutputStream.java b/modules/book/src/main/java/me/ag2s/epublib/util/NoCloseOutputStream.java similarity index 56% rename from book/src/main/java/me/ag2s/epublib/util/NoCloseOutputStream.java rename to modules/book/src/main/java/me/ag2s/epublib/util/NoCloseOutputStream.java index 15a3893b6..86744c12f 100644 --- a/book/src/main/java/me/ag2s/epublib/util/NoCloseOutputStream.java +++ b/modules/book/src/main/java/me/ag2s/epublib/util/NoCloseOutputStream.java @@ -14,20 +14,20 @@ import java.io.OutputStream; @SuppressWarnings("unused") public class NoCloseOutputStream extends OutputStream { - private final OutputStream outputStream; + private final OutputStream outputStream; - public NoCloseOutputStream(OutputStream outputStream) { - this.outputStream = outputStream; - } + public NoCloseOutputStream(OutputStream outputStream) { + this.outputStream = outputStream; + } - @Override - public void write(int b) throws IOException { - outputStream.write(b); - } + @Override + public void write(int b) throws IOException { + outputStream.write(b); + } - /** - * A close() that does not call it's parent's close() - */ - public void close() { - } + /** + * A close() that does not call it's parent's close() + */ + public void close() { + } } diff --git a/book/src/main/java/me/ag2s/epublib/util/NoCloseWriter.java b/modules/book/src/main/java/me/ag2s/epublib/util/NoCloseWriter.java similarity index 53% rename from book/src/main/java/me/ag2s/epublib/util/NoCloseWriter.java rename to modules/book/src/main/java/me/ag2s/epublib/util/NoCloseWriter.java index ad1da9c7c..b71a5f405 100644 --- a/book/src/main/java/me/ag2s/epublib/util/NoCloseWriter.java +++ b/modules/book/src/main/java/me/ag2s/epublib/util/NoCloseWriter.java @@ -14,23 +14,23 @@ import java.io.Writer; @SuppressWarnings("unused") public class NoCloseWriter extends Writer { - private final Writer writer; + private final Writer writer; - public NoCloseWriter(Writer writer) { - this.writer = writer; - } + public NoCloseWriter(Writer writer) { + this.writer = writer; + } - @Override - public void close() { - } + @Override + public void close() { + } - @Override - public void flush() throws IOException { - writer.flush(); - } + @Override + public void flush() throws IOException { + writer.flush(); + } - @Override - public void write(char[] cbuf, int off, int len) throws IOException { - writer.write(cbuf, off, len); - } + @Override + public void write(char[] cbuf, int off, int len) throws IOException { + writer.write(cbuf, off, len); + } } diff --git a/book/src/main/java/me/ag2s/epublib/util/ResourceUtil.java b/modules/book/src/main/java/me/ag2s/epublib/util/ResourceUtil.java similarity index 100% rename from book/src/main/java/me/ag2s/epublib/util/ResourceUtil.java rename to modules/book/src/main/java/me/ag2s/epublib/util/ResourceUtil.java diff --git a/book/src/main/java/me/ag2s/epublib/util/StringUtil.java b/modules/book/src/main/java/me/ag2s/epublib/util/StringUtil.java similarity index 100% rename from book/src/main/java/me/ag2s/epublib/util/StringUtil.java rename to modules/book/src/main/java/me/ag2s/epublib/util/StringUtil.java diff --git a/book/src/main/java/me/ag2s/epublib/util/commons/io/BOMInputStream.java b/modules/book/src/main/java/me/ag2s/epublib/util/commons/io/BOMInputStream.java similarity index 84% rename from book/src/main/java/me/ag2s/epublib/util/commons/io/BOMInputStream.java rename to modules/book/src/main/java/me/ag2s/epublib/util/commons/io/BOMInputStream.java index 4e7c3ce5a..8d42c6e59 100644 --- a/book/src/main/java/me/ag2s/epublib/util/commons/io/BOMInputStream.java +++ b/modules/book/src/main/java/me/ag2s/epublib/util/commons/io/BOMInputStream.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -32,10 +32,10 @@ import me.ag2s.epublib.util.IOUtil; /** * This class is used to wrap a stream that includes an encoded {@link ByteOrderMark} as its first bytes. - * + *

* This class detects these bytes and, if required, can automatically skip them and return the subsequent byte as the * first byte in the stream. - * + *

* The {@link ByteOrderMark} implementation has the following pre-defined BOMs: *