Search in sources :

Example 1 with ValidationMessage

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

the class TestOPSPublication method test_Bug358671_Illegal_Fallback.

/**
 * Test method for <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=358671">bug 358671</a>: Add support for
 * fallback items
 * <p>
 * This method tests for the exception that shall be raised when an illegal item has been added with an illegal
 * fallback item. Which fallback items that are allowed is specified by the OPS version.
 * </p>
 *
 * @throws Exception
 */
@Test
public final void test_Bug358671_Illegal_Fallback() throws Exception {
    epub.add(oebps);
    Item item = oebps.addItem(new File("testdata/OPF-Tests/Bug_358671/illegal-type.html"));
    item.setFallback("fallback");
    oebps.addItem("fallback", null, new File("testdata/OPF-Tests/Bug_358671/illegal-type.html"), null, null, true, true, false);
    epub.pack(epubFile);
    ValidationMessage msg = oebps.getValidationMessages().get(0);
    assertEquals(Severity.WARNING, msg.getSeverity());
    assertEquals(true, msg.getMessage().equals("Item \"illegal-type.html\" is not a core media type and specifies a non-core media fallback item."));
}
Also used : Item(org.eclipse.mylyn.docs.epub.opf.Item) ValidationMessage(org.eclipse.mylyn.docs.epub.core.ValidationMessage) File(java.io.File) Test(org.junit.Test)

Example 2 with ValidationMessage

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

the class TestOPSPublication method testValidateContents.

/**
 * Test method for {@link org.eclipse.mylyn.docs.epub.core.OPSPublication#validateContents()} .
 * <ul>
 * <li>There shall be a warning message</li>
 * </ul>
 *
 * @throws Exception
 */
@Test
public final void testValidateContents() throws Exception {
    epub.add(oebps);
    oebps.addItem(new File("testdata/plain-page_warnings.xhtml"));
    epub.pack(epubFile);
    assertEquals(1, oebps.getValidationMessages().size());
    ValidationMessage msg = oebps.getValidationMessages().get(0);
    assertEquals(Severity.WARNING, msg.getSeverity());
    assertTrue(msg.getMessage().startsWith("Element \"bad\""));
}
Also used : ValidationMessage(org.eclipse.mylyn.docs.epub.core.ValidationMessage) File(java.io.File) Test(org.junit.Test)

Example 3 with ValidationMessage

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

the class TestOPSPublication method test_Bug358671_Legal_Fallback.

/**
 * Test method for <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=358671">bug 358671</a>: Add support for
 * fallback items
 * <p>
 * This method tests for the warning that shall be issued when an illegal item has been added with a legal fallback
 * item.
 * </p>
 *
 * @throws Exception
 */
@Test
public final void test_Bug358671_Legal_Fallback() throws Exception {
    epub.add(oebps);
    Item item = oebps.addItem(new File("testdata/OPF-Tests/Bug_358671/illegal-type.html"));
    item.setFallback("fallback");
    oebps.addItem("fallback", null, new File("testdata/plain-page.xhtml"), null, null, true, true, false);
    epub.pack(epubFile);
    assertEquals(3, oebps.getPackage().getManifest().getItems().size());
    assertEquals(1, oebps.getValidationMessages().size());
    ValidationMessage msg = oebps.getValidationMessages().get(0);
    assertEquals(Severity.WARNING, msg.getSeverity());
    assertEquals(true, msg.getMessage().equals("Item \"illegal-type.html\" is not a core media type but a legal fallback item has been specified."));
}
Also used : Item(org.eclipse.mylyn.docs.epub.opf.Item) ValidationMessage(org.eclipse.mylyn.docs.epub.core.ValidationMessage) File(java.io.File) Test(org.junit.Test)

Example 4 with ValidationMessage

use of org.eclipse.mylyn.docs.epub.core.ValidationMessage 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)

Example 5 with ValidationMessage

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

the class TestOPSPublication method test_Bug358671_Illegal_Item.

/**
 * Test method for <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=358671">bug 358671</a>: Add support for
 * fallback items
 * <p>
 * This method tests for the exception that shall be raised when an illegal item has been added.
 * </p>
 *
 * @throws Exception
 */
@Test
public final void test_Bug358671_Illegal_Item() throws Exception {
    epub.add(oebps);
    oebps.addItem(new File("testdata/OPF-Tests/Bug_358671/illegal-type.html"));
    epub.pack(epubFile);
    ValidationMessage msg = oebps.getValidationMessages().get(0);
    assertEquals(Severity.WARNING, msg.getSeverity());
    assertEquals(true, msg.getMessage().equals("Item \"illegal-type.html\" is not a core media type and does not specify a fallback item."));
}
Also used : ValidationMessage(org.eclipse.mylyn.docs.epub.core.ValidationMessage) File(java.io.File) Test(org.junit.Test)

Aggregations

ValidationMessage (org.eclipse.mylyn.docs.epub.core.ValidationMessage)5 File (java.io.File)4 Test (org.junit.Test)4 Item (org.eclipse.mylyn.docs.epub.opf.Item)2 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 MarkupToOPS (org.eclipse.mylyn.docs.epub.core.wikitext.MarkupToOPS)1