Package nl.siegmann.epublib.epub
Class PackageDocumentReader
- java.lang.Object
-
- nl.siegmann.epublib.epub.PackageDocumentBase
-
- nl.siegmann.epublib.epub.PackageDocumentReader
-
public class PackageDocumentReader extends PackageDocumentBase
Reads the opf package document as defined by namespace http://www.idpf.org/2007/opf
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class nl.siegmann.epublib.epub.PackageDocumentBase
PackageDocumentBase.DCAttributes, PackageDocumentBase.DCTags, PackageDocumentBase.OPFAttributes, PackageDocumentBase.OPFTags, PackageDocumentBase.OPFValues
-
-
Field Summary
Fields Modifier and Type Field Description private static org.slf4j.Loggerlogprivate static java.lang.String[]POSSIBLE_NCX_ITEM_IDS-
Fields inherited from class nl.siegmann.epublib.epub.PackageDocumentBase
BOOK_ID_ID, dateFormat, NAMESPACE_DUBLIN_CORE, NAMESPACE_OPF, PREFIX_DUBLIN_CORE, PREFIX_OPF
-
-
Constructor Summary
Constructors Constructor Description PackageDocumentReader()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static java.util.Set<java.lang.String>findCoverHrefs(org.w3c.dom.Document packageDocument)Find all resources that have something to do with the coverpage and the cover image.(package private) static ResourcefindTableOfContentsResource(java.lang.String tocResourceId, Resources resources)The spine tag should contain a 'toc' attribute with as value the resource id of the table of contents resource.(package private) static ResourcesfixHrefs(java.lang.String packageHref, Resources resourcesByHref)Strips off the package prefixes up to the href of the packageHref.private static SpinegenerateSpineFromResources(Resources resources)Creates a spine out of all resources in the resources.static voidread(Resource packageResource, EpubReader epubReader, Book book, Resources resources)private static voidreadCover(org.w3c.dom.Document packageDocument, Book book)Finds the cover resource in the packageDocument and adds it to the book if found.private static voidreadGuide(org.w3c.dom.Document packageDocument, EpubReader epubReader, Book book, Resources resources)Reads the book's guide.private static ResourcesreadManifest(org.w3c.dom.Document packageDocument, java.lang.String packageHref, EpubReader epubReader, Resources resources, java.util.Map<java.lang.String,java.lang.String> idMapping)Reads the manifest containing the resource ids, hrefs and mediatypes.private static SpinereadSpine(org.w3c.dom.Document packageDocument, Resources resources, java.util.Map<java.lang.String,java.lang.String> idMapping)Reads the document's spine, containing all sections in reading order.
-
-
-
Method Detail
-
read
public static void read(Resource packageResource, EpubReader epubReader, Book book, Resources resources) throws java.io.UnsupportedEncodingException, org.xml.sax.SAXException, java.io.IOException, javax.xml.parsers.ParserConfigurationException
- Throws:
java.io.UnsupportedEncodingExceptionorg.xml.sax.SAXExceptionjava.io.IOExceptionjavax.xml.parsers.ParserConfigurationException
-
readManifest
private static Resources readManifest(org.w3c.dom.Document packageDocument, java.lang.String packageHref, EpubReader epubReader, Resources resources, java.util.Map<java.lang.String,java.lang.String> idMapping)
Reads the manifest containing the resource ids, hrefs and mediatypes.- Parameters:
packageDocument-packageHref-epubReader-book-resourcesByHref-- Returns:
- a Map with resources, with their id's as key.
-
readGuide
private static void readGuide(org.w3c.dom.Document packageDocument, EpubReader epubReader, Book book, Resources resources)Reads the book's guide. Here some more attempts are made at finding the cover page.- Parameters:
packageDocument-epubReader-book-resources-
-
fixHrefs
static Resources fixHrefs(java.lang.String packageHref, Resources resourcesByHref)
Strips off the package prefixes up to the href of the packageHref. Example: If the packageHref is "OEBPS/content.opf" then a resource href like "OEBPS/foo/bar.html" will be turned into "foo/bar.html"- Parameters:
packageHref-resourcesByHref-- Returns:
- The stripped package href
-
readSpine
private static Spine readSpine(org.w3c.dom.Document packageDocument, Resources resources, java.util.Map<java.lang.String,java.lang.String> idMapping)
Reads the document's spine, containing all sections in reading order.- Parameters:
packageDocument-epubReader-book-resourcesById-- Returns:
- the document's spine, containing all sections in reading order.
-
generateSpineFromResources
private static Spine generateSpineFromResources(Resources resources)
Creates a spine out of all resources in the resources. The generated spine consists of all XHTML pages in order of their href.- Parameters:
resources-- Returns:
- a spine created out of all resources in the resources.
-
findTableOfContentsResource
static Resource findTableOfContentsResource(java.lang.String tocResourceId, Resources resources)
The spine tag should contain a 'toc' attribute with as value the resource id of the table of contents resource. Here we try several ways of finding this table of contents resource. We try the given attribute value, some often-used ones and finally look through all resources for the first resource with the table of contents mimetype.- Parameters:
spineElement-resourcesById-- Returns:
- the Resource containing the table of contents
-
findCoverHrefs
static java.util.Set<java.lang.String> findCoverHrefs(org.w3c.dom.Document packageDocument)
Find all resources that have something to do with the coverpage and the cover image. Search the meta tags and the guide references- Parameters:
packageDocument-- Returns:
- all resources that have something to do with the coverpage and the cover image.
-
readCover
private static void readCover(org.w3c.dom.Document packageDocument, Book book)Finds the cover resource in the packageDocument and adds it to the book if found. Keeps the cover resource in the resources map- Parameters:
packageDocument-book-resources-
-
-