use of org.eclipse.mylyn.wikitext.parser.util.MarkupToEclipseToc 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.parser.util.MarkupToEclipseToc 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.parser.util.MarkupToEclipseToc in project mylyn.docs by eclipse.
the class MarkupToEclipseHelpMojo method createEclipseHelpToc.
private void createEclipseHelpToc(SplitOutlineItem rootTocItem, File sourceFile, String relativePath, File htmlOutputFile, String name) {
File tocOutputFile = computeTocFile(htmlOutputFile, name);
if (!tocOutputFile.exists() || tocOutputFile.lastModified() < sourceFile.lastModified()) {
Writer writer = createWriter(tocOutputFile);
try {
MarkupToEclipseToc toEclipseToc = createMarkupToEclipseToc(relativePath, htmlOutputFile, name);
String tocXml = toEclipseToc.createToc(rootTocItem);
writer.write(tocXml);
} catch (IOException e) {
throw new BuildFailureException(format("Cannot write to file {0}: {1}", tocOutputFile, e.getMessage()), e);
} finally {
close(writer, tocOutputFile);
}
}
}
use of org.eclipse.mylyn.wikitext.parser.util.MarkupToEclipseToc in project mylyn.docs by eclipse.
the class MarkupToEclipseTocTest method setUp.
@Override
public void setUp() {
markupToEclipseToc = new MarkupToEclipseToc();
markupToEclipseToc.setMarkupLanguage(new TextileLanguage());
}
use of org.eclipse.mylyn.wikitext.parser.util.MarkupToEclipseToc in project mylyn.docs by eclipse.
the class ConvertMarkupToEclipseHelp method handleFile.
@Override
protected void handleFile(final IFile file, String name) {
super.handleFile(file, name);
// $NON-NLS-1$
final IFile newFile = file.getParent().getFile(new Path(name + "-toc.xml"));
if (newFile.exists()) {
if (!MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.ConvertMarkupToEclipseHelp_overwrite, NLS.bind(Messages.ConvertMarkupToEclipseHelp_fileExistsOverwrite, new Object[] { newFile.getFullPath() }))) {
return;
}
}
IPath parentFullPath = file.getParent().getFullPath();
IPath pluginPathToHelp = parentFullPath.removeFirstSegments(1);
final MarkupToEclipseToc markupToEclipseToc = new MarkupToEclipseToc();
markupToEclipseToc.setMarkupLanguage(markupLanguage);
markupToEclipseToc.setBookTitle(name);
// $NON-NLS-1$
String htmlFilePath = name + ".html";
if (pluginPathToHelp.segmentCount() > 0) {
String pathPart = pluginPathToHelp.toString();
if (!pathPart.endsWith("/")) {
// $NON-NLS-1$
// $NON-NLS-1$
pathPart = pathPart + "/";
}
htmlFilePath = pathPart + htmlFilePath;
}
markupToEclipseToc.setHtmlFile(htmlFilePath);
try {
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
String content = IOUtil.readFully(file);
final String tocXml = markupToEclipseToc.parse(content);
if (newFile.exists()) {
// $NON-NLS-1$
newFile.setContents(// $NON-NLS-1$
new ByteArrayInputStream(tocXml.getBytes("utf-8")), // $NON-NLS-1$
false, // $NON-NLS-1$
true, monitor);
} else {
// $NON-NLS-1$
newFile.create(new ByteArrayInputStream(tocXml.getBytes("utf-8")), false, monitor);
}
// $NON-NLS-1$
newFile.setCharset("utf-8", monitor);
} catch (Exception e) {
throw new InvocationTargetException(e);
}
}
};
try {
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(runnable);
} catch (InterruptedException e) {
return;
} catch (InvocationTargetException e) {
throw e.getCause();
}
} catch (Throwable e) {
StringWriter message = new StringWriter();
PrintWriter out = new PrintWriter(message);
out.println(Messages.ConvertMarkupToEclipseHelp_cannotConvert + e.getMessage());
out.println(Messages.ConvertMarkupToEclipseHelp_detailsFollow);
e.printStackTrace(out);
out.close();
MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.ConvertMarkupToEclipseHelp_cannotCompleteOperation, message.toString());
}
}
Aggregations