Class EpubBook


  • public class EpubBook
    extends Object
    Representation of an EPUB book
    Author:
    OpenCollab
    • Constructor Detail

      • EpubBook

        public EpubBook()
        Constructs EPUBBook
      • EpubBook

        public EpubBook​(String language,
                        String id,
                        String title,
                        String author)
        Constructs EPUBBook
        Parameters:
        language - the 2 letter language code set in the dc:language meta data
        id - the id used as the meta data dc:identifier
        title - the title of the book
        author - the author, this is set as the meta data dc:creator value
    • Method Detail

      • addContent

        public boolean addContent​(Content content)
        Adds content to the content list and checks the id. Only adds unique href's
        Parameters:
        content - the EpubBook content - TOC, pages, files
        Returns:
        boolean indicating if the content has been added
      • insertContent

        public boolean insertContent​(Content content,
                                     int index)
        Inserts content at a specific index. Only adds unique href's
        Parameters:
        content - the EpubBook content - TOC, pages, files
        index - index where the content will be inserted
        Returns:
        boolean indicating if the content has been added
      • addTextContent

        public Content addTextContent​(String title,
                                      String href,
                                      String content)
        Wraps a String in the HTML wrapper and adds create a content object that is added to the content list. Returns null if the href is not unique
        Parameters:
        title - the title of the page
        href - used as unique link
        content - text content to be added
        Returns:
        the Content object generated from the text
      • addContent

        public Content addContent​(byte[] contents,
                                  String mediaType,
                                  String href,
                                  boolean toc,
                                  boolean spine)
        Creates and adds file Content to the book
        Parameters:
        contents - the byte array content
        mediaType - the mime type
        href - used as unique link
        toc - flag whether it must be added to the TOC
        spine - flag whether it must be added to the spine
        Returns:
        a reference to the newly created Content object
      • addContent

        public Content addContent​(InputStream contents,
                                  String mediaType,
                                  String href,
                                  boolean toc,
                                  boolean spine)
                           throws IOException
        Creates and adds an InputStream to the book
        Parameters:
        contents - the InputStream to the content
        mediaType - the mime type
        href - used as unique link
        toc - flag whether it must be added to the TOC
        spine - flag whether it must be added to the spine
        Returns:
        a reference to the newly created Content object
        Throws:
        IOException - if the InputStream can not be converted to byte[]
      • addCoverImage

        public void addCoverImage​(byte[] coverImage,
                                  String mediaType,
                                  String href)
        Adds an file as the cover image
        Parameters:
        coverImage - the cover image
        mediaType - the mime type of the cover image
        href - used to name the cover image
      • writeToStream

        public void writeToStream​(OutputStream out)
                           throws Exception
        Creates the EPUB zip container and writes it to the OutputStream
        Parameters:
        out - the OutputStream
        Throws:
        Exception - if the content can not be zipped and written
      • writeToFile

        public void writeToFile​(String fileName)
                         throws Exception
        Creates the EPUB zip container and writes it to the File
        Parameters:
        fileName - to store as
        Throws:
        Exception - if the content can not be zipped and stored
      • getContents

        public List<Content> getContents()
        Returns:
        the contents
      • setContents

        public void setContents​(List<Content> contents)
        Parameters:
        contents - the content to set
      • isAutoToc

        public boolean isAutoToc()
        Returns:
        the autoToc
      • setAutoToc

        public void setAutoToc​(boolean autoToc)
        Parameters:
        autoToc - the autoToc to set
      • getLanguage

        public String getLanguage()
        Returns:
        the language
      • setLanguage

        public void setLanguage​(String language)
        Parameters:
        language - the language to set
      • getId

        public String getId()
        Returns:
        the id
      • setId

        public void setId​(String id)
        Parameters:
        id - the id to set
      • getTitle

        public String getTitle()
        Returns:
        the title
      • setTitle

        public void setTitle​(String title)
        Parameters:
        title - the title to set
      • getTocLinks

        public List<TocLink> getTocLinks()
        Returns:
        the tocLinks
      • setTocLinks

        public void setTocLinks​(List<TocLink> tocLinks)
        Parameters:
        tocLinks - the tocLinks to set
      • getLandmarks

        public List<Landmark> getLandmarks()
        Returns:
        the landmarks
      • setLandmarks

        public void setLandmarks​(List<Landmark> landmarks)
        Parameters:
        landmarks - the landmarks to set
      • getAuthor

        public String getAuthor()
        Returns:
        the author
      • setAuthor

        public void setAuthor​(String author)
        Parameters:
        author - the author to set
      • getEpubCreator

        public EpubWriter getEpubCreator()
        Returns:
        the epubCreator
      • getUniqueHrefs

        public Set getUniqueHrefs()
        Returns:
        the uniqueHrefs