コード例 #1
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--;
 }
コード例 #2
0
 /**
  * Validates all XHTML items in the manifest. The following rules are observed:
  *
  * <ul>
  *   <li>The item must be a core media type. If not it must have a fallback item which must exist
  *       and be of a core media type. Otherwise an error is added to the list of messages
  *   <li>XHTML file content must be in the preferred vocabulary. Warnings are added when this is
  *       not the case.
  * </ul>
  *
  * @throws IOException
  * @throws SAXException
  * @throws ParserConfigurationException
  */
 @Override
 protected List<ValidationMessage> validateContents()
     throws ParserConfigurationException, SAXException, IOException {
   EList<Item> manifestItems = opfPackage.getManifest().getItems();
   ArrayList<ValidationMessage> messages = new ArrayList<ValidationMessage>();
   for (Item item : manifestItems) {
     // if the "file" attribute is not set we probably have an item
     // that is in the model because we're repacking an EPUB. We'll try
     // to make it easier on the user by figuring out the path to the
     // file and fail only if the file does not exist.
     if (item.getFile() == null) {
       File rootFolder = getRootFolder();
       String href = item.getHref();
       File file = new File(rootFolder, href);
       if (!file.exists()) {
         messages.add(
             new ValidationMessage(
                 ValidationMessage.Severity.ERROR,
                 MessageFormat.format(
                     Messages.getString("OPSPublication.7"), item.getHref()))); // $NON-NLS-1$
       }
       item.setFile(file.toString());
     }
     if (!isLegalType(item)) {
       Item fallback = getItemById(item.getFallback());
       if (fallback == null) {
         messages.add(
             new ValidationMessage(
                 ValidationMessage.Severity.WARNING,
                 MessageFormat.format(
                     Messages.getString("OPS2Publication.13"), // $NON-NLS-1$
                     item.getHref())));
       } else if (!isLegalType(fallback)) {
         messages.add(
             new ValidationMessage(
                 ValidationMessage.Severity.WARNING,
                 MessageFormat.format(
                     Messages.getString("OPS2Publication.14"), // $NON-NLS-1$
                     item.getHref())));
       } else {
         messages.add(
             new ValidationMessage(
                 ValidationMessage.Severity.WARNING,
                 MessageFormat.format(
                     Messages.getString("OPS2Publication.15"), // $NON-NLS-1$
                     item.getHref())));
       }
     }
     // Validate the XHTML items to see if they contain illegal attributes and elements
     if (item.getMedia_type().equals(MIMETYPE_XHTML)) {
       File file = new File(item.getFile());
       FileReader fr = new FileReader(file);
       messages.addAll(OPSValidator.validate(new InputSource(fr), item.getHref()));
     }
   }
   return messages;
 }