use of org.eclipse.mylyn.docs.epub.ncx.Ncx in project mylyn.docs by eclipse.
the class TestOPSPublication method testReadTableOfContents.
/**
* Test method for {@link org.eclipse.mylyn.docs.epub.core.OPSPublication#readTableOfContents(java.io.File)} .
*
* @throws Exception
*/
@Test
public final void testReadTableOfContents() throws Exception {
epub.add(oebps);
oebps.addItem(new File("testdata/plain-page.xhtml"));
epub.pack(epubFile);
EPUB epub_in = new EPUB();
epub_in.unpack(epubFile, epubFolder);
Publication oebps_in = epub_in.getOPSPublications().get(0);
assertTrue(oebps_in.getTableOfContents() != null);
assertTrue(oebps_in.getTableOfContents() instanceof Ncx);
Ncx ncx = (Ncx) oebps_in.getTableOfContents();
NavPoint h1_1 = ncx.getNavMap().getNavPoints().get(0);
NavPoint h1_2 = ncx.getNavMap().getNavPoints().get(1);
assertEquals("First item", getText(h1_1));
assertEquals("Second item", getText(h1_2));
}
use of org.eclipse.mylyn.docs.epub.ncx.Ncx in project mylyn.docs by eclipse.
the class TestOPSPublication method testGenerateTableOfContents.
/**
* Test method for {@link org.eclipse.mylyn.docs.epub.core.OPSPublication#generateTableOfContents()} .
* <ul>
* <li>Table of contents shall be generated from content per default.</li>
* </ul>
*
* @throws Exception
*/
@Test
public final void testGenerateTableOfContents() throws Exception {
epub.add(oebps);
oebps.addItem(new File("testdata/plain-page.xhtml"));
epub.pack(epubFile);
assertTrue(oebps.getTableOfContents() != null);
assertTrue(oebps.getTableOfContents() instanceof Ncx);
Ncx ncx = (Ncx) oebps.getTableOfContents();
NavPoint h1_1 = ncx.getNavMap().getNavPoints().get(0);
NavPoint h1_2 = ncx.getNavMap().getNavPoints().get(1);
assertEquals("First item", getText(h1_1));
assertEquals("Second item", getText(h1_2));
epubFile.delete();
}
use of org.eclipse.mylyn.docs.epub.ncx.Ncx in project mylyn.docs by eclipse.
the class TestTOCGenerator method testNormal.
@Test
public void testNormal() throws ParserConfigurationException, SAXException, IOException {
String html = "<body><h1 id='h1-1'>test</h1><h2 id='h2-1'>test</h2><h2 id='h2-2'>test</h2>" + "<h3 id='h3-1'>test</h3><h1 id='h1-2'>test</h1></body>";
Ncx ncx = createNcx();
TOCGenerator.parse(new InputSource(new StringReader(html)), "test.html", ncx, 0);
EList<NavPoint> points = ncx.getNavMap().getNavPoints();
// h1
assertEquals(2, points.size());
// h2
assertEquals(2, points.get(0).getNavPoints().size());
// h3
assertEquals(1, points.get(0).getNavPoints().get(1).getNavPoints().size());
}
use of org.eclipse.mylyn.docs.epub.ncx.Ncx in project mylyn.docs by eclipse.
the class TestTOCGenerator method testH1throughH6.
/**
* Verifies that the table of contents generator is capable of handling all levels from 1 through 6.
*/
@Test
public void testH1throughH6() throws ParserConfigurationException, SAXException, IOException {
StringBuilder sb = new StringBuilder();
sb.append("<body>");
for (int i = 1; i < 7; i++) {
sb.append(String.format("<h%1$d id='h%1$d'>test</h%1$d>%n", i));
}
sb.append("</body>");
Ncx ncx = createNcx();
TOCGenerator.parse(new InputSource(new StringReader(sb.toString())), "test.html", ncx, 0);
EList<NavPoint> points = ncx.getNavMap().getNavPoints();
for (int i = 1; i < 6; i++) {
assertEquals(1, points.size());
points = points.get(0).getNavPoints();
}
}
use of org.eclipse.mylyn.docs.epub.ncx.Ncx in project mylyn.docs by eclipse.
the class TestOPSPublication method testSetTableOfContents.
/**
* Test method for {@link org.eclipse.mylyn.docs.epub.core.OPSPublication#setTableOfContents(java.io.File)} .
*
* @throws Exception
*/
@Test
public final void testSetTableOfContents() throws Exception {
oebps.setTableOfContents(new File("testdata/toc.ncx"));
epub.add(oebps);
oebps.addItem(new File("testdata/plain-page.xhtml"));
epub.pack(epubFile);
EPUB epub_in = new EPUB();
epub_in.unpack(epubFile, epubFolder);
Publication oebps_in = epub_in.getOPSPublications().get(0);
assertTrue(oebps_in.getTableOfContents() != null);
assertTrue(oebps_in.getTableOfContents() instanceof Ncx);
Ncx ncx = (Ncx) oebps_in.getTableOfContents();
NavPoint h1_1 = ncx.getNavMap().getNavPoints().get(0);
NavPoint h1_2 = ncx.getNavMap().getNavPoints().get(1);
assertEquals("First item", getText(h1_1));
assertEquals("Second item", getText(h1_2));
Meta meta = ncx.getHead().getMetas().get(0);
String id = getText(meta);
// The UUID for the NCX file should be different if it comes from
// another NCX than the one specified.
assertTrue(TOCFILE_ID.equals(id));
}
Aggregations