예제 #1
0
 /** Creates and configures a table of contents. */
 private void configureNCX() {
   ncxTOC = NCXFactory.eINSTANCE.createNcx();
   // Set the required version attribute
   ncxTOC.setVersion("2005-1"); // $NON-NLS-1$
   // Create the required head element
   Head head = NCXFactory.eINSTANCE.createHead();
   ncxTOC.setHead(head);
   // Create the required title element
   DocTitle docTitle = NCXFactory.eINSTANCE.createDocTitle();
   Text text = NCXFactory.eINSTANCE.createText();
   FeatureMapUtil.addText(text.getMixed(), "Table of contents"); // $NON-NLS-1$
   docTitle.setText(text);
   ncxTOC.setDocTitle(docTitle);
   // Create the required navigation map element
   NavMap navMap = NCXFactory.eINSTANCE.createNavMap();
   ncxTOC.setNavMap(navMap);
 }
예제 #2
0
 /**
  * This mechanism will traverse the spine of the publication (which is representing the reading
  * order) and parse each file for information that can be used to assemble a table of contents.
  * Only XHTML type of files will be taken into consideration.
  *
  * @throws SAXException
  * @throws IOException
  * @throws ParserConfigurationException
  */
 @Override
 protected void generateTableOfContents()
     throws ParserConfigurationException, SAXException, IOException {
   log(Messages.getString("OPS2Publication.0"), Severity.INFO, indent++); // $NON-NLS-1$
   Meta meta = NCXFactory.eINSTANCE.createMeta();
   meta.setName("dtb:uid"); // $NON-NLS-1$
   meta.setContent(getIdentifier().getMixed().getValue(0).toString());
   ncxTOC.getHead().getMetas().add(meta);
   int playOrder = 0;
   // Iterate over the spine
   EList<Itemref> spineItems = getSpine().getSpineItems();
   EList<Item> manifestItems = opfPackage.getManifest().getItems();
   for (Itemref itemref : spineItems) {
     Item referencedItem = null;
     String id = itemref.getIdref();
     // Find the manifest item that is referenced
     for (Item item : manifestItems) {
       if (item.getId().equals(id)) {
         referencedItem = item;
         break;
       }
     }
     if (referencedItem != null
         && !referencedItem.isNoToc()
         && referencedItem.getMedia_type().equals(MIMETYPE_XHTML)) {
       File file = new File(referencedItem.getFile());
       FileInputStream fis = new FileInputStream(file);
       log(
           MessageFormat.format(
               Messages.getString("OPS2Publication.1"), referencedItem.getHref()), // $NON-NLS-1$
           Severity.VERBOSE,
           indent);
       playOrder =
           TOCGenerator.parse(new InputSource(fis), referencedItem.getHref(), ncxTOC, playOrder);
     }
   }
   indent--;
 }