Package nl.siegmann.epublib.domain

Examples of nl.siegmann.epublib.domain.Metadata


class PackageDocumentMetadataReader extends PackageDocumentBase {

  private static final Logger log = LoggerFactory.getLogger(PackageDocumentMetadataReader.class);

  public static Metadata readMetadata(Document packageDocument) {
    Metadata result = new Metadata();
    Element metadataElement = DOMUtil.getFirstElementByTagNameNS(packageDocument.getDocumentElement(), NAMESPACE_OPF, OPFTags.metadata);
    if(metadataElement == null) {
      log.error("Package does not contain element " + OPFTags.metadata);
      return result;
    }
    result.setTitles(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.title));
    result.setPublishers(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.publisher));
    result.setDescriptions(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.description));
    result.setRights(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.rights));
    result.setTypes(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.type));
    result.setSubjects(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.subject));
    result.setIdentifiers(readIdentifiers(metadataElement));
    result.setAuthors(readCreators(metadataElement));
    result.setContributors(readContributors(metadataElement));
    result.setDates(readDates(metadataElement));
        result.setOtherProperties(readOtherProperties(metadataElement));
        result.setMetaAttributes(readMetaProperties(metadataElement));
        Element languageTag = DOMUtil.getFirstElementByTagNameNS(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.language);
        if (languageTag != null) {
            result.setLanguage(DOMUtil.getTextChildrenContent(languageTag));
        }


    return result;
  }
View Full Code Here


  public static final String DEFAULT_COVER_IMAGE_ID = "cover-image";
  public static final String DEFAULT_COVER_IMAGE_HREF = "images/cover.png";
 
  @Override
  public Book processBook(Book book) {
    Metadata metadata = book.getMetadata();
    if(book.getCoverPage() == null && book.getCoverImage() == null) {
      return book;
    }
    Resource coverPage = book.getCoverPage();
    if (coverPage == null) {
      coverPage = findCoverPage(book);
      book.setCoverPage(coverPage);
    }
    Resource coverImage = book.getCoverImage();
    if(coverPage == null) {
      if(coverImage == null) {
        // give up
      } else { // coverImage != null
        if(StringUtils.isBlank(coverImage.getHref())) {
          coverImage.setHref(getCoverImageHref(coverImage, book));
        }
        String coverPageHtml = createCoverpageHtml(CollectionUtil.first(metadata.getTitles()), coverImage.getHref());
        coverPage = new Resource(null, coverPageHtml.getBytes(), getCoverPageHref(book), MediatypeService.XHTML);
        fixCoverResourceId(book, coverPage, DEFAULT_COVER_PAGE_ID);
      }
    } else { // coverPage != null
      if(book.getCoverImage() == null) {
View Full Code Here

 
  @Test 
  public void test1() {
    try {
      Document document = EpubProcessorSupport.createDocumentBuilder().parse(PackageDocumentMetadataReader.class.getResourceAsStream("/opf/test2.opf"));
      Metadata metadata = PackageDocumentMetadataReader.readMetadata(document);
      assertEquals(1, metadata.getAuthors().size());
    } catch (Exception e) {
      e.printStackTrace();
      assertTrue(false);
    }
  }
View Full Code Here

    }
  }

  @Test 
    public void testReadsLanguage() {
        Metadata metadata = getMetadata("/opf/test_language.opf");
        assertEquals("fi", metadata.getLanguage());
    }
View Full Code Here

        assertEquals("fi", metadata.getLanguage());
    }

  @Test 
    public void testDefaultsToEnglish() {
        Metadata metadata = getMetadata("/opf/test_default_language.opf");
        assertEquals("en", metadata.getLanguage());
    }
View Full Code Here

          + "</metadata>"
         + "</package>";

      // when
      Document metadataDocument = EpubProcessorSupport.createDocumentBuilder().parse(new InputSource(new StringReader(input)));
      Metadata metadata = PackageDocumentMetadataReader.readMetadata(metadataDocument);
     
      // then
      Assert.assertEquals("Three Men in a Boat", metadata.getFirstTitle());

      // test identifier
      Assert.assertNotNull(metadata.getIdentifiers());
      Assert.assertEquals(1, metadata.getIdentifiers().size());
      Identifier identifier = metadata.getIdentifiers().get(0);
      Assert.assertEquals("URI", identifier.getScheme());
      Assert.assertEquals("zelda@mobileread.com:2010040720", identifier.getValue());
     
      Assert.assertEquals("8", metadata.getMetaAttribute("calibre:rating"));
      Assert.assertEquals("cover_pic", metadata.getMetaAttribute("cover"));
    }
View Full Code Here

TOP

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

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.