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);
}
}
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);
}
}
}
}
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;
}
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);
}
}
Aggregations