EpubParser
EpubParser is the main parser class of the EPUBime library, responsible for parsing EPUB files and generating EpubBook objects.
Constructor
public EpubParser(File epubFile)Creates a new EPUB parser instance.
Parameters:
epubFile: The EPUB file to parse
Main Methods
parse()
public EpubBook parse() throws EpubExceptionParses the EPUB file and returns an EpubBook object. If results are cached, returns the cached parsing result.
Returns:
EpubBook: The parsed EPUB book object
Throws:
EpubException: Error occurred during parsing
parseWithoutCache()
public EpubBook parseWithoutCache() throws EpubExceptionParses the EPUB file and returns an EpubBook object, skipping cache.
Returns:
EpubBook: The parsed EPUB book object
Throws:
EpubException: Error occurred during parsing
readEpubContent()
public static String readEpubContent(File epubFile, String entryPath) throws EpubExceptionDirectly reads specific content from an EPUB file.
Parameters:
epubFile: The EPUB fileentryPath: The internal file path to read
Returns:
String: File content
Throws:
EpubException: Error occurred during reading
processHtmlChapterContent()
public static void processHtmlChapterContent(File epubFile, String entryPath, ContentProcessor processor) throws EpubExceptionStreaming process HTML chapter content.
Parameters:
epubFile: The EPUB fileentryPath: Chapter file pathprocessor: Content processor
Throws:
EpubException: Error occurred during processing
processMultipleHtmlChapters()
public static void processMultipleHtmlChapters(File epubFile, List<String> entryPaths, ChapterContentProcessor processor) throws EpubExceptionBatch streaming process multiple HTML chapters.
Parameters:
epubFile: The EPUB fileentryPaths: List of chapter file pathsprocessor: Chapter content processor
Throws:
EpubException: Error occurred during processing
parseMetadata()
public static Metadata parseMetadata(String opfContent) throws EpubExceptionParses OPF file content and extracts metadata.
Parameters:
opfContent: OPF file content
Returns:
Metadata: The parsed metadata object
Throws:
EpubException: Error occurred during parsing
parseNcx()
public static List<EpubChapter> parseNcx(String ncxContent) throws EpubExceptionParses NCX file content and extracts chapter information.
Parameters:
ncxContent: NCX file content
Returns:
List<EpubChapter>: The parsed chapter list
Throws:
EpubException: Error occurred during parsing
parseNav()
public static List<EpubChapter> parseNav(String navContent) throws EpubExceptionParses NAV file content and extracts chapter information.
Parameters:
navContent: NAV file content
Returns:
List<EpubChapter>: The parsed chapter list
Throws:
EpubException: Error occurred during parsing
parseNavByType()
public static List<EpubChapter> parseNavByType(String navContent, String type) throws EpubExceptionParses NAV file content by type.
Parameters:
navContent: NAV file contenttype: Navigation type (e.g., "landmarks", "page-list")
Returns:
List<EpubChapter>: The parsed chapter list
Throws:
EpubException: Error occurred during parsing
getNcxPath()
public static String getNcxPath(String opfContent, String basePath) throws EpubExceptionGets the NCX file path from OPF file.
Parameters:
opfContent: OPF file contentbasePath: Base path
Returns:
String: NCX file path
Throws:
EpubException: Error occurred during parsing
getNavPath()
public static String getNavPath(String opfContent, String basePath) throws EpubExceptionGets the NAV file path from OPF file.
Parameters:
opfContent: OPF file contentbasePath: Base path
Returns:
String: NAV file path, or null if not found
Throws:
EpubException: Error occurred during parsing
parseResources()
public static List<EpubResource> parseResources(String opfContent, String basePath, File epubFile) throws EpubExceptionParses OPF file content and extracts all resource files.
Parameters:
opfContent: OPF file contentbasePath: Base pathepubFile: EPUB file
Returns:
List<EpubResource>: The parsed resource list
Throws:
EpubException: Error occurred during parsing