use of org.eclipse.mylyn.wikitext.splitter.SplitOutlineItem 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);
}
}
Aggregations