Пример #1
0
 private Map<String, Resource> readResources(ZipInputStream in, String defaultHtmlEncoding)
     throws IOException {
   Map<String, Resource> result = new HashMap<String, Resource>();
   for (ZipEntry zipEntry = in.getNextEntry(); zipEntry != null; zipEntry = in.getNextEntry()) {
     // System.out.println(zipEntry.getName());
     if (zipEntry.isDirectory()) {
       continue;
     }
     Resource resource = ResourceUtil.createResource(zipEntry, in);
     if (resource.getMediaType() == MediatypeService.XHTML) {
       resource.setInputEncoding(defaultHtmlEncoding);
     }
     result.put(resource.getHref(), resource);
   }
   return result;
 }
Пример #2
0
  private String getPackageResourceHref(Book book, Map<String, Resource> 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;
  }