Search in sources :

Example 1 with SplittingMarkupToEclipseToc

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

the class WikiToDocTask method createToc.

private void createToc(final Path path, OutlineItem rootItem) {
    SplittingMarkupToEclipseToc markupToEclipseToc = new SplittingMarkupToEclipseToc() {

        @Override
        protected String computeFile(OutlineItem item) {
            if (item instanceof SplitOutlineItem) {
                return computeTocRelativeFile(item, path);
            }
            return super.computeFile(item);
        }
    };
    markupToEclipseToc.setBookTitle(path.getTitle());
    markupToEclipseToc.setHtmlFile(computeTocRelativeFile(rootItem, path));
    String tocContents = markupToEclipseToc.createToc(rootItem);
    // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
    File tocFile = new File(dest, path.name.replaceAll("[^a-zA-Z0-9]", "-") + "-toc.xml");
    try {
        // $NON-NLS-1$
        Writer writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(tocFile)), "UTF-8");
        try {
            writer.write(tocContents);
        } finally {
            writer.close();
        }
    } catch (IOException e) {
        // $NON-NLS-1$
        String message = MessageFormat.format("Cannot write {0}: {1}", tocFile, e.getMessage());
        throw new BuildException(message, e);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) SplittingMarkupToEclipseToc(org.eclipse.mylyn.wikitext.splitter.SplittingMarkupToEclipseToc) SplitOutlineItem(org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) SplitOutlineItem(org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)

Example 2 with SplittingMarkupToEclipseToc

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

the class MarkupToEclipseHelpTask method processed.

@Override
void processed(String markupContent, SplitOutlineItem item, final File baseDir, final File source) {
    super.processed(markupContent, item, baseDir, source);
    String name = source.getName();
    if (name.lastIndexOf('.') != -1) {
        name = name.substring(0, name.lastIndexOf('.'));
    }
    File tocOutputFile = computeTocFile(source, name);
    if (!tocOutputFile.exists() || overwrite || tocOutputFile.lastModified() < source.lastModified()) {
        File htmlOutputFile = computeHtmlFile(source, name);
        Writer writer;
        try {
            // $NON-NLS-1$
            writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(tocOutputFile)), "utf-8");
        } catch (Exception e) {
            throw new // $NON-NLS-1$
            BuildException(// $NON-NLS-1$
            String.format("Cannot write to file '%s': %s", tocOutputFile, e.getMessage()), e);
        }
        try {
            MarkupToEclipseToc toEclipseToc = new SplittingMarkupToEclipseToc();
            toEclipseToc.setHelpPrefix(helpPrefix);
            toEclipseToc.setAnchorLevel(tocAnchorLevel);
            // $NON-NLS-1$//$NON-NLS-2$
            System.out.println("Help: " + baseDir + " " + htmlOutputFile);
            toEclipseToc.setBookTitle(title == null ? name : title);
            toEclipseToc.setCopyrightNotice(getCopyrightNotice());
            String basePath = baseDir.getAbsolutePath().replace('\\', '/');
            String outputFilePath = htmlOutputFile.getAbsolutePath().replace('\\', '/');
            if (outputFilePath.startsWith(basePath)) {
                String filePath = outputFilePath.substring(basePath.length());
                if (filePath.startsWith("/")) {
                    // $NON-NLS-1$
                    filePath = filePath.substring(1);
                }
                if (filePath.lastIndexOf('/') != -1) {
                    String relativePart = filePath.substring(0, filePath.lastIndexOf('/'));
                    toEclipseToc.setHelpPrefix(helpPrefix == null ? relativePart : helpPrefix + '/' + relativePart);
                }
            }
            toEclipseToc.setHtmlFile(htmlOutputFile.getName());
            String tocXml = toEclipseToc.createToc(item);
            try {
                writer.write(tocXml);
            } catch (Exception e) {
                // $NON-NLS-1$
                throw new BuildException(String.format("Cannot write to file '%s': %s", tocXml, e.getMessage()), e);
            }
        } finally {
            try {
                writer.close();
            } catch (Exception e) {
                throw new BuildException(// $NON-NLS-1$
                String.format(// $NON-NLS-1$
                "Cannot write to file '%s': %s", // $NON-NLS-1$
                tocOutputFile, e.getMessage()), e);
            }
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) SplittingMarkupToEclipseToc(org.eclipse.mylyn.wikitext.splitter.SplittingMarkupToEclipseToc) OutputStreamWriter(java.io.OutputStreamWriter) MarkupToEclipseToc(org.eclipse.mylyn.wikitext.parser.util.MarkupToEclipseToc) SplittingMarkupToEclipseToc(org.eclipse.mylyn.wikitext.splitter.SplittingMarkupToEclipseToc) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) BuildException(org.apache.tools.ant.BuildException)

Example 3 with SplittingMarkupToEclipseToc

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

the class MarkupToEclipseHelpMojo method createMarkupToEclipseToc.

protected MarkupToEclipseToc createMarkupToEclipseToc(String relativePath, File htmlOutputFile, String name) {
    MarkupToEclipseToc toEclipseToc = new SplittingMarkupToEclipseToc();
    toEclipseToc.setBookTitle(title == null ? name : title);
    toEclipseToc.setCopyrightNotice(copyrightNotice);
    toEclipseToc.setAnchorLevel(tocAnchorLevel);
    toEclipseToc.setHelpPrefix(calculateHelpPrefix(relativePath));
    toEclipseToc.setHtmlFile(htmlOutputFile.getName());
    return toEclipseToc;
}
Also used : SplittingMarkupToEclipseToc(org.eclipse.mylyn.wikitext.splitter.SplittingMarkupToEclipseToc) MarkupToEclipseToc(org.eclipse.mylyn.wikitext.parser.util.MarkupToEclipseToc) SplittingMarkupToEclipseToc(org.eclipse.mylyn.wikitext.splitter.SplittingMarkupToEclipseToc)

Example 4 with SplittingMarkupToEclipseToc

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

the class WikiToDocTask method createToc.

private void createToc(List<Path> paths, final Map<String, SplitOutlineItem> pathNameToOutline) {
    // $NON-NLS-1$
    getProject().log(// $NON-NLS-1$
    MessageFormat.format(Messages.getString("WikiToDocTask_writing_toc"), tocFile), Project.MSG_VERBOSE);
    final OutlineItem rootItem = new // $NON-NLS-1$
    OutlineItem(// $NON-NLS-1$
    null, // $NON-NLS-1$
    0, // $NON-NLS-1$
    "<root>", // $NON-NLS-1$
    0, // $NON-NLS-1$
    -1, title == null ? computeTitle(paths.get(0)) : title);
    final Map<OutlineItem, Path> outlineItemToPath = new HashMap<OutlineItem, Path>();
    final Map<String, OutlineItem> nameToItem = new HashMap<String, OutlineItem>();
    // create root-level items
    for (Path path : paths) {
        if (path.includeInUnifiedToc) {
            SplitOutlineItem pathItem = pathNameToOutline.get(path.name);
            outlineItemToPath.put(pathItem, path);
            nameToItem.put(path.name, pathItem);
            if (path.getTocParentName() == null) {
                rootItem.getChildren().add(pathItem);
            }
        }
    }
    for (Path path : paths) {
        if (path.includeInUnifiedToc) {
            if (path.getTocParentName() != null) {
                SplitOutlineItem pathItem = pathNameToOutline.get(path.name);
                if (nameToItem.containsKey(path.getTocParentName())) {
                    nameToItem.get(path.getTocParentName()).getChildren().add(pathItem);
                } else {
                    throw new ConfigurationException(MessageFormat.format(Messages.getString("WikiToDocTask_unknown_tocParentName"), // $NON-NLS-1$
                    path.getTocParentName()));
                }
            }
        }
    }
    SplittingMarkupToEclipseToc markupToEclipseToc = new SplittingMarkupToEclipseToc() {

        @Override
        protected String computeFile(OutlineItem item) {
            if (item instanceof SplitOutlineItem) {
                return computeTocRelativeFile(outlineItemToPath, item);
            }
            return super.computeFile(item);
        }
    };
    markupToEclipseToc.setBookTitle(rootItem.getLabel());
    markupToEclipseToc.setHtmlFile(computeTocRelativeFile(outlineItemToPath, rootItem.getChildren().get(0)));
    String tocContents = markupToEclipseToc.createToc(rootItem);
    try {
        // $NON-NLS-1$
        Writer writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(tocFile)), "UTF-8");
        try {
            writer.write(tocContents);
        } finally {
            writer.close();
        }
    } catch (IOException e) {
        // $NON-NLS-1$
        String message = MessageFormat.format("Cannot write {0}: {1}", tocFile, e.getMessage());
        throw new BuildException(message, e);
    }
}
Also used : HashMap(java.util.HashMap) SplittingMarkupToEclipseToc(org.eclipse.mylyn.wikitext.splitter.SplittingMarkupToEclipseToc) SplitOutlineItem(org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem) IOException(java.io.IOException) SplitOutlineItem(org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem) OutlineItem(org.eclipse.mylyn.wikitext.parser.outline.OutlineItem) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) BuildException(org.apache.tools.ant.BuildException) BufferedOutputStream(java.io.BufferedOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Aggregations

SplittingMarkupToEclipseToc (org.eclipse.mylyn.wikitext.splitter.SplittingMarkupToEclipseToc)4 BufferedOutputStream (java.io.BufferedOutputStream)3 FileOutputStream (java.io.FileOutputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3 Writer (java.io.Writer)3 BuildException (org.apache.tools.ant.BuildException)3 File (java.io.File)2 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2 OutlineItem (org.eclipse.mylyn.wikitext.parser.outline.OutlineItem)2 MarkupToEclipseToc (org.eclipse.mylyn.wikitext.parser.util.MarkupToEclipseToc)2 SplitOutlineItem (org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem)2 HashMap (java.util.HashMap)1