use of org.eclipse.mylyn.wikitext.splitter.SplittingStrategy 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;
}
use of org.eclipse.mylyn.wikitext.splitter.SplittingStrategy 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;
}
use of org.eclipse.mylyn.wikitext.splitter.SplittingStrategy in project mylyn.docs by eclipse.
the class MarkupToEclipseHelpMojo method processMarkup.
protected void processMarkup(File sourceFile, String relativePath, MarkupLanguage markupLanguage) {
getLog().info(format("Processing markup file: {0}", sourceFile));
String name = sourceFile.getName();
if (name.lastIndexOf('.') != -1) {
name = name.substring(0, name.lastIndexOf('.'));
}
File htmlOutputFile = computeHtmlFile(relativePath, name);
if (!htmlOutputFile.exists() || htmlOutputFile.lastModified() < sourceFile.lastModified()) {
String markupContent = readFully(sourceFile);
if (!htmlOutputFile.getParentFile().exists()) {
if (!htmlOutputFile.getParentFile().mkdirs()) {
throw new BuildFailureException(format("Cannot create folder {0}", htmlOutputFile.getParentFile()));
}
}
Writer writer = createWriter(htmlOutputFile);
try {
HtmlDocumentBuilder builder = createRootBuilder(writer, name, relativePath);
SplittingStrategy splittingStrategy = createSplittingStrategy();
SplittingOutlineParser outlineParser = createOutlineParser(markupLanguage, splittingStrategy);
SplitOutlineItem rootTocItem = outlineParser.parse(markupContent);
rootTocItem.setSplitTarget(htmlOutputFile.getName());
SplittingHtmlDocumentBuilder splittingBuilder = createSplittingBuilder(builder, rootTocItem, htmlOutputFile, relativePath);
MarkupParser parser = new MarkupParser();
parser.setMarkupLanguage(markupLanguage);
parser.setBuilder(splittingBuilder);
parser.parse(markupContent);
createEclipseHelpToc(rootTocItem, sourceFile, relativePath, htmlOutputFile, name);
} finally {
close(writer, htmlOutputFile);
}
}
}
Aggregations