Search in sources :

Example 1 with MarkupToOPS

use of org.eclipse.mylyn.docs.epub.core.wikitext.MarkupToOPS in project mylyn.docs by eclipse.

the class ConvertFromMarkupWizard method performFinish.

@Override
public boolean performFinish() {
    final MarkupToOPS markupToEPUB = new MarkupToOPS();
    markupToEPUB.setMarkupLanguage(markupLanguage);
    final MultiStatus ms = new MultiStatus(EPUBUIPlugin.PLUGIN_ID, 0, Messages.ConvertFromMarkupWizard_1, null);
    try {
        getContainer().run(false, false, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) {
                monitor.beginTask(Messages.ConvertFromMarkupWizard_2, 3);
                try {
                    if (epubFile.exists()) {
                        // Delete the old one
                        epubFile.delete(true, monitor);
                    }
                    // Parse the wiki markup and populate the EPUB
                    markupFolder = markupToEPUB.parse(oebps, markupFile.getLocation().toFile());
                    monitor.worked(1);
                    EPUB publication = new EPUB();
                    publication.add(oebps);
                    epubFolder = publication.pack(epubFile.getLocation().toFile());
                    monitor.worked(1);
                    epubFile.refreshLocal(IResource.DEPTH_ONE, monitor);
                    monitor.worked(1);
                    List<ValidationMessage> messages = oebps.getMessages();
                    for (ValidationMessage validationMessage : messages) {
                        ms.add(new Status(IStatus.WARNING, EPUBUIPlugin.PLUGIN_ID, validationMessage.getMessage()));
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    ms.add(new Status(IStatus.ERROR, EPUBUIPlugin.PLUGIN_ID, Messages.ConvertFromMarkupWizard_3, e));
                } finally {
                    deleteFolder(epubFolder);
                    deleteFolder(markupFolder);
                    monitor.done();
                }
            }
        });
    } catch (Throwable e) {
        ms.add(new Status(IStatus.ERROR, EPUBUIPlugin.PLUGIN_ID, Messages.ConvertFromMarkupWizard_4, e));
        return false;
    }
    if (!ms.isOK()) {
        StatusManager.getManager().handle(ms, StatusManager.BLOCK);
    }
    return ms.isOK();
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ValidationMessage(org.eclipse.mylyn.docs.epub.core.ValidationMessage) EPUB(org.eclipse.mylyn.docs.epub.core.EPUB) MultiStatus(org.eclipse.core.runtime.MultiStatus) List(java.util.List) MarkupToOPS(org.eclipse.mylyn.docs.epub.core.wikitext.MarkupToOPS) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

List (java.util.List)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 Status (org.eclipse.core.runtime.Status)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 EPUB (org.eclipse.mylyn.docs.epub.core.EPUB)1 ValidationMessage (org.eclipse.mylyn.docs.epub.core.ValidationMessage)1 MarkupToOPS (org.eclipse.mylyn.docs.epub.core.wikitext.MarkupToOPS)1