Search in sources :

Example 11 with Publication

use of org.eclipse.mylyn.docs.epub.core.Publication in project mylyn.docs by eclipse.

the class TestEPUB method testRepack_AddItem.

/**
 * Verifies that an EPUB can be unpacked, modified and repacked.
 *
 * @throws Exception
 */
@Test
public final void testRepack_AddItem() throws Exception {
    File folder = File.createTempFile("epub_", null);
    folder.delete();
    folder.mkdirs();
    File epubFile = new File("testdata/epub/basic_2.epub");
    File epubFile2 = new File(folder, "repacked.epub");
    epub.unpack(epubFile, folder);
    Publication publication = epub.getOPSPublications().get(0);
    // remove the existing table of contents from the spine
    publication.removeItemById(publication.getSpine().getToc());
    // make sure a new one is generated
    publication.setGenerateToc(true);
    // add a new item to the spine
    publication.addItem(new File("testdata/plain-page_link.xhtml"));
    epub.pack(epubFile2, folder);
}
Also used : Publication(org.eclipse.mylyn.docs.epub.core.Publication) OPSPublication(org.eclipse.mylyn.docs.epub.core.OPSPublication) RootFile(org.eclipse.mylyn.docs.epub.ocf.RootFile) File(java.io.File) Test(org.junit.Test)

Example 12 with Publication

use of org.eclipse.mylyn.docs.epub.core.Publication in project mylyn.docs by eclipse.

the class TestEPUB method test_Bug378800.

/**
 * Test method for <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=378800">bug 378800</a>: [epub] Remove
 * "ocf" prefix from elements in container.xml
 *
 * @throws Exception
 */
@Test
public final void test_Bug378800() throws Exception {
    EPUB epub = new EPUB();
    Publication oebps = new OPSPublication();
    oebps.addItem(new File("testdata/plain-page.xhtml"));
    epub.add(oebps);
    epub.pack(epubFile, epubFolder);
    // $NON-NLS-1$
    File metaFolder = new File(epubFolder.getAbsolutePath() + File.separator + "META-INF");
    // $NON-NLS-1$
    File containerFile = new File(metaFolder.getAbsolutePath() + File.separator + "container.xml");
    BufferedReader br = new BufferedReader(new FileReader(containerFile));
    String in = null;
    boolean ok = false;
    while ((in = br.readLine()) != null) {
        // as opposed to "<ocf:container "
        if (in.startsWith("<container ")) {
            ok = true;
        }
    }
    br.close();
    assertEquals(true, ok);
}
Also used : EPUB(org.eclipse.mylyn.docs.epub.core.EPUB) BufferedReader(java.io.BufferedReader) Publication(org.eclipse.mylyn.docs.epub.core.Publication) OPSPublication(org.eclipse.mylyn.docs.epub.core.OPSPublication) FileReader(java.io.FileReader) OPSPublication(org.eclipse.mylyn.docs.epub.core.OPSPublication) RootFile(org.eclipse.mylyn.docs.epub.ocf.RootFile) File(java.io.File) Test(org.junit.Test)

Example 13 with Publication

use of org.eclipse.mylyn.docs.epub.core.Publication 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 14 with Publication

use of org.eclipse.mylyn.docs.epub.core.Publication in project mylyn.docs by eclipse.

the class TestPublication method test_Bug380016.

/**
 * Test method for <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=380016">bug 380016</a>: Reference scanner
 * should also include referenced CSS style sheets
 *
 * @throws Exception
 */
@Test
public final void test_Bug380016() throws Exception {
    oebps.setIncludeReferencedResources(true);
    oebps.addItem(new File("testdata/OPF-Tests/Bug_380016/chapter.xhtml"));
    epub.add(oebps);
    epub.pack(epubFile);
    EPUB epub2 = new EPUB();
    epub2.unpack(epubFile, epubFolder);
    Publication oebps = epub2.getOPSPublications().get(0);
    File root = oebps.getRootFolder();
    File svg = new File(root.getAbsolutePath() + File.separator + "style.css");
    Assert.assertTrue(svg.exists());
}
Also used : 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 15 with Publication

use of org.eclipse.mylyn.docs.epub.core.Publication in project mylyn.docs by eclipse.

the class TestPublication method test_Bug373052.

/**
 * Test method for <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=373052">bug 373052</a>: [epub] Reference
 * scanner does not handle absolute paths
 *
 * @throws Exception
 */
@Test
public final void test_Bug373052() throws Exception {
    // We need to link to a absolute file so we create a temporary HTML file
    // in which we have the link.m
    File htmlFile = File.createTempFile("temp", ".xhtml");
    File svgFile = new File("testdata/drawing.svg");
    FileWriter fw = new FileWriter(htmlFile);
    // A proper declaration must be added or the file type cannot be
    // correctly detected.
    fw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    fw.write("<!DOCTYPE html\n" + "  PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">");
    fw.write("<html xmlns=\"http://www.w3.org/1999/xhtml\"><body>");
    fw.write("<img src=\"" + svgFile.getAbsolutePath() + "\"/>");
    fw.write("</body></html>");
    fw.close();
    oebps.setIncludeReferencedResources(true);
    oebps.addItem(htmlFile);
    epub.add(oebps);
    epub.pack(epubFile);
    htmlFile.delete();
    EPUB epub2 = new EPUB();
    epub2.unpack(epubFile, epubFolder);
    Publication oebps = epub2.getOPSPublications().get(0);
    File root = oebps.getRootFolder();
    File svg = new File(root.getAbsolutePath() + File.separator + "drawing.svg");
    Assert.assertTrue(svg.exists());
}
Also used : FileWriter(java.io.FileWriter) 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)

Aggregations

OPSPublication (org.eclipse.mylyn.docs.epub.core.OPSPublication)16 Publication (org.eclipse.mylyn.docs.epub.core.Publication)16 Test (org.junit.Test)16 File (java.io.File)15 EPUB (org.eclipse.mylyn.docs.epub.core.EPUB)15 RootFile (org.eclipse.mylyn.docs.epub.ocf.RootFile)9 NavPoint (org.eclipse.mylyn.docs.epub.ncx.NavPoint)2 Ncx (org.eclipse.mylyn.docs.epub.ncx.Ncx)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 Meta (org.eclipse.mylyn.docs.epub.ncx.Meta)1 Container (org.eclipse.mylyn.docs.epub.ocf.Container)1 RootFiles (org.eclipse.mylyn.docs.epub.ocf.RootFiles)1