Search in sources :

Example 1 with MarkupToDocbook

use of org.eclipse.mylyn.wikitext.parser.util.MarkupToDocbook in project mylyn.docs by eclipse.

the class TextileToDocbookTest method setUp.

@Override
public void setUp() {
    textileToDocbook = new MarkupToDocbook();
    textileToDocbook.setMarkupLanguage(new TextileLanguage());
}
Also used : TextileLanguage(org.eclipse.mylyn.wikitext.textile.TextileLanguage) MarkupToDocbook(org.eclipse.mylyn.wikitext.parser.util.MarkupToDocbook)

Example 2 with MarkupToDocbook

use of org.eclipse.mylyn.wikitext.parser.util.MarkupToDocbook in project mylyn.docs by eclipse.

the class ConvertMarkupToDocbook method handleFile.

@Override
protected void handleFile(final IFile file, String name) {
    // $NON-NLS-1$
    final IFile newFile = file.getParent().getFile(new Path(name + ".xml"));
    if (newFile.exists()) {
        if (!MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.ConvertMarkupToDocbook_overwrite, NLS.bind(Messages.ConvertMarkupToDocbook_fileExistsOverwrite, new Object[] { newFile.getFullPath() }))) {
            return;
        }
    }
    final MarkupToDocbook markupToDocbook = new MarkupToDocbook();
    markupToDocbook.setMarkupLanguage(markupLanguage);
    markupToDocbook.setBookTitle(name);
    try {
        IRunnableWithProgress runnable = new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    String content = IOUtil.readFully(file);
                    final String docbook = markupToDocbook.parse(content);
                    if (newFile.exists()) {
                        // $NON-NLS-1$
                        newFile.setContents(// $NON-NLS-1$
                        new ByteArrayInputStream(docbook.getBytes("utf-8")), // $NON-NLS-1$
                        false, // $NON-NLS-1$
                        true, monitor);
                    } else {
                        // $NON-NLS-1$
                        newFile.create(new ByteArrayInputStream(docbook.getBytes("utf-8")), false, monitor);
                    }
                    // $NON-NLS-1$
                    newFile.setCharset("utf-8", monitor);
                } catch (Exception e) {
                    throw new InvocationTargetException(e);
                }
            }
        };
        try {
            PlatformUI.getWorkbench().getProgressService().busyCursorWhile(runnable);
        } catch (InterruptedException e) {
            return;
        } catch (InvocationTargetException e) {
            throw e.getCause();
        }
    } catch (Throwable e) {
        StringWriter message = new StringWriter();
        PrintWriter out = new PrintWriter(message);
        out.println(Messages.ConvertMarkupToDocbook_cannotConvert + e.getMessage());
        out.println(Messages.ConvertMarkupToDocbook_detailsFollow);
        e.printStackTrace(out);
        out.close();
        MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.ConvertMarkupToDocbook_cannotCompleteOperation, message.toString());
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) MarkupToDocbook(org.eclipse.mylyn.wikitext.parser.util.MarkupToDocbook) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) StringWriter(java.io.StringWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) PrintWriter(java.io.PrintWriter)

Aggregations

MarkupToDocbook (org.eclipse.mylyn.wikitext.parser.util.MarkupToDocbook)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IFile (org.eclipse.core.resources.IFile)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Path (org.eclipse.core.runtime.Path)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 TextileLanguage (org.eclipse.mylyn.wikitext.textile.TextileLanguage)1