Search in sources :

Example 6 with Ncx

use of org.eclipse.mylyn.docs.epub.ncx.Ncx in project mylyn.docs by eclipse.

the class TestOPSPublication method testGenerateEmptyTableOfContents.

/**
 * Test method for {@link org.eclipse.mylyn.docs.epub.core.OPSPublication#generateTableOfContents()} .
 * <ul>
 * <li>Table of contents shall exist but be empty if not otherwise specified.</li>
 * </ul>
 *
 * @throws Exception
 */
public final void testGenerateEmptyTableOfContents() throws Exception {
    epub.add(oebps);
    oebps.addItem(new File("testdata/plain-page.xhtml"));
    oebps.setGenerateToc(false);
    epub.pack(epubFile);
    assertTrue(oebps.getTableOfContents() != null);
    assertTrue(oebps.getTableOfContents() instanceof Ncx);
}
Also used : Ncx(org.eclipse.mylyn.docs.epub.ncx.Ncx) File(java.io.File)

Example 7 with Ncx

use of org.eclipse.mylyn.docs.epub.ncx.Ncx in project mylyn.docs by eclipse.

the class TestTOCGenerator method testMissingIdentifier.

@Test
public void testMissingIdentifier() throws ParserConfigurationException, SAXException, IOException {
    String html = "<body><h1 id='h1-1'>test</h1><h2>test</h2><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();
    assertEquals(2, points.size());
    // "h2" will be added as a sub-node to the first "h1" regardless of the
    // missing identifier.
    assertEquals(1, points.get(0).getNavPoints().size());
}
Also used : Ncx(org.eclipse.mylyn.docs.epub.ncx.Ncx) InputSource(org.xml.sax.InputSource) NavPoint(org.eclipse.mylyn.docs.epub.ncx.NavPoint) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 8 with Ncx

use of org.eclipse.mylyn.docs.epub.ncx.Ncx in project mylyn.docs by eclipse.

the class TestTOCGenerator method testMissingParent.

@Test
public void testMissingParent() throws ParserConfigurationException, SAXException, IOException {
    String html = "<body><h1 id='h1-1'>test</h1><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();
    // should be two items at level 1 and one at level 2
    assertEquals(2, points.size());
    assertEquals(1, points.get(0).getNavPoints().size());
}
Also used : Ncx(org.eclipse.mylyn.docs.epub.ncx.Ncx) InputSource(org.xml.sax.InputSource) NavPoint(org.eclipse.mylyn.docs.epub.ncx.NavPoint) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 9 with Ncx

use of org.eclipse.mylyn.docs.epub.ncx.Ncx in project mylyn.docs by eclipse.

the class TestTOCGenerator method createNcx.

private Ncx createNcx() {
    Ncx ncx = NCXFactory.eINSTANCE.createNcx();
    NavMap navMap = NCXFactory.eINSTANCE.createNavMap();
    ncx.setNavMap(navMap);
    return ncx;
}
Also used : Ncx(org.eclipse.mylyn.docs.epub.ncx.Ncx) NavMap(org.eclipse.mylyn.docs.epub.ncx.NavMap)

Example 10 with Ncx

use of org.eclipse.mylyn.docs.epub.ncx.Ncx in project mylyn.docs by eclipse.

the class TestTOCGenerator method testCrazyStructure.

@Test
public void testCrazyStructure() throws ParserConfigurationException, SAXException, IOException {
    String html = "<body><h3 id='h3-1'>test</h3><h2 id='h2-1'>test</h2><h1 id='h1-1'>test</h1></body>";
    Ncx ncx = createNcx();
    TOCGenerator.parse(new InputSource(new StringReader(html)), "test.html", ncx, 0);
    EList<NavPoint> points = ncx.getNavMap().getNavPoints();
    // "h3" will be created as a "h1" and "h2" added to it
    assertEquals(2, points.size());
}
Also used : Ncx(org.eclipse.mylyn.docs.epub.ncx.Ncx) InputSource(org.xml.sax.InputSource) NavPoint(org.eclipse.mylyn.docs.epub.ncx.NavPoint) StringReader(java.io.StringReader) Test(org.junit.Test)

Aggregations

Ncx (org.eclipse.mylyn.docs.epub.ncx.Ncx)10 NavPoint (org.eclipse.mylyn.docs.epub.ncx.NavPoint)8 Test (org.junit.Test)8 StringReader (java.io.StringReader)5 InputSource (org.xml.sax.InputSource)5 File (java.io.File)4 EPUB (org.eclipse.mylyn.docs.epub.core.EPUB)2 OPSPublication (org.eclipse.mylyn.docs.epub.core.OPSPublication)2 Publication (org.eclipse.mylyn.docs.epub.core.Publication)2 Meta (org.eclipse.mylyn.docs.epub.ncx.Meta)1 NavMap (org.eclipse.mylyn.docs.epub.ncx.NavMap)1