コード例 #1
0
 /**
  * Check whether a resource is valid. A valid resource must have a non-blank ID, a non-blank link
  * and a media type.
  *
  * @param book the book the resource is for
  * @param resource the resource to check
  * @return whether the resource is valid
  */
 private static boolean isValidResource(final Book book, final Resource resource) {
   if (resource == null
       || (resource.getMediaType() == MediatypeService.NCX
           && book.getSpine().getTocResource() != null)) {
     return false;
   }
   if (StringUtil.isBlank(resource.getId())) {
     LOGGER.error(
         "resource id must not be blank (href: "
             + resource.getHref()
             + ", mediatype:"
             + resource.getMediaType()
             + ")");
     return false;
   }
   if (StringUtil.isBlank(resource.getHref())) {
     LOGGER.error(
         "resource href must not be blank (id: "
             + resource.getId()
             + ", mediatype:"
             + resource.getMediaType()
             + ")");
     return false;
   }
   if (resource.getMediaType() == null) {
     LOGGER.error(
         "resource media type must be specified (id: "
             + resource.getId()
             + ", href:"
             + resource.getHref()
             + ")");
     return false;
   }
   return true;
 }
コード例 #2
0
ファイル: EpubReader.java プロジェクト: freme-project/epublib
  private String getPackageResourceHref(Resources resources) {
    String defaultResult = "OEBPS/content.opf";
    String result = defaultResult;

    Resource containerResource = resources.remove("META-INF/container.xml");
    if (containerResource == null) {
      return result;
    }
    try {
      Document document = ResourceUtil.getAsDocument(containerResource);
      Element rootFileElement =
          (Element)
              ((Element) document.getDocumentElement().getElementsByTagName("rootfiles").item(0))
                  .getElementsByTagName("rootfile")
                  .item(0);
      result = rootFileElement.getAttribute("full-path");
    } catch (Exception e) {
      log.error(e.getMessage(), e);
    }
    if (StringUtil.isBlank(result)) {
      result = defaultResult;
    }
    return result;
  }