Package nl.siegmann.epublib.domain

Examples of nl.siegmann.epublib.domain.Resource


    if (file == null) {
      return null;
    }
    MediaType mediaType = MediatypeService.determineMediaType(file.getName());
    byte[] data = IOUtil.toByteArray(new FileInputStream(file));
    Resource result = new Resource(data, mediaType);
    return result;
  }
View Full Code Here


   * @param href
   * @return a resource with as contents a html page with the given title.
   */
  public static Resource createResource(String title, String href) {
    String content = "<html><head><title>" + title + "</title></head><body><h1>" + title + "</h1></body></html>";
    return new Resource(null, content.getBytes(), href, MediatypeService.XHTML, Constants.CHARACTER_ENCODING);
  }
View Full Code Here

   * @param zipInputStream
   * @return a resource created out of the given zipEntry and zipInputStream.
   * @throws IOException
   */
  public static Resource createResource(ZipEntry zipEntry, ZipInputStream zipInputStream) throws IOException {
    return new Resource(zipInputStream, zipEntry.getName());

  }
View Full Code Here

    return new Resource(zipInputStream, zipEntry.getName());

  }

    public static Resource createResource(ZipEntry zipEntry, InputStream zipInputStream) throws IOException {
        return new Resource(zipInputStream, zipEntry.getName());

    }
View Full Code Here

    }
    return book;
  }

  private void initTOCResource(Book book) {
    Resource tocResource;
    try {
      tocResource = NCXDocument.createNCXResource(book);
      Resource currentTocResource = book.getSpine().getTocResource();
      if (currentTocResource != null) {
        book.getResources().remove(currentTocResource.getHref());
      }
      book.getSpine().setTocResource(tocResource);
      book.getResources().add(tocResource);
    } catch (Exception e) {
      log.error("Error writing table of contents: " + e.getClass().getName() + ": " + e.getMessage());
View Full Code Here

      return gotoSpineSection(currentSpinePos + 1, source);
    }
  }

  public int gotoResource(String resourceHref, Object source) {
    Resource resource = book.getResources().getByHref(resourceHref);
    return gotoResource(resource, source);
  }
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

        "a", "b", new Integer[] {},
        "XXX", "<html><title>my title1</title><body><h1>wrong title</h1></body></html>", new Integer[] {},
        "title", "<html><title>my title1</title><body><h1>wrong title</h1></body></html>", new Integer[] {3, 15}
    };
    for (int i = 0; i < testData.length; i+= 3) {
      Resource resource = new Resource(((String) testData[i + 1]).getBytes(), MediatypeService.XHTML);
      String content = SearchIndex.getSearchContent(new StringReader((String) testData[i + 1]));
      String searchTerm = (String) testData[i];
      Integer[] expectedResult = (Integer[]) testData[i + 2];
      List<SearchResult> actualResult = SearchIndex.doSearch(searchTerm, content, resource);
      assertEquals("test " + ((i / 3) + 1), expectedResult.length, actualResult.size());
View Full Code Here

        "<html><body><H1>my h1 title4</h1></body></html>", "my h1 title4",
        "<html><body><H1 class=\"main\">my h1 title5</h1></body></html>", "my h1 title5",
        "<html><body><XH1 class=\"main\">wrong title</Xh1><h2>test title 6</h2></body></html>", "test title 6",
    };
    for (int i = 0; i < testData.length; i+= 2) {
      Resource resource = new Resource(testData[i].getBytes(), MediatypeService.XHTML);
      String actualTitle = ToolsResourceUtil.findTitleFromXhtml(resource);
      assertEquals(testData[i + 1], actualTitle);
    }
  }
View Full Code Here

  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);
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.