Search in sources :

Example 1 with Meta

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--;
}
Also used : Meta(org.eclipse.mylyn.docs.epub.ncx.Meta) Item(org.eclipse.mylyn.docs.epub.opf.Item) InputSource(org.xml.sax.InputSource) Itemref(org.eclipse.mylyn.docs.epub.opf.Itemref) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with Meta

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));
}
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 3 with Meta

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

Aggregations

Meta (org.eclipse.mylyn.docs.epub.ncx.Meta)3 File (java.io.File)2 NavPoint (org.eclipse.mylyn.docs.epub.ncx.NavPoint)2 FileInputStream (java.io.FileInputStream)1 FeatureMap (org.eclipse.emf.ecore.util.FeatureMap)1 FeatureEList (org.eclipse.emf.ecore.util.FeatureMapUtil.FeatureEList)1 EPUB (org.eclipse.mylyn.docs.epub.core.EPUB)1 OPSPublication (org.eclipse.mylyn.docs.epub.core.OPSPublication)1 Publication (org.eclipse.mylyn.docs.epub.core.Publication)1 Ncx (org.eclipse.mylyn.docs.epub.ncx.Ncx)1 Item (org.eclipse.mylyn.docs.epub.opf.Item)1 Itemref (org.eclipse.mylyn.docs.epub.opf.Itemref)1 Test (org.junit.Test)1 InputSource (org.xml.sax.InputSource)1