use of org.eclipse.mylyn.docs.epub.ncx.NavPoint 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.NavPoint 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.NavPoint 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.NavPoint 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.NavPoint in project mylyn.docs by eclipse.
the class TOCGenerator method endElement.
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
int currentLevel = isHeader(qName);
int parentLevel = currentLevel - 1;
// only handle header level specifications H1 through H6
if (currentLevel > 0 && currentLevel < 7) {
recording = false;
NavPoint navPoint = createNavPoint(buffer.toString());
// level immediately above, as one would expect.
if (currentLevel > 1) {
NavPoint parent = headers[parentLevel - 1];
while (parent == null && parentLevel > 1) {
parentLevel = parentLevel - 1;
parent = headers[parentLevel - 1];
}
if (parent == null) {
ncx.getNavMap().getNavPoints().add(navPoint);
headers[0] = navPoint;
} else {
parent.getNavPoints().add(navPoint);
headers[parentLevel] = navPoint;
}
} else {
ncx.getNavMap().getNavPoints().add(navPoint);
headers[0] = navPoint;
}
buffer.setLength(0);
}
}
Aggregations