Package nl.siegmann.epublib.domain

Examples of nl.siegmann.epublib.domain.Book


   
    if (StringUtils.isBlank(inputEncoding)) {
      inputEncoding = Constants.CHARACTER_ENCODING;
    }
   
    Book book;
    if("chm".equals(type)) {
      book = ChmParser.parseChm(VFSUtil.resolveFileObject(inputLocation), inputEncoding);
    } else if ("epub".equals(type)) {
      book = new EpubReader().readEpub(VFSUtil.resolveInputStream(inputLocation), inputEncoding);
    } else {
      book = FilesetBookCreator.createBookFromDirectory(VFSUtil.resolveFileObject(inputLocation), inputEncoding);
    }
   
    if(StringUtils.isNotBlank(coverImage)) {
//      book.getResourceByHref(book.getCoverImage());
      book.setCoverImage(new Resource(VFSUtil.resolveInputStream(coverImage), coverImage));
      epubCleaner.getBookProcessors().add(new CoverpageBookProcessor());
    }
   
    if(StringUtils.isNotBlank(title)) {
      List<String> titles = new ArrayList<String>();
      titles.add(title);
      book.getMetadata().setTitles(titles);
    }
   
    if(StringUtils.isNotBlank(isbn)) {
      book.getMetadata().addIdentifier(new Identifier(Identifier.Scheme.ISBN, isbn));
    }
   
    initAuthors(authorNames, book);
   
    OutputStream result;
View Full Code Here


  private NavigationHistory browserHistory;
  private BookProcessorPipeline epubCleaner = new BookProcessorPipeline(Collections.<BookProcessor>emptyList());
 
  public Viewer(InputStream bookStream) {
    mainWindow = createMainWindow();
    Book book;
    try {
      book = (new EpubReader()).readEpub(bookStream);
      gotoBook(book);
    } catch (IOException e) {
      log.error(e.getMessage(), e);
View Full Code Here

        }
        if (! selectedFile.isDirectory()) {
          previousDir = selectedFile.getParentFile();
        }
        try {
          Book book = (new EpubReader()).readEpub(new FileInputStream(selectedFile));
          gotoBook(book);
        } catch (Exception e1) {
          log.error(e1.getMessage(), e1);
        }
      }
View Full Code Here

  }

  public static Book parseChm(FileObject chmRootDir, String inputHtmlEncoding)
      throws IOException, ParserConfigurationException,
      XPathExpressionException {
    Book result = new Book();
    result.getMetadata().addTitle(findTitle(chmRootDir));
    FileObject hhcFileObject = findHhcFileObject(chmRootDir);
    if(hhcFileObject == null) {
      throw new IllegalArgumentException("No index file found in directory " + chmRootDir + ". (Looked for file ending with extension '.hhc'");
    }
    if(inputHtmlEncoding == null) {
      inputHtmlEncoding = DEFAULT_CHM_HTML_INPUT_ENCODING;
    }
    Resources resources = findResources(chmRootDir, inputHtmlEncoding);
    List<TOCReference> tocReferences = HHCParser.parseHhc(hhcFileObject.getContent().getInputStream(), resources);
    result.setTableOfContents(new TableOfContents(tocReferences));
    result.setResources(resources);
    result.generateSpineFromTableOfContents();
    return result;
  }
View Full Code Here

public class Simple1 {
    public static void main(String[] args) {
        try {
            // Create new Book
            Book book = new Book();

            // Set the title
            book.getMetadata().addTitle("Epublib test book 1");

            // Add an Author
            book.getMetadata().addAuthor(new Author("Joe", "Tester"));

            // Set cover image
            book.setCoverImage(new Resource(Simple1.class.getResourceAsStream("/book1/test_cover.png"), "cover.png"));

            // Add Chapter 1
            book.addSection("Introduction", new Resource(Simple1.class.getResourceAsStream("/book1/chapter1.html"), "chapter1.html"));

            // Add css file
            book.getResources().add(new Resource(Simple1.class.getResourceAsStream("/book1/book1.css"), "book1.css"));

            // Add Chapter 2
            TOCReference chapter2 = book.addSection("Second Chapter", new Resource(Simple1.class.getResourceAsStream("/book1/chapter2.html"), "chapter2.html"));

            // Add image used by Chapter 2
            book.getResources().add(new Resource(Simple1.class.getResourceAsStream("/book1/flowers_320x240.jpg"), "flowers.jpg"));

            // Add Chapter2, Section 1
            book.addSection(chapter2, "Chapter 2, section 1", new Resource(Simple1.class.getResourceAsStream("/book1/chapter2_1.html"), "chapter2_1.html"));

            // Add Chapter 3
            book.addSection("Conclusion", new Resource(Simple1.class.getResourceAsStream("/book1/chapter3.html"), "chapter3.html"));

            // Create EpubWriter
            EpubWriter epubWriter = new EpubWriter();

            // Write the Book as Epub
View Full Code Here

public class EpubWriterTest {

  @Test
  public void testBook1() throws IOException {
    // create test book
    Book book = createTestBook();
   
    // write book to byte[]
    byte[] bookData = writeBookToByteArray(book);
      FileOutputStream fileOutputStream = new FileOutputStream("foo.zip");
      fileOutputStream.write(bookData);
      fileOutputStream.flush();
      fileOutputStream.close();
    Assert.assertNotNull(bookData);
    Assert.assertTrue(bookData.length > 0);
   
    // read book from byte[]
    Book readBook = new EpubReader().readEpub(new ByteArrayInputStream(bookData));
   
    // assert book values are correct
    Assert.assertEquals(book.getMetadata().getTitles(), readBook.getMetadata().getTitles());
    Assert.assertEquals(Identifier.Scheme.ISBN, CollectionUtil.first(readBook.getMetadata().getIdentifiers()).getScheme());
    Assert.assertEquals(CollectionUtil.first(book.getMetadata().getIdentifiers()).getValue(), CollectionUtil.first(readBook.getMetadata().getIdentifiers()).getValue());
    Assert.assertEquals(CollectionUtil.first(book.getMetadata().getAuthors()), CollectionUtil.first(readBook.getMetadata().getAuthors()));
    Assert.assertEquals(1, readBook.getGuide().getGuideReferencesByType(GuideReference.COVER).size());
    Assert.assertEquals(5, readBook.getSpine().size());
    Assert.assertNotNull(book.getCoverPage());
    Assert.assertNotNull(book.getCoverImage());
    Assert.assertEquals(4, readBook.getTableOfContents().size());
     
  }
View Full Code Here

   * @throws IOException
   * @throws FileNotFoundException
   *
   */
  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

      EpubWriter epubWriter = new EpubWriter();
      epubWriter.write(book, new FileOutputStream("test1_book1.epub"));
  }
 
  private Book createTestBook() throws IOException {
    Book book = new Book();
   
    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

     */
    @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");

        book.setNcxResource(ncxResource);
        book.getSpine().setTocResource(ncxResource);

        NCXDocument.read(book, new EpubReader());
        assertEquals("xhtml/chapter1.html", book.getTableOfContents().getTocReferences().get(0).getCompleteHref());
    }
View Full Code Here

public class EpubReaderTest {

  @Test
  public void testCover_only_cover() throws IOException {
    Book book = new Book();

    book.setCoverImage(new Resource(this.getClass().getResourceAsStream(
        "/book1/cover.png"), "cover.png"));

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    (new EpubWriter()).write(book, out);
    byte[] epubData = out.toByteArray();
    Book readBook = new EpubReader().readEpub(new ByteArrayInputStream(
        epubData));
    Assert.assertNotNull(readBook.getCoverImage());
  }
View Full Code Here

TOP

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

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.