Package nl.siegmann.epublib.domain

Examples of nl.siegmann.epublib.domain.Book


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 InputStreamResource(Simple1.class.getResourceAsStream("/book1/cover.png"), MediatypeService.PNG));
     
      // Add Chapter 1
      book.addResourceAsSection("Introduction", new InputStreamResource(Simple1.class.getResourceAsStream("/book1/chapter1.html"), MediatypeService.XHTML));
 
      // Add css file
      book.getResources().add(new InputStreamResource(Simple1.class.getResourceAsStream("/book1/book1.css"), "book1.css"));
 
      // Add Chapter 2
      Section chapter2 = book.addResourceAsSection("Second Chapter", new InputStreamResource(Simple1.class.getResourceAsStream("/book1/chapter2.html"), "chapter2.html"));
     
      // Add image used by Chapter 2
      book.getResources().add(new InputStreamResource(Simple1.class.getResourceAsStream("/book1/flowers_320x240.jpg"), "flowers.jpg"));
 
      // Add Chapter2, Section 1
      book.addResourceAsSubSection(chapter2, "Chapter 2, section 1", new InputStreamResource(Simple1.class.getResourceAsStream("/book1/chapter2_1.html"), "chapter2_1.html"));
 
      // Add Chapter 3
      book.addResourceAsSection("Conclusion", new InputStreamResource(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 SearchIndexTest extends TestCase {

  public void testDoSearch1() {
    try {
      Book testBook = new Book();
      testBook.addSection("chapter1", new Resource(new StringReader("a"), "chapter1.html"));
      testBook.addSection("chapter2", new Resource(new StringReader("<title>ab</title>"), "chapter2.html"));
      testBook.addSection("chapter3", new Resource(new StringReader("ba"), "chapter3.html"));
      testBook.addSection("chapter4", new Resource(new StringReader("aa"), "chapter4.html"));
      SearchIndex searchIndex = new SearchIndex(testBook);
      SearchResults searchResults = searchIndex.doSearch("a");
      assertFalse(searchResults.isEmpty());
      assertEquals(5, searchResults.size());
      assertEquals(0, searchResults.getHits().get(0).getPagePos());
View Full Code Here

      FileObject dir = fsManager.resolveFile("ram://test-dir");
      dir.createFolder();
      FileObject chapter1 = dir.resolveFile("chapter1.html", NameScope.CHILD);
      chapter1.createFile();
      IOUtils.copy(this.getClass().getResourceAsStream("/book1/chapter1.html"), chapter1.getContent().getOutputStream());
      Book bookFromDirectory = FilesetBookCreator.createBookFromDirectory(dir, Constants.CHARACTER_ENCODING);
      assertEquals(1, bookFromDirectory.getResources().size());
      assertEquals(1, bookFromDirectory.getSpine().size());
      assertEquals(1, bookFromDirectory.getTableOfContents().size());
    } catch(Exception e) {
      assertTrue(false);
    }
  }
View Full Code Here

import nl.siegmann.epublib.util.CollectionUtil;

public class FixIdentifierBookProcessorTest extends TestCase {

  public void test_empty_book() {
    Book book = new Book();
    FixIdentifierBookProcessor fixIdentifierBookProcessor = new FixIdentifierBookProcessor();
    Book resultBook = fixIdentifierBookProcessor.processBook(book);
    assertEquals(1, resultBook.getMetadata().getIdentifiers().size());
    Identifier identifier = CollectionUtil.first(resultBook.getMetadata().getIdentifiers());
    assertEquals(Identifier.Scheme.UUID, identifier.getScheme());
  }
View Full Code Here

    Identifier identifier = CollectionUtil.first(resultBook.getMetadata().getIdentifiers());
    assertEquals(Identifier.Scheme.UUID, identifier.getScheme());
  }

  public void test_single_identifier() {
    Book book = new Book();
    Identifier identifier = new Identifier(Identifier.Scheme.ISBN, "1234");
    book.getMetadata().addIdentifier(identifier);
    FixIdentifierBookProcessor fixIdentifierBookProcessor = new FixIdentifierBookProcessor();
    Book resultBook = fixIdentifierBookProcessor.processBook(book);
    assertEquals(1, resultBook.getMetadata().getIdentifiers().size());
    Identifier actualIdentifier = CollectionUtil.first(resultBook.getMetadata().getIdentifiers());
    assertEquals(identifier, actualIdentifier);
  }
View Full Code Here

        file.createFile();
        IOUtils.copy(this.getClass().getResourceAsStream(chm1Dir + "/" + line), file.getContent().getOutputStream());
        file.getContent().close();
      }
     
      Book chmBook = ChmParser.parseChm(dir, Constants.CHARACTER_ENCODING);
      assertEquals(45, chmBook.getResources().size());
      assertEquals(18, chmBook.getSpine().size());
      assertEquals(19, chmBook.getTableOfContents().size());
      assertEquals("chm-example", chmBook.getMetadata().getTitles().get(0));
    } catch(Exception e) {
      e.printStackTrace();
      assertTrue(false);
    }
  }
View Full Code Here

public class FilesetBookCreatorTest extends TestCase {
 
  public void test1() {
    try {
      FileObject dir = createDirWithSourceFiles();
      Book book = FilesetBookCreator.createBookFromDirectory(dir);
      assertEquals(5, book.getSpine().size());
      assertEquals(5, book.getTableOfContents().size());
    } catch(Exception e) {
      e.printStackTrace();
      assertTrue(false);
    }
  }
View Full Code Here

      FileObject dir = createDirWithSourceFiles();
     
      // this file should be ignored
      copyInputStreamToFileObject(new ByteArrayInputStream("hi".getBytes()), dir, "foo.nonsense");
     
      Book book = FilesetBookCreator.createBookFromDirectory(dir);
      assertEquals(5, book.getSpine().size());
      assertEquals(5, book.getTableOfContents().size());
    } catch(Exception e) {
      e.printStackTrace();
      assertTrue(false);
    }
  }
View Full Code Here

import nl.siegmann.epublib.service.MediatypeService;

public class HtmlCleanerBookProcessorTest extends TestCase {

  public void testSimpleDocument1() {
    Book book = new Book();
    String testInput = "<html><head><title>title</title></head><body>Hello, world!</html>";
    String expectedResult = Constants.DOCTYPE_XHTML + "\n<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>title</title></head><body>Hello, world!</body></html>";
    try {
      Resource resource = new Resource(testInput.getBytes(Constants.CHARACTER_ENCODING), "test.html");
      book.getResources().add(resource);
      HtmlCleanerBookProcessor htmlCleanerBookProcessor = new HtmlCleanerBookProcessor();
      byte[] processedHtml = htmlCleanerBookProcessor.processHtml(resource, book, Constants.CHARACTER_ENCODING);
      String actualResult = new String(processedHtml, Constants.CHARACTER_ENCODING);
      assertEquals(expectedResult, actualResult);
    } catch (IOException e) {
View Full Code Here

      assertTrue(e.getMessage(), false);
    }
  }
 
  public void testSimpleDocument2() {
    Book book = new Book();
    String testInput = "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>test page</title><link foo=\"bar\" /></head><body background=\"red\">Hello, world!</body></html>";
    try {
      Resource resource = new Resource(testInput.getBytes(Constants.CHARACTER_ENCODING), "test.html");
      book.getResources().add(resource);
      HtmlCleanerBookProcessor htmlCleanerBookProcessor = new HtmlCleanerBookProcessor();
      byte[] processedHtml = htmlCleanerBookProcessor.processHtml(resource, book, Constants.CHARACTER_ENCODING);
      String result = new String(processedHtml, Constants.CHARACTER_ENCODING);
      assertEquals(Constants.DOCTYPE_XHTML + "\n" + testInput, result);
    } catch (IOException e) {
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.