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;
}
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));
}
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";
}
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());
}
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());
}
Aggregations