Search in sources :

Example 1 with DefaultXmlStreamWriter

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

the class MarkupToDitaTask method processFile.

private void processFile(MarkupLanguage markupLanguage, final File baseDir, final File source) throws BuildException {
    // $NON-NLS-1$
    log(MessageFormat.format(Messages.getString("MarkupToDitaTask.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 outputFile = new File(source.getParentFile(), filenameFormat.replace("$1", name));
    if (!outputFile.exists() || overwrite || outputFile.lastModified() < source.lastModified()) {
        if (markupContent == null) {
            markupContent = readFully(source);
        }
        performValidation(source, markupContent);
        OutlineItem outline = new OutlineParser(markupLanguage).parse(markupContent);
        Writer writer;
        try {
            // $NON-NLS-1$
            writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(outputFile)), "utf-8");
        } catch (Exception e) {
            throw new BuildException(// $NON-NLS-1$
            MessageFormat.format(// $NON-NLS-1$
            Messages.getString("MarkupToDitaTask.11"), // $NON-NLS-1$
            outputFile, e.getMessage()), e);
        }
        try {
            if (topicStrategy == BreakStrategy.NONE) {
                DitaTopicDocumentBuilder builder = new DitaTopicDocumentBuilder(new DefaultXmlStreamWriter(writer), formatting);
                builder.setRootTopicTitle(bookTitle);
                MarkupParser parser = new MarkupParser();
                parser.setMarkupLanguage(markupLanguage);
                parser.setBuilder(builder);
                if (topicDoctype != null) {
                    builder.setDoctype(topicDoctype);
                }
                builder.setFilename(outputFile.getName());
                builder.setOutline(outline);
                parser.parse(markupContent);
            } else {
                DitaBookMapDocumentBuilder builder = new DitaBookMapDocumentBuilder(formatting ? new FormattingXMLStreamWriter(new DefaultXmlStreamWriter(writer)) : new DefaultXmlStreamWriter(writer));
                try {
                    builder.setFormattingDependencies(formatting);
                    MarkupParser parser = new MarkupParser();
                    parser.setMarkupLanguage(markupLanguage);
                    parser.setBuilder(builder);
                    builder.setBookTitle(bookTitle == null ? name : bookTitle);
                    if (doctype != null) {
                        builder.setDoctype(doctype);
                    }
                    if (topicDoctype != null) {
                        builder.setTopicDoctype(topicDoctype);
                    }
                    builder.setTargetFile(outputFile);
                    builder.setTopicFolder(topicFolder);
                    builder.setOutline(outline);
                    switch(topicStrategy) {
                        case FIRST:
                            if (!outline.getChildren().isEmpty()) {
                                builder.setTopicBreakLevel(outline.getChildren().get(0).getLevel());
                            } else {
                                builder.setTopicBreakLevel(1);
                            }
                            break;
                        case LEVEL1:
                            builder.setTopicBreakLevel(1);
                            break;
                    }
                    parser.parse(markupContent);
                } finally {
                    try {
                        builder.close();
                    } catch (IOException e) {
                        throw new BuildException(MessageFormat.format(// $NON-NLS-1$
                        Messages.getString("MarkupToDitaTask.12"), // $NON-NLS-1$
                        outputFile, e.getMessage()), e);
                    }
                }
            }
        } finally {
            try {
                writer.close();
            } catch (Exception e) {
                throw new BuildException(MessageFormat.format(// $NON-NLS-1$
                Messages.getString("MarkupToDitaTask.12"), // $NON-NLS-1$
                outputFile, e.getMessage()), e);
            }
        }
    }
}
Also used : DitaBookMapDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.DitaBookMapDocumentBuilder) FormattingXMLStreamWriter(org.eclipse.mylyn.wikitext.util.FormattingXMLStreamWriter) DitaTopicDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.DitaTopicDocumentBuilder) DefaultXmlStreamWriter(org.eclipse.mylyn.wikitext.util.DefaultXmlStreamWriter) IOException(java.io.IOException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem) OutlineParser(org.eclipse.mylyn.wikitext.parser.outline.OutlineParser) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) FormattingXMLStreamWriter(org.eclipse.mylyn.wikitext.util.FormattingXMLStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) DefaultXmlStreamWriter(org.eclipse.mylyn.wikitext.util.DefaultXmlStreamWriter) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 2 with DefaultXmlStreamWriter

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

the class FormattingXMLStreamWriterTest method setUp.

@Before
public void setUp() {
    out = new StringWriter();
    writer = new FormattingXMLStreamWriter(new DefaultXmlStreamWriter(out));
}
Also used : FormattingXMLStreamWriter(org.eclipse.mylyn.wikitext.util.FormattingXMLStreamWriter) StringWriter(java.io.StringWriter) DefaultXmlStreamWriter(org.eclipse.mylyn.wikitext.util.DefaultXmlStreamWriter) Before(org.junit.Before)

Example 3 with DefaultXmlStreamWriter

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

the class XslfoDocumentBuilderIntegrationTest method setUp.

@Override
protected void setUp() throws Exception {
    out = new StringWriter();
    documentBuilder = new XslfoDocumentBuilder(new DefaultXmlStreamWriter(out));
    parser = new MarkupParser();
    parser.setBuilder(documentBuilder);
}
Also used : StringWriter(java.io.StringWriter) DefaultXmlStreamWriter(org.eclipse.mylyn.wikitext.util.DefaultXmlStreamWriter) XslfoDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.XslfoDocumentBuilder) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 4 with DefaultXmlStreamWriter

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

the class DitaBookMapDocumentBuilder method getCurrentTopic.

private DitaTopicDocumentBuilder getCurrentTopic() {
    if (currentTopic == null) {
        try {
            currentTopicFile = computeFile(latestHeadingId);
            currentTopicOut = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(currentTopicFile)), // $NON-NLS-1$
            "utf-8");
        } catch (IOException e1) {
            throw new IllegalStateException(e1);
        }
        // create a DITA map entry
        String relativeTopic = currentTopicFile.getName();
        if (topicFolder != null) {
            relativeTopic = topicFolder + '/' + relativeTopic;
        }
        // $NON-NLS-1$
        writer.writeEmptyElement("chapter");
        // $NON-NLS-1$
        writer.writeAttribute("href", relativeTopic);
        // $NON-NLS-1$
        titleText = "";
        mapEntryOpen = true;
        currentTopic = new DitaTopicDocumentBuilder(new DefaultXmlStreamWriter(currentTopicOut), formattingDependencies);
        if (topicDoctype != null) {
            currentTopic.setDoctype(topicDoctype);
        }
        currentTopic.setTopicBreakLevel(topicBreakLevel);
        currentTopic.setOutline(outline);
        currentTopic.setFilename(currentTopicFile.getName());
        currentTopic.beginDocument();
    }
    return currentTopic;
}
Also used : FileOutputStream(java.io.FileOutputStream) DefaultXmlStreamWriter(org.eclipse.mylyn.wikitext.util.DefaultXmlStreamWriter) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 5 with DefaultXmlStreamWriter

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

the class DitaTopicDocumentBuilderTest method testNoFormatting.

public void testNoFormatting() {
    parser = new MarkupParser();
    parser.setMarkupLanguage(new TextileLanguage());
    out = new StringWriter();
    DefaultXmlStreamWriter xmlStreamWriter = new DefaultXmlStreamWriter(out);
    builder = new DitaTopicDocumentBuilder(xmlStreamWriter, false);
    parser.setBuilder(builder);
    parser.parse("h1. Title1\n\nsome content in a para");
    xmlStreamWriter.close();
    String dita = out.toString();
    assertTrue(dita.contains("<topic id=\"Title1\"><title>Title1</title><body><p>some content in a para</p></body></topic>"));
}
Also used : TextileLanguage(org.eclipse.mylyn.wikitext.textile.TextileLanguage) StringWriter(java.io.StringWriter) DitaTopicDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.DitaTopicDocumentBuilder) DefaultXmlStreamWriter(org.eclipse.mylyn.wikitext.util.DefaultXmlStreamWriter) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Aggregations

DefaultXmlStreamWriter (org.eclipse.mylyn.wikitext.util.DefaultXmlStreamWriter)5 StringWriter (java.io.StringWriter)3 MarkupParser (org.eclipse.mylyn.wikitext.parser.MarkupParser)3 BufferedOutputStream (java.io.BufferedOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 OutputStreamWriter (java.io.OutputStreamWriter)2 DitaTopicDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.DitaTopicDocumentBuilder)2 FormattingXMLStreamWriter (org.eclipse.mylyn.wikitext.util.FormattingXMLStreamWriter)2 File (java.io.File)1 Writer (java.io.Writer)1 BuildException (org.apache.tools.ant.BuildException)1 DitaBookMapDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.DitaBookMapDocumentBuilder)1 XslfoDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.XslfoDocumentBuilder)1 OutlineItem (org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)1 OutlineParser (org.eclipse.mylyn.wikitext.parser.outline.OutlineParser)1 TextileLanguage (org.eclipse.mylyn.wikitext.textile.TextileLanguage)1 Before (org.junit.Before)1