Search in sources :

Example 1 with NoSplittingStrategy

use of org.eclipse.mylyn.wikitext.splitter.NoSplittingStrategy 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 NoSplittingStrategy

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

the class WikiToDocTask method computeOutline.

protected SplitOutlineItem computeOutline(Path path, MarkupLanguage markupLanguage, File defaultFile, String markupContent) {
    SplittingStrategy splittingStrategy = multipleOutputFiles ? new DefaultSplittingStrategy() : new NoSplittingStrategy();
    SplittingOutlineParser outlineParser = new SplittingOutlineParser();
    outlineParser.setMarkupLanguage(markupLanguage);
    outlineParser.setSplittingStrategy(splittingStrategy);
    SplitOutlineItem item = outlineParser.parse(markupContent);
    item.setSplitTarget(defaultFile.getName());
    item.setLabel(computeTitle(path));
    return item;
}
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) NoSplittingStrategy(org.eclipse.mylyn.wikitext.splitter.NoSplittingStrategy) SplitOutlineItem(org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem) DefaultSplittingStrategy(org.eclipse.mylyn.wikitext.splitter.DefaultSplittingStrategy)

Aggregations

DefaultSplittingStrategy (org.eclipse.mylyn.wikitext.splitter.DefaultSplittingStrategy)2 NoSplittingStrategy (org.eclipse.mylyn.wikitext.splitter.NoSplittingStrategy)2 SplitOutlineItem (org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem)2 SplittingOutlineParser (org.eclipse.mylyn.wikitext.splitter.SplittingOutlineParser)2 SplittingStrategy (org.eclipse.mylyn.wikitext.splitter.SplittingStrategy)2 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BuildException (org.apache.tools.ant.BuildException)1 MarkupParser (org.eclipse.mylyn.wikitext.parser.MarkupParser)1 HtmlDocumentBuilder (org.eclipse.mylyn.wikitext.parser.builder.HtmlDocumentBuilder)1 SplittingHtmlDocumentBuilder (org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder)1