Class Book

  • All Implemented Interfaces:
    java.io.Serializable

    public class Book
    extends java.lang.Object
    implements java.io.Serializable
    Representation of a Book. All resources of a Book (html, css, xml, fonts, images) are represented as Resources. See getResources() for access to these.
    A Book as 3 indexes into these Resources, as per the epub specification.
    Spine
    these are the Resources to be shown when a user reads the book from start to finish.
    Table of Contents
    The table of contents. Table of Contents references may be in a different order and contain different Resources than the spine, and often do.
    Guide
    The Guide has references to a set of special Resources like the cover page, the Glossary, the copyright page, etc.

    The complication is that these 3 indexes may and usually do point to different pages. A chapter may be split up in 2 pieces to fit it in to memory. Then the spine will contain both pieces, but the Table of Contents only the first. The Content page may be in the Table of Contents, the Guide, but not in the Spine. Etc.

    image/svg+xml Spine Table of Contents Guide Chapter 1 Chapter 1 Part 2 Chapter 2 Chapter 1 Chapter 2 Cover Resources Preface

    See Also:
    Serialized Form
    • Constructor Detail

      • Book

        public Book()
    • Method Detail

      • addSection

        public TOCReference addSection​(TOCReference parentSection,
                                       java.lang.String sectionTitle,
                                       Resource resource)
        Adds the resource to the table of contents of the book as a child section of the given parentSection
        Parameters:
        parentSection -
        sectionTitle -
        resource -
        Returns:
        The table of contents
      • generateSpineFromTableOfContents

        public void generateSpineFromTableOfContents()
      • addSection

        public TOCReference addSection​(java.lang.String title,
                                       Resource resource)
        Adds a resource to the book's set of resources, table of contents and if there is no resource with the id in the spine also adds it to the spine.
        Parameters:
        title -
        resource -
        Returns:
        The table of contents
      • getMetadata

        public Metadata getMetadata()
        The Book's metadata (titles, authors, etc)
        Returns:
        The Book's metadata (titles, authors, etc)
      • setMetadata

        public void setMetadata​(Metadata metadata)
      • setResources

        public void setResources​(Resources resources)
      • getResources

        public Resources getResources()
        The collection of all images, chapters, sections, xhtml files, stylesheets, etc that make up the book.
        Returns:
        The collection of all images, chapters, sections, xhtml files, stylesheets, etc that make up the book.
      • getSpine

        public Spine getSpine()
        The sections of the book that should be shown if a user reads the book from start to finish.
        Returns:
        The Spine
      • setSpine

        public void setSpine​(Spine spine)
      • getTableOfContents

        public TableOfContents getTableOfContents()
        The Table of Contents of the book.
        Returns:
        The Table of Contents of the book.
      • setTableOfContents

        public void setTableOfContents​(TableOfContents tableOfContents)
      • getCoverPage

        public Resource getCoverPage()
        The book's cover page as a Resource. An XHTML document containing a link to the cover image.
        Returns:
        The book's cover page as a Resource
      • setCoverPage

        public void setCoverPage​(Resource coverPage)
      • getTitle

        public java.lang.String getTitle()
        Gets the first non-blank title from the book's metadata.
        Returns:
        the first non-blank title from the book's metadata.
      • getCoverImage

        public Resource getCoverImage()
        The book's cover image.
        Returns:
        The book's cover image.
      • setCoverImage

        public void setCoverImage​(Resource coverImage)
      • getGuide

        public Guide getGuide()
        The guide; contains references to special sections of the book like colophon, glossary, etc.
        Returns:
        The guide; contains references to special sections of the book like colophon, glossary, etc.
      • getContents

        public java.util.List<Resource> getContents()
        All Resources of the Book that can be reached via the Spine, the TableOfContents or the Guide.

        Consists of a list of "reachable" resources:

        • The coverpage
        • The resources of the Spine that are not already in the result
        • The resources of the Table of Contents that are not already in the result
        • The resources of the Guide that are not already in the result
        To get all html files that make up the epub file use getResources()
        Returns:
        All Resources of the Book that can be reached via the Spine, the TableOfContents or the Guide.
      • addToContentsResult

        private static void addToContentsResult​(Resource resource,
                                                java.util.Map<java.lang.String,​Resource> allReachableResources)
      • getOpfResource

        public Resource getOpfResource()
      • setOpfResource

        public void setOpfResource​(Resource opfResource)
      • setNcxResource

        public void setNcxResource​(Resource ncxResource)
      • getNcxResource

        public Resource getNcxResource()