Search in sources :

Example 1 with SplittingHtmlDocumentBuilder

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

the class MarkupToHtmlTask method processFile.

/**
 * process the file
 *
 * @param baseDir
 * @param source
 * @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("MarkupToHtmlTask.14"), source), Project.MSG_VERBOSE);
    String markupContent = null;
    String name = source.getName();
    if (name.lastIndexOf('.') != -1) {
        name = name.substring(0, name.lastIndexOf('.'));
    }
    File htmlOutputFile = computeHtmlFile(source, name);
    if (!htmlOutputFile.exists() || overwrite || htmlOutputFile.lastModified() < source.lastModified()) {
        if (markupContent == null) {
            markupContent = readFully(source);
        }
        performValidation(source, markupContent);
        Writer writer;
        try {
            // $NON-NLS-1$
            writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(htmlOutputFile)), "utf-8");
        } catch (Exception e) {
            throw new BuildException(MessageFormat.format(Messages.getString("MarkupToHtmlTask.16"), htmlOutputFile, e.getMessage()), // $NON-NLS-1$
            e);
        }
        try {
            HtmlDocumentBuilder builder = new HtmlDocumentBuilder(writer, formatOutput);
            for (Stylesheet stylesheet : stylesheets) {
                HtmlDocumentBuilder.Stylesheet builderStylesheet;
                if (stylesheet.url != null) {
                    builderStylesheet = new HtmlDocumentBuilder.Stylesheet(stylesheet.url);
                } else {
                    builderStylesheet = new HtmlDocumentBuilder.Stylesheet(stylesheet.file);
                }
                builder.addCssStylesheet(builderStylesheet);
                if (!stylesheet.attributes.isEmpty()) {
                    for (Map.Entry<String, String> attr : stylesheet.attributes.entrySet()) {
                        builderStylesheet.getAttributes().put(attr.getKey(), attr.getValue());
                    }
                }
            }
            builder.setTitle(title == null ? name : title);
            builder.setEmitDtd(emitDoctype);
            if (emitDoctype && htmlDoctype != null) {
                builder.setHtmlDtd(htmlDoctype);
            }
            builder.setUseInlineStyles(useInlineCssStyles);
            builder.setSuppressBuiltInStyles(suppressBuiltInCssStyles);
            builder.setLinkRel(linkRel);
            builder.setDefaultAbsoluteLinkTarget(defaultAbsoluteLinkTarget);
            builder.setPrependImagePrefix(prependImagePrefix);
            builder.setXhtmlStrict(xhtmlStrict);
            builder.setCopyrightNotice(copyrightNotice);
            builder.setHtmlFilenameFormat(htmlFilenameFormat);
            SplittingStrategy splittingStrategy = multipleOutputFiles ? new DefaultSplittingStrategy() : new NoSplittingStrategy();
            SplittingOutlineParser outlineParser = new SplittingOutlineParser();
            outlineParser.setMarkupLanguage(markupLanguage.clone());
            outlineParser.setSplittingStrategy(splittingStrategy);
            SplitOutlineItem item = outlineParser.parse(markupContent);
            item.setSplitTarget(htmlOutputFile.getName());
            SplittingHtmlDocumentBuilder splittingBuilder = new SplittingHtmlDocumentBuilder();
            splittingBuilder.setRootBuilder(builder);
            splittingBuilder.setOutline(item);
            splittingBuilder.setRootFile(htmlOutputFile);
            splittingBuilder.setNavigationImages(navigationImages);
            splittingBuilder.setFormatting(formatOutput);
            MarkupParser parser = new MarkupParser();
            parser.setMarkupLanguage(markupLanguage);
            parser.setBuilder(splittingBuilder);
            parser.parse(markupContent);
            processed(markupContent, item, baseDir, source);
        } finally {
            try {
                writer.close();
            } catch (Exception e) {
                throw new BuildException(MessageFormat.format(// $NON-NLS-1$
                Messages.getString("MarkupToHtmlTask.17"), // $NON-NLS-1$
                htmlOutputFile, e.getMessage()), e);
            }
        }
    }
    return markupContent;
}
Also used : SplittingStrategy(org.eclipse.mylyn.wikitext.splitter.SplittingStrategy) NoSplittingStrategy(org.eclipse.mylyn.wikitext.splitter.NoSplittingStrategy) DefaultSplittingStrategy(org.eclipse.mylyn.wikitext.splitter.DefaultSplittingStrategy) SplitOutlineItem(org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) BuildException(org.apache.tools.ant.BuildException) FileOutputStream(java.io.FileOutputStream) SplittingOutlineParser(org.eclipse.mylyn.wikitext.splitter.SplittingOutlineParser) NoSplittingStrategy(org.eclipse.mylyn.wikitext.splitter.NoSplittingStrategy) OutputStreamWriter(java.io.OutputStreamWriter) BuildException(org.apache.tools.ant.BuildException) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) HashMap(java.util.HashMap) Map(java.util.Map) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) DefaultSplittingStrategy(org.eclipse.mylyn.wikitext.splitter.DefaultSplittingStrategy) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 2 with SplittingHtmlDocumentBuilder

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

the class WikiToDocTask method markupToDoc.

private void markupToDoc(MarkupLanguage markupLanguage, Path path, String markupContent, Map<String, SplitOutlineItem> pathNameToOutline, Set<String> imageFilenames) throws BuildException {
    File htmlOutputFile = computeHtmlOutputFile(path);
    File pathDir = htmlOutputFile.getParentFile();
    if (!pathDir.exists()) {
        if (!pathDir.mkdirs()) {
            throw new BuildException(// $NON-NLS-1$
            MessageFormat.format(// $NON-NLS-1$
            Messages.getString("WikiToDocTask_cannot_create_dest_folder"), pathDir.getAbsolutePath()));
        }
    }
    Writer writer;
    try {
        // $NON-NLS-1$
        writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(htmlOutputFile)), "utf-8");
    } catch (Exception e) {
        throw new BuildException(// $NON-NLS-1$
        MessageFormat.format(// $NON-NLS-1$
        Messages.getString("WikiToDocTask_cannot_create_output_file"), // $NON-NLS-1$
        htmlOutputFile, e.getMessage()), e);
    }
    try {
        HtmlDocumentBuilder builder = new HtmlDocumentBuilder(writer, formatOutput);
        for (Stylesheet stylesheet : stylesheets) {
            HtmlDocumentBuilder.Stylesheet builderStylesheet = createBuilderStylesheet(pathDir, stylesheet);
            builder.addCssStylesheet(builderStylesheet);
        }
        builder.setTitle(computeTitle(path));
        builder.setEmitDtd(emitDoctype);
        if (emitDoctype && htmlDoctype != null) {
            builder.setHtmlDtd(htmlDoctype);
        }
        builder.setUseInlineStyles(useInlineCssStyles);
        builder.setSuppressBuiltInStyles(suppressBuiltInCssStyles);
        builder.setLinkRel(linkRel);
        builder.setDefaultAbsoluteLinkTarget(defaultAbsoluteLinkTarget);
        builder.setPrependImagePrefix(prependImagePrefix);
        builder.setXhtmlStrict(xhtmlStrict);
        MarkupLanguage markupLanguageClone = markupLanguage.clone();
        if (markupLanguageClone instanceof MediaWikiLanguage) {
            MediaWikiLanguage mediaWikiLanguage = (MediaWikiLanguage) markupLanguageClone;
            mediaWikiLanguage.setPageMapping(new PathPageMapping(path, paths, pathNameToOutline));
            if (imageFilenames != null) {
                mediaWikiLanguage.setImageNames(imageFilenames);
            }
        }
        SplitOutlineItem item = pathNameToOutline.get(path.name);
        SplittingHtmlDocumentBuilder splittingBuilder = new SplittingHtmlDocumentBuilder();
        splittingBuilder.setRootBuilder(builder);
        splittingBuilder.setOutline(item);
        splittingBuilder.setRootFile(htmlOutputFile);
        splittingBuilder.setNavigationImages(navigationImages);
        splittingBuilder.setFormatting(formatOutput);
        splittingBuilder.setNavigationImagePath(computeNavigationImagePath(pathDir));
        MarkupParser parser = new MarkupParser();
        parser.setMarkupLanguage(markupLanguageClone);
        parser.setBuilder(splittingBuilder);
        parser.parse(markupContent);
    } finally {
        try {
            writer.close();
        } catch (Exception e) {
            throw new BuildException(MessageFormat.format(// $NON-NLS-1$
            Messages.getString("WikiToDocTask_cannot_write_output_file"), // $NON-NLS-1$
            htmlOutputFile, e.getMessage()), e);
        }
    }
}
Also used : SplitOutlineItem(org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) FileOutputStream(java.io.FileOutputStream) MediaWikiLanguage(org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage) OutputStreamWriter(java.io.OutputStreamWriter) BuildException(org.apache.tools.ant.BuildException) MarkupLanguage(org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) MarkupParser(org.eclipse.mylyn.wikitext.parser.MarkupParser)

Example 3 with SplittingHtmlDocumentBuilder

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

the class MarkupToEclipseHelpMojoTest method embeddedTableOfContents.

@Test
public void embeddedTableOfContents() {
    HtmlDocumentBuilder builder = mock(HtmlDocumentBuilder.class);
    SplitOutlineItem item = mock(SplitOutlineItem.class);
    File htmlOutputFile = mock(File.class);
    SplittingHtmlDocumentBuilder splittingBuilder = markupToEclipseHelp.createSplittingBuilder(builder, item, htmlOutputFile, "");
    assertFalse(splittingBuilder.isEmbeddedTableOfContents());
    markupToEclipseHelp.embeddedTableOfContents = true;
    splittingBuilder = markupToEclipseHelp.createSplittingBuilder(builder, item, htmlOutputFile, "");
    assertTrue(splittingBuilder.isEmbeddedTableOfContents());
}
Also used : SplitOutlineItem(org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) File(java.io.File) Test(org.junit.Test)

Example 4 with SplittingHtmlDocumentBuilder

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

the class MarkupToEclipseHelpMojoTest method assertNavigationImagesPath.

private void assertNavigationImagesPath(String expected, String relativePath) {
    HtmlDocumentBuilder builder = mock(HtmlDocumentBuilder.class);
    SplitOutlineItem item = mock(SplitOutlineItem.class);
    SplittingHtmlDocumentBuilder splittingBuilder = markupToEclipseHelp.createSplittingBuilder(builder, item, mock(File.class), relativePath);
    assertEquals(expected, splittingBuilder.getNavigationImagePath());
}
Also used : SplitOutlineItem(org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) HtmlDocumentBuilder(org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder) SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder) File(java.io.File)

Example 5 with SplittingHtmlDocumentBuilder

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

the class MarkupToEclipseHelpMojo method createSplittingBuilder.

protected SplittingHtmlDocumentBuilder createSplittingBuilder(HtmlDocumentBuilder builder, SplitOutlineItem item, File htmlOutputFile, String relativePath) {
    SplittingHtmlDocumentBuilder splittingBuilder = new SplittingHtmlDocumentBuilder();
    splittingBuilder.setRootBuilder(builder);
    splittingBuilder.setOutline(item);
    splittingBuilder.setEmbeddedTableOfContents(embeddedTableOfContents);
    splittingBuilder.setRootFile(htmlOutputFile);
    splittingBuilder.setNavigationImages(navigationImages);
    splittingBuilder.setNavigationImagePath(computeResourcePath(splittingBuilder.getNavigationImagePath(), relativePath));
    splittingBuilder.setFormatting(formatOutput);
    return splittingBuilder;
}
Also used : SplittingHtmlDocumentBuilder(org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder)

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