@Test public void testReadWithNonRootLevelTOC() { Book book = new Book(); Resource ncxResource = new Resource(ncxData, "xhtml/toc.ncx"); Resource chapterResource = new Resource("id1", "Hello, world !".getBytes(), "xhtml/chapter1.html", MediatypeService.XHTML); book.addResource(chapterResource); book.getSpine().addResource(chapterResource); book.setNcxResource(ncxResource); book.getSpine().setTocResource(ncxResource); NCXDocument.read(book, new EpubReader()); assertEquals("xhtml/chapter1.html", book.getTableOfContents().getTocReferences().get(0).getCompleteHref()); }
public static Resource read(Book book, EpubReader epubReader) { Resource ncxResource = null; if(book.getSpine().getTocResource() == null) { return ncxResource; } try { ncxResource = book.getSpine().getTocResource(); if(ncxResource == null) { return ncxResource; } Document ncxDocument = ResourceUtil.getAsDocument(ncxResource); Element navMapElement = DOMUtil.getFirstElementByTagNameNS(ncxDocument.getDocumentElement(), NAMESPACE_NCX, NCXTags.navMap); TableOfContents tableOfContents = new TableOfContents(readTOCReferences(navMapElement.getChildNodes(), book)); book.setTableOfContents(tableOfContents); } catch (Exception e) { log.error(e.getMessage(), e); } return ncxResource; }
NCXDocument { public static Resource read(Book book, EpubReader epubReader) { Resource ncxResource = null; if(book.getSpine().getTocResource() == null) { return ncxResource; } try { ncxResource = book.getSpine().getTocResource(); if(ncxResource == null) { return ncxResource; } Document ncxDocument = ResourceUtil.getAsDocument(ncxResource); Element navMapElement = DOMUtil.getFirstElementByTagNameNS(ncxDocument.getDocumentElement(), NAMESPACE_NCX, NCXTags.navMap); TableOfContents tableOfContents = new TableOfContents(readTOCReferences(navMapElement.getChildNodes(), book)); book.setTableOfContents(tableOfContents); } catch (Exception e) { log.error(e.getMessage(), e); } return ncxResource; } }
NCXDocument { public static Resource read(Book book, EpubReader epubReader) { Resource ncxResource = null; if(book.getSpine().getTocResource() == null) { return ncxResource; } try { ncxResource = book.getSpine().getTocResource(); if(ncxResource == null) { return ncxResource; } Document ncxDocument = ResourceUtil.getAsDocument(ncxResource); Element navMapElement = DOMUtil.getFirstElementByTagNameNS(ncxDocument.getDocumentElement(), NAMESPACE_NCX, NCXTags.navMap); TableOfContents tableOfContents = new TableOfContents(readTOCReferences(navMapElement.getChildNodes(), book)); book.setTableOfContents(tableOfContents); } catch (Exception e) { log.error(e.getMessage(), e); } return ncxResource; }  }
NCXDocument { public static Resource read(Book book, EpubReader epubReader) { Resource ncxResource = null; if(book.getSpine().getTocResource() == null) { return ncxResource; } try { ncxResource = book.getSpine().getTocResource(); if(ncxResource == null) { return ncxResource; } Document ncxDocument = ResourceUtil.getAsDocument(ncxResource); Element navMapElement = DOMUtil.getFirstElementByTagNameNS(ncxDocument.getDocumentElement(), NAMESPACE_NCX, NCXTags.navMap); TableOfContents tableOfContents = new TableOfContents(readTOCReferences(navMapElement.getChildNodes(), book)); book.setTableOfContents(tableOfContents); } catch (Exception e) { log.error(e.getMessage(), e); } return ncxResource; }  static Resource read(Book book, EpubReader epubReader); static void write(EpubWriter epubWriter, Book book, ZipOutputStream resultStream); static void write(XmlSerializer xmlSerializer, Book book); static Resource createNCXResource(Book book); static Resource createNCXResource(List<Identifier> identifiers, DcmesElement title, List<Author> authors, TableOfContents tableOfContents); static void write(XmlSerializer serializer, List<Identifier> identifiers, DcmesElement title, List<Author> authors, TableOfContents tableOfContents); }
NCXDocument { public static Resource read(Book book, EpubReader epubReader) { Resource ncxResource = null; if(book.getSpine().getTocResource() == null) { return ncxResource; } try { ncxResource = book.getSpine().getTocResource(); if(ncxResource == null) { return ncxResource; } Document ncxDocument = ResourceUtil.getAsDocument(ncxResource); Element navMapElement = DOMUtil.getFirstElementByTagNameNS(ncxDocument.getDocumentElement(), NAMESPACE_NCX, NCXTags.navMap); TableOfContents tableOfContents = new TableOfContents(readTOCReferences(navMapElement.getChildNodes(), book)); book.setTableOfContents(tableOfContents); } catch (Exception e) { log.error(e.getMessage(), e); } return ncxResource; }  static Resource read(Book book, EpubReader epubReader); static void write(EpubWriter epubWriter, Book book, ZipOutputStream resultStream); static void write(XmlSerializer xmlSerializer, Book book); static Resource createNCXResource(Book book); static Resource createNCXResource(List<Identifier> identifiers, DcmesElement title, List<Author> authors, TableOfContents tableOfContents); static void write(XmlSerializer serializer, List<Identifier> identifiers, DcmesElement title, List<Author> authors, TableOfContents tableOfContents); static final String NAMESPACE_NCX; static final String PREFIX_NCX; static final String NCX_ITEM_ID; static final String DEFAULT_NCX_HREF; static final String PREFIX_DTB; }