Search in sources :

Example 1 with DocBookDocumentBuilder

use of org.eclipse.mylyn.wikitext.parser.builder.DocBookDocumentBuilder in project mylyn.docs by eclipse.

the class MarkupToDocbook method parse.

public String parse(String markupContent) throws Exception {
    if (markupLanguage == null) {
        // $NON-NLS-1$
        throw new IllegalStateException("must set markupLanguage");
    }
    StringWriter out = new StringWriter();
    DocBookDocumentBuilder builder = new DocBookDocumentBuilder(out) {

        @Override
        protected XmlStreamWriter createXmlStreamWriter(Writer out) {
            return super.createFormattingXmlStreamWriter(out);
        }
    };
    builder.setBookTitle(bookTitle);
    MarkupParser markupParser = new MarkupParser();
    markupParser.setBuilder(builder);
    markupParser.setMarkupLanguage(markupLanguage);
    markupParser.parse(markupContent);
    return out.toString();
}
Also used : StringWriter(java.io.StringWriter) StringWriter(java.io.StringWriter) XmlStreamWriter(org.eclipse.mylyn.wikitext.util.XmlStreamWriter) Writer(java.io.Writer) DocBookDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.DocBookDocumentBuilder) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 2 with DocBookDocumentBuilder

use of org.eclipse.mylyn.wikitext.parser.builder.DocBookDocumentBuilder in project mylyn.docs by eclipse.

the class MediaWikiLanguageTest method testListOrderedWithContinuationToDocBook.

@Test
public void testListOrderedWithContinuationToDocBook() throws IOException {
    StringWriter out = new StringWriter();
    parser.setBuilder(new DocBookDocumentBuilder(out));
    parser.parse("# a list\n" + "## a nested item\n" + "### another nested item\n" + "#: continued\n" + "# another item");
    String docbook = out.toString();
    // should look like this:
    // 
    // <orderedlist>
    // <listitem>
    // <para>a list</para>
    // <orderedlist>
    // <listitem>
    // <para>a nested item</para>
    // <orderedlist>
    // <listitem>
    // <para>another nested item</para>
    // </listitem>
    // </orderedlist>
    // <para>continued</para>
    // </listitem>
    // </orderedlist>
    // </listitem>
    // <listitem>
    // <para>another item</para>
    // </listitem>
    // </orderedlist>
    assertTrue(docbook.contains("<orderedlist><listitem><para>a list</para><orderedlist><listitem><para>a nested item</para><orderedlist><listitem><para>another nested item</para></listitem></orderedlist><para>continued</para></listitem></orderedlist></listitem><listitem><para>another item</para></listitem></orderedlist>"));
}
Also used : StringWriter(java.io.StringWriter) DocBookDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.DocBookDocumentBuilder) AbstractMarkupGenerationTest(org.eclipse.mylyn.wikitext.toolkit.AbstractMarkupGenerationTest) Test(org.junit.Test)

Example 3 with DocBookDocumentBuilder

use of org.eclipse.mylyn.wikitext.parser.builder.DocBookDocumentBuilder in project mylyn.docs by eclipse.

the class ConfluenceLanguageTest method testImageWithAttributesAlignCenterToDocbook.

@Test
public void testImageWithAttributesAlignCenterToDocbook() {
    StringWriter out = new StringWriter();
    DocBookDocumentBuilder builder = new DocBookDocumentBuilder(out);
    parser.setBuilder(builder);
    parser.parse("an !image.png|align=center! image");
    String result = out.toString();
    assertTrue(result.contains("<para>an <mediaobject><imageobject><imagedata fileref=\"image.png\"/></imageobject></mediaobject> image</para>"));
}
Also used : StringWriter(java.io.StringWriter) DocBookDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.DocBookDocumentBuilder) Test(org.junit.Test) AbstractMarkupGenerationTest(org.eclipse.mylyn.wikitext.toolkit.AbstractMarkupGenerationTest)

Example 4 with DocBookDocumentBuilder

use of org.eclipse.mylyn.wikitext.parser.builder.DocBookDocumentBuilder in project mylyn.docs by eclipse.

the class MarkupToDocbookTask method processFile.

private void processFile(MarkupLanguage markupLanguage, final File baseDir, final File source) throws BuildException {
    // $NON-NLS-1$
    log(MessageFormat.format(Messages.getString("MarkupToDocbookTask.8"), source), Project.MSG_VERBOSE);
    String markupContent = null;
    String name = source.getName();
    if (name.lastIndexOf('.') != -1) {
        name = name.substring(0, name.lastIndexOf('.'));
    }
    // $NON-NLS-1$
    File docbookOutputFile = new File(source.getParentFile(), docbookFilenameFormat.replace("$1", name));
    if (!docbookOutputFile.exists() || overwrite || docbookOutputFile.lastModified() < source.lastModified()) {
        if (markupContent == null) {
            markupContent = readFully(source);
        }
        performValidation(source, markupContent);
        Writer writer;
        try {
            writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(docbookOutputFile)), // $NON-NLS-1$
            "utf-8");
        } catch (Exception e) {
            throw new BuildException(MessageFormat.format(// $NON-NLS-1$
            Messages.getString("MarkupToDocbookTask.11"), // $NON-NLS-1$
            docbookOutputFile, e.getMessage()), e);
        }
        try {
            DocBookDocumentBuilder builder = new DocBookDocumentBuilder(writer) {

                @Override
                protected XmlStreamWriter createXmlStreamWriter(Writer out) {
                    return super.createFormattingXmlStreamWriter(out);
                }
            };
            MarkupParser parser = new MarkupParser();
            parser.setMarkupLanguage(markupLanguage);
            parser.setBuilder(builder);
            builder.setBookTitle(bookTitle == null ? name : bookTitle);
            if (doctype != null) {
                builder.setDoctype(doctype);
            }
            parser.parse(markupContent);
        } finally {
            try {
                writer.close();
            } catch (Exception e) {
                throw new BuildException(MessageFormat.format(// $NON-NLS-1$
                Messages.getString("MarkupToDocbookTask.12"), // $NON-NLS-1$
                docbookOutputFile, e.getMessage()), e);
            }
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) XmlStreamWriter(org.eclipse.mylyn.wikitext.util.XmlStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) BuildException(org.apache.tools.ant.BuildException) DocBookDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.DocBookDocumentBuilder) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 5 with DocBookDocumentBuilder

use of org.eclipse.mylyn.wikitext.parser.builder.DocBookDocumentBuilder in project mylyn.docs by eclipse.

the class ConfluenceLanguageTest method testTipToDocBook.

@Test
public void testTipToDocBook() {
    StringWriter out = new StringWriter();
    parser.setBuilder(new DocBookDocumentBuilder(out));
    parser.parse("h1. a header\n" + "\n" + "Some text\n" + "{tip:title=A Title}\n" + "the body of the note\n" + "which may span multiple lines\n" + "\n" + "And may even have multiple paragraphs or *other* _textile_ ??markup??\n" + "{tip}" + "\n" + "More text...");
    String docbook = out.toString();
    assertTrue(docbook.contains("<tip><title>A Title</title><para>the body of"));
    assertTrue(docbook.contains("paragraphs or <emphasis role=\"bold\">other</emphasis> <emphasis>textile</emphasis> <citation>markup</citation></para></tip>"));
}
Also used : StringWriter(java.io.StringWriter) DocBookDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.DocBookDocumentBuilder) Test(org.junit.Test) AbstractMarkupGenerationTest(org.eclipse.mylyn.wikitext.toolkit.AbstractMarkupGenerationTest)

Aggregations

DocBookDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.DocBookDocumentBuilder)5 StringWriter (java.io.StringWriter)4 AbstractMarkupGenerationTest (org.eclipse.mylyn.wikitext.toolkit.AbstractMarkupGenerationTest)3 Test (org.junit.Test)3 Writer (java.io.Writer)2 MarkupParser (org.eclipse.mylyn.wikitext.parser.MarkupParser)2 XmlStreamWriter (org.eclipse.mylyn.wikitext.util.XmlStreamWriter)2 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 BuildException (org.apache.tools.ant.BuildException)1