use of org.eclipse.mylyn.docs.epub.opf.Item in project mylyn.docs by eclipse.
the class OPSPublication method generateTableOfContents.
/**
* 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 {
// $NON-NLS-1$
log(Messages.getString("OPS2Publication.0"), Severity.INFO, indent++);
Meta meta = NCXFactory.eINSTANCE.createMeta();
// $NON-NLS-1$
meta.setName("dtb:uid");
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(// $NON-NLS-1$
MessageFormat.format(Messages.getString("OPS2Publication.1"), referencedItem.getHref()), Severity.VERBOSE, indent);
playOrder = TOCGenerator.parse(new InputSource(fis), referencedItem.getHref(), ncxTOC, playOrder);
}
}
indent--;
}
use of org.eclipse.mylyn.docs.epub.opf.Item in project mylyn.docs by eclipse.
the class OPSPublication method validateContents.
/**
* 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>
* <li>XHTML file content must be in the preferred vocabulary. Warnings are added when this is not the case.</li>
* </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) {
// 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, // $NON-NLS-1$
MessageFormat.format(Messages.getString("OPSPublication.7"), item.getHref())));
}
item.setFile(file.toString());
}
if (!isLegalType(item)) {
Item fallback = getItemById(item.getFallback());
if (fallback == null) {
messages.add(new ValidationMessage(ValidationMessage.Severity.WARNING, // $NON-NLS-1$
MessageFormat.format(// $NON-NLS-1$
Messages.getString("OPS2Publication.13"), item.getHref())));
} else if (!isLegalType(fallback)) {
messages.add(new ValidationMessage(ValidationMessage.Severity.WARNING, // $NON-NLS-1$
MessageFormat.format(// $NON-NLS-1$
Messages.getString("OPS2Publication.14"), item.getHref())));
} else {
messages.add(new ValidationMessage(ValidationMessage.Severity.WARNING, // $NON-NLS-1$
MessageFormat.format(// $NON-NLS-1$
Messages.getString("OPS2Publication.15"), 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;
}
use of org.eclipse.mylyn.docs.epub.opf.Item in project mylyn.docs by eclipse.
the class Publication method unpack.
/**
* Populates the data model with the content from an unpacked EPUB.
*
* @param opfFile
* the (OPS) root file
* @throws Exception
*/
void unpack(File opfFile) throws Exception {
readOPF(opfFile);
rootFolder = opfFile.getAbsoluteFile().getParentFile();
String tocId = opfPackage.getSpine().getToc();
Item tocItem = getItemById(tocId);
File tocFile = new File(rootFolder.getAbsolutePath() + File.separator + tocItem.getHref());
readTableOfContents(tocFile);
}
use of org.eclipse.mylyn.docs.epub.opf.Item in project mylyn.docs by eclipse.
the class Publication method removeItemById.
/**
* Removes the item with the given identifier from the manifest. If found and removed the item will be returned.
* Otherwise <code>null</code> is returned.
*
* @param id
* identifier of item to remove
* @return the item or <code>null</code>
* @since 3.1
*/
public Item removeItemById(String id) {
EList<Item> items = opfPackage.getManifest().getItems();
Item found = null;
for (Item item : items) {
if (item.getId().equals(id)) {
found = item;
break;
}
}
if (found != null) {
opfPackage.getManifest().getItems().remove(found);
}
return found;
}
use of org.eclipse.mylyn.docs.epub.opf.Item in project mylyn.docs by eclipse.
the class Publication method getItemsByMIMEType.
/**
* Returns a list of all manifest items that have the specified MIME type.
*
* @param mimetype
* the MIME type to search for
* @return a list of all items
*/
public List<Item> getItemsByMIMEType(String mimetype) {
ArrayList<Item> stylesheets = new ArrayList<Item>();
EList<Item> items = opfPackage.getManifest().getItems();
for (Item item : items) {
if (item.getMedia_type().equals(mimetype)) {
stylesheets.add(item);
}
}
return stylesheets;
}
Aggregations