Search in sources :

Example 6 with NavPoint

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

the class TOCGenerator method createNavPoint.

private NavPoint createNavPoint(String title) {
    NavPoint np = NCXFactory.eINSTANCE.createNavPoint();
    NavLabel nl = NCXFactory.eINSTANCE.createNavLabel();
    Content c = NCXFactory.eINSTANCE.createContent();
    // $NON-NLS-1$
    c.setSrc(currentId == null ? currentHref : currentHref + "#" + currentId);
    Text text = NCXFactory.eINSTANCE.createText();
    FeatureMapUtil.addText(text.getMixed(), title);
    nl.setText(text);
    np.getNavLabels().add(nl);
    np.setPlayOrder(++playOrder);
    // $NON-NLS-1$
    np.setId("navpoint" + playOrder);
    np.setContent(c);
    return np;
}
Also used : NavLabel(org.eclipse.mylyn.docs.epub.ncx.NavLabel) NavPoint(org.eclipse.mylyn.docs.epub.ncx.NavPoint) Content(org.eclipse.mylyn.docs.epub.ncx.Content) Text(org.eclipse.mylyn.docs.epub.ncx.Text)

Example 7 with NavPoint

use of org.eclipse.mylyn.docs.epub.ncx.NavPoint 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)

Example 8 with NavPoint

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

the class TestOPSPublication method getText.

@SuppressWarnings("rawtypes")
public String getText(Object element) {
    if (element instanceof NavPoint) {
        FeatureMap fm = ((NavPoint) element).getNavLabels().get(0).getText().getMixed();
        Object o = fm.get(TEXT, false);
        if (o instanceof FeatureEList) {
            if (((FeatureEList) o).size() > 0) {
                return ((FeatureEList) o).get(0).toString();
            }
        }
    }
    if (element instanceof Meta) {
        Object o = ((Meta) element).getContent();
        return o.toString();
    }
    return "null";
}
Also used : FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) FeatureEList(org.eclipse.emf.ecore.util.FeatureMapUtil.FeatureEList) Meta(org.eclipse.mylyn.docs.epub.ncx.Meta) NavPoint(org.eclipse.mylyn.docs.epub.ncx.NavPoint)

Example 9 with NavPoint

use of org.eclipse.mylyn.docs.epub.ncx.NavPoint 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 10 with NavPoint

use of org.eclipse.mylyn.docs.epub.ncx.NavPoint 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)

Aggregations

NavPoint (org.eclipse.mylyn.docs.epub.ncx.NavPoint)11 Ncx (org.eclipse.mylyn.docs.epub.ncx.Ncx)8 Test (org.junit.Test)8 StringReader (java.io.StringReader)5 InputSource (org.xml.sax.InputSource)5 File (java.io.File)3 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)2 FeatureMap (org.eclipse.emf.ecore.util.FeatureMap)1 FeatureEList (org.eclipse.emf.ecore.util.FeatureMapUtil.FeatureEList)1 Content (org.eclipse.mylyn.docs.epub.ncx.Content)1 NavLabel (org.eclipse.mylyn.docs.epub.ncx.NavLabel)1 Text (org.eclipse.mylyn.docs.epub.ncx.Text)1