Class PackageDocumentReader


  • public class PackageDocumentReader
    extends PackageDocumentBase
    Reads the opf package document as defined by namespace http://www.idpf.org/2007/opf
    • Field Detail

      • log

        private static final org.slf4j.Logger log
      • POSSIBLE_NCX_ITEM_IDS

        private static final java.lang.String[] POSSIBLE_NCX_ITEM_IDS
    • Constructor Detail

      • PackageDocumentReader

        public PackageDocumentReader()
    • 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.UnsupportedEncodingException
        org.xml.sax.SAXException
        java.io.IOException
        javax.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 -