Search in sources :

Example 6 with RootFile

use of org.eclipse.mylyn.docs.epub.ocf.RootFile in project mylyn.docs by eclipse.

the class TestEPUB method testAddFileString.

/**
 * Test method for {@link org.eclipse.mylyn.docs.epub.core.EPUB#add(java.io.File, java.lang.String)} .
 * <ul>
 * <li>Publication MIME-type shall be correct</li>
 * <li>Rootfile path shall be correct</li>
 * <li>Rootfile object shall be correct.</li>
 * </ul>
 *
 * @throws Exception
 */
@Test
public final void testAddFileString() throws Exception {
    EPUB epub = new EPUB();
    File drawing = new File("testdata/drawing.svg");
    epub.add(drawing, "image/svg+xml");
    Container container = epub.getContainer();
    RootFiles rootfiles = container.getRootfiles();
    EList<RootFile> files = rootfiles.getRootfiles();
    assertEquals(true, files.get(0).getFullPath().equals("SVG+XML/drawing.svg"));
    assertEquals(true, files.get(0).getMediaType().equals("image/svg+xml"));
    assertEquals(true, files.get(0).getPublication() == drawing);
}
Also used : Container(org.eclipse.mylyn.docs.epub.ocf.Container) EPUB(org.eclipse.mylyn.docs.epub.core.EPUB) RootFiles(org.eclipse.mylyn.docs.epub.ocf.RootFiles) RootFile(org.eclipse.mylyn.docs.epub.ocf.RootFile) RootFile(org.eclipse.mylyn.docs.epub.ocf.RootFile) File(java.io.File) Test(org.junit.Test)

Example 7 with RootFile

use of org.eclipse.mylyn.docs.epub.ocf.RootFile in project mylyn.docs by eclipse.

the class EPUB method add.

/**
 * Adds a new OEBPS publication to the EPUB. Use {@link #add(File, String)} to add other types of content.
 * <p>
 * Note that while an {@link EPUB} can technically contain multiple instances of an {@link Publication}, in practice
 * reading systems does not support this.
 * </p>
 *
 * @param oebps
 *            the publication to add.
 * @since 2.0
 */
public void add(Publication oebps) {
    RootFiles rootFiles = ocfContainer.getRootfiles();
    int count = rootFiles.getRootfiles().size();
    if (count >= 1) {
        // $NON-NLS-1$
        log("Multiple root files is unsupported by most reading systems!", Severity.WARNING);
    }
    // $NON-NLS-1$ //$NON-NLS-2$
    String rootFileName = count > 0 ? "OEBPS_" + count : "OEBPS";
    // $NON-NLS-1$
    rootFileName += "/content.opf";
    RootFile rootFile = OCFFactory.eINSTANCE.createRootFile();
    rootFile.setFullPath(rootFileName);
    rootFile.setMediaType(MIMETYPE_OEBPS);
    rootFile.setPublication(oebps);
    rootFiles.getRootfiles().add(rootFile);
    log(// $NON-NLS-1$
    MessageFormat.format(// $NON-NLS-1$
    Messages.getString("EPUB.0"), // $NON-NLS-1$
    rootFile.getFullPath(), rootFile.getMediaType()), Severity.VERBOSE);
}
Also used : RootFiles(org.eclipse.mylyn.docs.epub.ocf.RootFiles) RootFile(org.eclipse.mylyn.docs.epub.ocf.RootFile)

Aggregations

RootFile (org.eclipse.mylyn.docs.epub.ocf.RootFile)7 RootFiles (org.eclipse.mylyn.docs.epub.ocf.RootFiles)5 File (java.io.File)3 EPUB (org.eclipse.mylyn.docs.epub.core.EPUB)3 Container (org.eclipse.mylyn.docs.epub.ocf.Container)3 Test (org.junit.Test)3 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 OPSPublication (org.eclipse.mylyn.docs.epub.core.OPSPublication)1 Publication (org.eclipse.mylyn.docs.epub.core.Publication)1