Package nl.siegmann.epublib.domain

Examples of nl.siegmann.epublib.domain.Spine


    Element spineElement = DOMUtil.getFirstElementByTagNameNS(packageDocument.getDocumentElement(), NAMESPACE_OPF, OPFTags.spine);
    if (spineElement == null) {
      log.error("Element " + OPFTags.spine + " not found in package document, generating one automatically");
      return generateSpineFromResources(resources);
    }
    Spine result = new Spine();
    result.setTocResource(findTableOfContentsResource(spineElement, resources));
    NodeList spineNodes = packageDocument.getElementsByTagNameNS(NAMESPACE_OPF, OPFTags.itemref);
    List<SpineReference> spineReferences = new ArrayList<SpineReference>(spineNodes.getLength());
    for(int i = 0; i < spineNodes.getLength(); i++) {
      Element spineItem = (Element) spineNodes.item(i);
      String itemref = DOMUtil.getAttribute(spineItem, NAMESPACE_OPF, OPFAttributes.idref);
      if(StringUtil.isBlank(itemref)) {
        log.error("itemref with missing or empty idref"); // XXX
        continue;
      }
      String id = idMapping.get(itemref);
      if (id == null) {
        id = itemref;
      }
      Resource resource = resources.getByIdOrHref(id);
      if(resource == null) {
        log.error("resource with id \'" + id + "\' not found");
        continue;
      }
     
      SpineReference spineReference = new SpineReference(resource);
      if (OPFValues.no.equalsIgnoreCase(DOMUtil.getAttribute(spineItem, NAMESPACE_OPF, OPFAttributes.linear))) {
        spineReference.setLinear(false);
      }
      spineReferences.add(spineReference);
    }
    result.setSpineReferences(spineReferences);
    return result;
  }
View Full Code Here


   *
   * @param resources
   * @return a spine created out of all resources in the resources.
   */
  private static Spine generateSpineFromResources(Resources resources) {
    Spine result = new Spine();
    List<String> resourceHrefs = new ArrayList<String>();
    resourceHrefs.addAll(resources.getAllHrefs());
    Collections.sort(resourceHrefs, String.CASE_INSENSITIVE_ORDER);
    for (String resourceHref: resourceHrefs) {
      Resource resource = resources.getByHref(resourceHref);
      if (resource.getMediaType() == MediatypeService.NCX) {
        result.setTocResource(resource);
      } else if (resource.getMediaType() == MediatypeService.XHTML) {
        result.addSpineReference(new SpineReference(resource));
      }
    }
    return result;
  }
View Full Code Here

    Resources resources = new Resources();
    processDirectory(rootDirectory, rootDirectory, sections, resources, encoding);
    result.setResources(resources);
    TableOfContents tableOfContents = new TableOfContents(sections);
    result.setTableOfContents(tableOfContents);
    result.setSpine(new Spine(tableOfContents));
   
    result = bookProcessor.processBook(result);
   
    return result;
  }
View Full Code Here

TOP

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

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.