Search in sources :

Example 1 with XslfoDocumentBuilder

use of org.eclipse.mylyn.wikitext.parser.builder.XslfoDocumentBuilder 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 2 with XslfoDocumentBuilder

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

the class MarkupToXslfoTask method processFile.

/**
 * process the file
 *
 * @param baseDir
 * @param source
 * @return
 * @return the lightweight markup, or null if the file was not written
 * @throws BuildException
 */
protected String processFile(MarkupLanguage markupLanguage, final File baseDir, final File source) throws BuildException {
    // $NON-NLS-1$
    log(MessageFormat.format(Messages.getString("MarkupToXslfoTask.7"), source), Project.MSG_VERBOSE);
    String markupContent = null;
    String name = source.getName();
    if (name.lastIndexOf('.') != -1) {
        name = name.substring(0, name.lastIndexOf('.'));
    }
    File outputFile = computeXslfoFile(source, name);
    if (targetdir != null) {
        outputFile = new File(targetdir, outputFile.getName());
    }
    if (!outputFile.exists() || overwrite || outputFile.lastModified() < source.lastModified()) {
        if (markupContent == null) {
            markupContent = readFully(source);
        }
        performValidation(source, markupContent);
        Writer out;
        try {
            // $NON-NLS-1$
            out = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(outputFile)), "utf-8");
        } catch (Exception e) {
            throw new BuildException(MessageFormat.format(Messages.getString("MarkupToXslfoTask.8"), outputFile, e.getMessage()), // $NON-NLS-1$
            e);
        }
        try {
            XslfoDocumentBuilder builder = new XslfoDocumentBuilder(out);
            XslfoDocumentBuilder.Configuration configuration = this.configuration.clone();
            if (configuration.getTitle() == null) {
                configuration.setTitle(name);
            }
            builder.setConfiguration(configuration);
            builder.setBase(source.getParentFile().toURI());
            MarkupParser parser = new MarkupParser();
            parser.setMarkupLanguage(markupLanguage);
            parser.setBuilder(builder);
            if (generateBookmarks) {
                OutlineItem outline = new OutlineParser(markupLanguage).parse(markupContent);
                builder.setOutline(outline);
            }
            parser.parse(markupContent);
        } finally {
            try {
                out.close();
            } catch (Exception e) {
                throw new BuildException(MessageFormat.format(// $NON-NLS-1$
                Messages.getString("MarkupToXslfoTask.9"), // $NON-NLS-1$
                outputFile, e.getMessage()), e);
            }
        }
    }
    return markupContent;
}
Also used : 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) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) XslfoDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.XslfoDocumentBuilder) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Aggregations

MarkupParser (org.eclipse.mylyn.wikitext.parser.MarkupParser)2 XslfoDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.XslfoDocumentBuilder)2 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 BuildException (org.apache.tools.ant.BuildException)1 OutlineItem (org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)1 OutlineParser (org.eclipse.mylyn.wikitext.parser.outline.OutlineParser)1 DefaultXmlStreamWriter (org.eclipse.mylyn.wikitext.util.DefaultXmlStreamWriter)1