EpubBook
EpubBook class represents a parsed EPUB book, following the Single Responsibility Principle, dedicated to storing book information as a data model. Business logic operations should use corresponding processor classes.
Constructor
public EpubBook()Creates an empty EpubBook instance.
public EpubBook(EpubBook other)Copy constructor for caching.
Parameters:
other: EpubBook instance to copy
Main Methods
Metadata Operations
getMetadata()
public Metadata getMetadata()Gets book metadata copy.
Returns:
Metadata: Book metadata object copy
setMetadata()
public void setMetadata(Metadata metadata)Sets book metadata.
Parameters:
metadata: Metadata object
Chapter Operations
getNcx()
public List<EpubChapter> getNcx()Gets NCX format table of contents chapter list.
Returns:
List<EpubChapter>: NCX table of contents list (unmodifiable)
setNcx()
public void setNcx(List<EpubChapter> ncx)Sets NCX format table of contents chapter list.
Parameters:
ncx: NCX table of contents list
getNav()
public List<EpubChapter> getNav()Gets NAV format table of contents chapter list.
Returns:
List<EpubChapter>: NAV table of contents list (unmodifiable)
setNav()
public void setNav(List<EpubChapter> nav)Sets NAV format table of contents chapter list.
Parameters:
nav: NAV table of contents list
getLandmarks()
public List<EpubChapter> getLandmarks()Gets landmark navigation chapter list.
Returns:
List<EpubChapter>: Landmark navigation list (unmodifiable)
setLandmarks()
public void setLandmarks(List<EpubChapter> landmarks)Sets landmark navigation chapter list.
Parameters:
landmarks: Landmark navigation list
getPageList()
public List<EpubChapter> getPageList()Gets page list navigation chapter list.
Returns:
List<EpubChapter>: Page list navigation list (unmodifiable)
setPageList()
public void setPageList(List<EpubChapter> pageList)Sets page list navigation chapter list.
Parameters:
pageList: Page list navigation list
getChapters()
public List<EpubChapter> getChapters()Gets main chapter list, preferring NAV table of contents if NAV is empty then NCX table of contents.
Returns:
List<EpubChapter>: Chapter list (unmodifiable)
Resource Operations
getResources()
public List<EpubResource> getResources()Gets resource file list.
Returns:
List<EpubResource>: Resource list (unmodifiable)
setResources()
public void setResources(List<EpubResource> resources)Sets resource file list.
Parameters:
resources: Resource list
Related Processor Classes
Since EpubBook follows the Single Responsibility Principle and is only responsible for data storage, business logic operations should use the following processor classes:
EpubBookProcessor
Handles book-related business logic:
getCover(EpubBook book)- Gets cover resourcegetResource(EpubBook book, String resourceId)- Gets specific resourcegetResourceWithFallback(EpubBook book, String resourceId)- Gets resource with fallback mechanismloadAllResourceData(EpubBook book)- Batch loads resource data
EpubStreamProcessor
Handles streaming operations:
processBookChapters(EpubBook book, BiConsumer<EpubChapter, InputStream> processor)- Streams book chapters
Usage Example
// Create EpubBook instance
EpubBook book = new EpubBook();
// Set metadata
Metadata metadata = new Metadata();
metadata.addTitle("Sample Book");
book.setMetadata(metadata);
// Set chapters
List<EpubChapter> chapters = new ArrayList<>();
// ... add chapters
book.setNcx(chapters);
// Set resources
List<EpubResource> resources = new ArrayList<>();
// ... add resources
book.setResources(resources);
// Use processor classes for business operations
EpubResource cover = EpubBookProcessor.getCover(book);
EpubResource resource = EpubBookProcessor.getResource(book, "image1");