use of org.eclipse.mylyn.docs.epub.ncx.Meta in project mylyn.docs by eclipse.
the class OPSPublication method generateTableOfContents.
/**
* This mechanism will traverse the spine of the publication (which is representing the reading order) and parse
* each file for information that can be used to assemble a table of contents. Only XHTML type of files will be
* taken into consideration.
*
* @throws SAXException
* @throws IOException
* @throws ParserConfigurationException
*/
@Override
protected void generateTableOfContents() throws ParserConfigurationException, SAXException, IOException {
// $NON-NLS-1$
log(Messages.getString("OPS2Publication.0"), Severity.INFO, indent++);
Meta meta = NCXFactory.eINSTANCE.createMeta();
// $NON-NLS-1$
meta.setName("dtb:uid");
meta.setContent(getIdentifier().getMixed().getValue(0).toString());
ncxTOC.getHead().getMetas().add(meta);
int playOrder = 0;
// Iterate over the spine
EList<Itemref> spineItems = getSpine().getSpineItems();
EList<Item> manifestItems = opfPackage.getManifest().getItems();
for (Itemref itemref : spineItems) {
Item referencedItem = null;
String id = itemref.getIdref();
// Find the manifest item that is referenced
for (Item item : manifestItems) {
if (item.getId().equals(id)) {
referencedItem = item;
break;
}
}
if (referencedItem != null && !referencedItem.isNoToc() && referencedItem.getMedia_type().equals(MIMETYPE_XHTML)) {
File file = new File(referencedItem.getFile());
FileInputStream fis = new FileInputStream(file);
log(// $NON-NLS-1$
MessageFormat.format(Messages.getString("OPS2Publication.1"), referencedItem.getHref()), Severity.VERBOSE, indent);
playOrder = TOCGenerator.parse(new InputSource(fis), referencedItem.getHref(), ncxTOC, playOrder);
}
}
indent--;
}
use of org.eclipse.mylyn.docs.epub.ncx.Meta 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.Meta 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";
}
Aggregations