Package nl.siegmann.epublib.domain

Examples of nl.siegmann.epublib.domain.Resource


  public void testWritingBookWithCoverWithNullId() throws FileNotFoundException, IOException {
    Book book = new Book();
      book.getMetadata().addTitle("Epub test book 1");
      book.getMetadata().addAuthor(new Author("Joe", "Tester"));
      InputStream is = this.getClass().getResourceAsStream("/book1/cover.png");
      book.setCoverImage(new Resource(is, "cover.png"));
      // Add Chapter 1
      InputStream is1 = this.getClass().getResourceAsStream("/book1/chapter1.html");
      book.addSection("Introduction", new Resource(is1, "chapter1.html"));
 
      EpubWriter epubWriter = new EpubWriter();
      epubWriter.write(book, new FileOutputStream("test1_book1.epub"));
  }
View Full Code Here


    book.getMetadata().addTitle("Epublib test book 1");
    book.getMetadata().addTitle("test2");
   
    book.getMetadata().addIdentifier(new Identifier(Identifier.Scheme.ISBN, "987654321"));
    book.getMetadata().addAuthor(new Author("Joe", "Tester"));
    book.setCoverPage(new Resource(this.getClass().getResourceAsStream("/book1/cover.html"), "cover.html"));
    book.setCoverImage(new Resource(this.getClass().getResourceAsStream("/book1/cover.png"), "cover.png"));
    book.addSection("Chapter 1", new Resource(this.getClass().getResourceAsStream("/book1/chapter1.html"), "chapter1.html"));
    book.addResource(new Resource(this.getClass().getResourceAsStream("/book1/book1.css"), "book1.css"));
    TOCReference chapter2 = book.addSection("Second chapter", new Resource(this.getClass().getResourceAsStream("/book1/chapter2.html"), "chapter2.html"));
    book.addResource(new Resource(this.getClass().getResourceAsStream("/book1/flowers_320x240.jpg"), "flowers.jpg"));
    book.addSection(chapter2, "Chapter 2 section 1", new Resource(this.getClass().getResourceAsStream("/book1/chapter2_1.html"), "chapter2_1.html"));
    book.addSection("Chapter 3", new Resource(this.getClass().getResourceAsStream("/book1/chapter3.html"), "chapter3.html"));
    return book;
  }
View Full Code Here

    @After
    public void tearDown() {
    }

    private void addResource(Book book, String filename) {
        Resource chapterResource = new Resource("id1", "Hello, world !".getBytes(), filename, MediatypeService.XHTML);
        book.addResource(chapterResource);
        book.getSpine().addResource(chapterResource);
    }
View Full Code Here

    @Test
    public void testReadWithNonRootLevelTOC() {
       
        // If the tox.ncx file is not in the root, the hrefs it refers to need to preserve its path.
        Book book = new Book();
        Resource ncxResource = new Resource(ncxData, "xhtml/toc.ncx");
        addResource(book, "xhtml/chapter1.html");
        addResource(book, "xhtml/chapter2.html");
        addResource(book, "xhtml/chapter2_1.html");
        addResource(book, "xhtml/chapter3.html");
View Full Code Here

    Assert.assertNotNull(resources);
    Assert.assertEquals(12, resources.getAll().size());
    List<String> allHrefs = new ArrayList<String>(resources.getAllHrefs());
    Collections.sort(allHrefs);
   
    Resource resource;
    byte[] expectedData;
   
    // container
    resource = resources.getByHref(allHrefs.get(0));
    Assert.assertEquals("container", resource.getId());
    Assert.assertEquals("META-INF/container.xml", resource.getHref());
    Assert.assertNull(resource.getMediaType());
    Assert.assertEquals(230, resource.getData().length);
   
    // book1.css
    resource = resources.getByHref(allHrefs.get(1));
    Assert.assertEquals("book1", resource.getId());
    Assert.assertEquals("OEBPS/book1.css", resource.getHref());
    Assert.assertEquals(MediatypeService.CSS, resource.getMediaType());
    Assert.assertEquals(65, resource.getData().length);
    expectedData = IOUtil.toByteArray(this.getClass().getResourceAsStream("/book1/book1.css"));
    Assert.assertTrue(Arrays.equals(expectedData, resource.getData()));
   
   
    // chapter1
    resource = resources.getByHref(allHrefs.get(2));
    Assert.assertEquals("chapter1", resource.getId());
    Assert.assertEquals("OEBPS/chapter1.html", resource.getHref());
    Assert.assertEquals(MediatypeService.XHTML, resource.getMediaType());
    Assert.assertEquals(247, resource.getData().length);
    expectedData = IOUtil.toByteArray(this.getClass().getResourceAsStream("/book1/chapter1.html"));
    Assert.assertTrue(Arrays.equals(expectedData, resource.getData()));
  }
View Full Code Here

TOP

Related Classes of nl.siegmann.epublib.domain.Resource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.