Search in sources :

Example 6 with SplittingHtmlDocumentBuilder

use of org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder in project mylyn.docs by eclipse.

the class MarkupToEclipseHelpMojo method processMarkup.

protected void processMarkup(File sourceFile, String relativePath, MarkupLanguage markupLanguage) {
    getLog().info(format("Processing markup file: {0}", sourceFile));
    String name = sourceFile.getName();
    if (name.lastIndexOf('.') != -1) {
        name = name.substring(0, name.lastIndexOf('.'));
    }
    File htmlOutputFile = computeHtmlFile(relativePath, name);
    if (!htmlOutputFile.exists() || htmlOutputFile.lastModified() < sourceFile.lastModified()) {
        String markupContent = readFully(sourceFile);
        if (!htmlOutputFile.getParentFile().exists()) {
            if (!htmlOutputFile.getParentFile().mkdirs()) {
                throw new BuildFailureException(format("Cannot create folder {0}", htmlOutputFile.getParentFile()));
            }
        }
        Writer writer = createWriter(htmlOutputFile);
        try {
            HtmlDocumentBuilder builder = createRootBuilder(writer, name, relativePath);
            SplittingStrategy splittingStrategy = createSplittingStrategy();
            SplittingOutlineParser outlineParser = createOutlineParser(markupLanguage, splittingStrategy);
            SplitOutlineItem rootTocItem = outlineParser.parse(markupContent);
            rootTocItem.setSplitTarget(htmlOutputFile.getName());
            SplittingHtmlDocumentBuilder splittingBuilder = createSplittingBuilder(builder, rootTocItem, htmlOutputFile, relativePath);
            MarkupParser parser = new MarkupParser();
            parser.setMarkupLanguage(markupLanguage);
            parser.setBuilder(splittingBuilder);
            parser.parse(markupContent);
            createEclipseHelpToc(rootTocItem, sourceFile, relativePath, htmlOutputFile, name);
        } finally {
            close(writer, htmlOutputFile);
        }
    }
}
Also used : SplittingStrategy(org.eclipse.mylyn.wikitext.splitter.SplittingStrategy) NoSplittingStrategy(org.eclipse.mylyn.wikitext.splitter.NoSplittingStrategy) DefaultSplittingStrategy(org.eclipse.mylyn.wikitext.splitter.DefaultSplittingStrategy) SplittingOutlineParser(org.eclipse.mylyn.wikitext.splitter.SplittingOutlineParser) SplitOutlineItem(org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) File(java.io.File) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Aggregations

SplittingHtmlDocumentBuilder (org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder)6 File (java.io.File)5 HtmlDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder)5 SplitOutlineItem (org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem)5 OutputStreamWriter (java.io.OutputStreamWriter)3 Writer (java.io.Writer)3 MarkupParser (org.eclipse.mylyn.wikitext.parser.MarkupParser)3 BufferedOutputStream (java.io.BufferedOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 BuildException (org.apache.tools.ant.BuildException)2 DefaultSplittingStrategy (org.eclipse.mylyn.wikitext.splitter.DefaultSplittingStrategy)2 NoSplittingStrategy (org.eclipse.mylyn.wikitext.splitter.NoSplittingStrategy)2 SplittingOutlineParser (org.eclipse.mylyn.wikitext.splitter.SplittingOutlineParser)2 SplittingStrategy (org.eclipse.mylyn.wikitext.splitter.SplittingStrategy)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 MalformedURLException (java.net.MalformedURLException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 MediaWikiLanguage (org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage)1