Search in sources :

Example 1 with Ncx

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));
}
Also used : Ncx(org.eclipse.mylyn.docs.epub.ncx.Ncx) NavPoint(org.eclipse.mylyn.docs.epub.ncx.NavPoint) EPUB(org.eclipse.mylyn.docs.epub.core.EPUB) Publication(org.eclipse.mylyn.docs.epub.core.Publication) OPSPublication(org.eclipse.mylyn.docs.epub.core.OPSPublication) File(java.io.File) Test(org.junit.Test)

Example 2 with Ncx

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();
}
Also used : Ncx(org.eclipse.mylyn.docs.epub.ncx.Ncx) NavPoint(org.eclipse.mylyn.docs.epub.ncx.NavPoint) File(java.io.File) Test(org.junit.Test)

Example 3 with Ncx

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());
}
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 4 with Ncx

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();
    }
}
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) NavPoint(org.eclipse.mylyn.docs.epub.ncx.NavPoint) Test(org.junit.Test)

Example 5 with Ncx

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));
}
Also used : Meta(org.eclipse.mylyn.docs.epub.ncx.Meta) Ncx(org.eclipse.mylyn.docs.epub.ncx.Ncx) NavPoint(org.eclipse.mylyn.docs.epub.ncx.NavPoint) EPUB(org.eclipse.mylyn.docs.epub.core.EPUB) Publication(org.eclipse.mylyn.docs.epub.core.Publication) OPSPublication(org.eclipse.mylyn.docs.epub.core.OPSPublication) File(java.io.File) 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