use of org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder 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.SplittingHtmlDocumentBuilder in project mylyn.docs by eclipse.
the class WikiToDocTask method markupToDoc.
private void markupToDoc(MarkupLanguage markupLanguage, Path path, String markupContent, Map<String, SplitOutlineItem> pathNameToOutline, Set<String> imageFilenames) throws BuildException {
File htmlOutputFile = computeHtmlOutputFile(path);
File pathDir = htmlOutputFile.getParentFile();
if (!pathDir.exists()) {
if (!pathDir.mkdirs()) {
throw new BuildException(// $NON-NLS-1$
MessageFormat.format(// $NON-NLS-1$
Messages.getString("WikiToDocTask_cannot_create_dest_folder"), pathDir.getAbsolutePath()));
}
}
Writer writer;
try {
// $NON-NLS-1$
writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(htmlOutputFile)), "utf-8");
} catch (Exception e) {
throw new BuildException(// $NON-NLS-1$
MessageFormat.format(// $NON-NLS-1$
Messages.getString("WikiToDocTask_cannot_create_output_file"), // $NON-NLS-1$
htmlOutputFile, e.getMessage()), e);
}
try {
HtmlDocumentBuilder builder = new HtmlDocumentBuilder(writer, formatOutput);
for (Stylesheet stylesheet : stylesheets) {
HtmlDocumentBuilder.Stylesheet builderStylesheet = createBuilderStylesheet(pathDir, stylesheet);
builder.addCssStylesheet(builderStylesheet);
}
builder.setTitle(computeTitle(path));
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);
MarkupLanguage markupLanguageClone = markupLanguage.clone();
if (markupLanguageClone instanceof MediaWikiLanguage) {
MediaWikiLanguage mediaWikiLanguage = (MediaWikiLanguage) markupLanguageClone;
mediaWikiLanguage.setPageMapping(new PathPageMapping(path, paths, pathNameToOutline));
if (imageFilenames != null) {
mediaWikiLanguage.setImageNames(imageFilenames);
}
}
SplitOutlineItem item = pathNameToOutline.get(path.name);
SplittingHtmlDocumentBuilder splittingBuilder = new SplittingHtmlDocumentBuilder();
splittingBuilder.setRootBuilder(builder);
splittingBuilder.setOutline(item);
splittingBuilder.setRootFile(htmlOutputFile);
splittingBuilder.setNavigationImages(navigationImages);
splittingBuilder.setFormatting(formatOutput);
splittingBuilder.setNavigationImagePath(computeNavigationImagePath(pathDir));
MarkupParser parser = new MarkupParser();
parser.setMarkupLanguage(markupLanguageClone);
parser.setBuilder(splittingBuilder);
parser.parse(markupContent);
} finally {
try {
writer.close();
} catch (Exception e) {
throw new BuildException(MessageFormat.format(// $NON-NLS-1$
Messages.getString("WikiToDocTask_cannot_write_output_file"), // $NON-NLS-1$
htmlOutputFile, e.getMessage()), e);
}
}
}
use of org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder in project mylyn.docs by eclipse.
the class MarkupToEclipseHelpMojoTest method embeddedTableOfContents.
@Test
public void embeddedTableOfContents() {
HtmlDocumentBuilder builder = mock(HtmlDocumentBuilder.class);
SplitOutlineItem item = mock(SplitOutlineItem.class);
File htmlOutputFile = mock(File.class);
SplittingHtmlDocumentBuilder splittingBuilder = markupToEclipseHelp.createSplittingBuilder(builder, item, htmlOutputFile, "");
assertFalse(splittingBuilder.isEmbeddedTableOfContents());
markupToEclipseHelp.embeddedTableOfContents = true;
splittingBuilder = markupToEclipseHelp.createSplittingBuilder(builder, item, htmlOutputFile, "");
assertTrue(splittingBuilder.isEmbeddedTableOfContents());
}
use of org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder in project mylyn.docs by eclipse.
the class MarkupToEclipseHelpMojoTest method assertNavigationImagesPath.
private void assertNavigationImagesPath(String expected, String relativePath) {
HtmlDocumentBuilder builder = mock(HtmlDocumentBuilder.class);
SplitOutlineItem item = mock(SplitOutlineItem.class);
SplittingHtmlDocumentBuilder splittingBuilder = markupToEclipseHelp.createSplittingBuilder(builder, item, mock(File.class), relativePath);
assertEquals(expected, splittingBuilder.getNavigationImagePath());
}
use of org.eclipse.mylyn.wikitext.splitter.SplittingHtmlDocumentBuilder in project mylyn.docs by eclipse.
the class MarkupToEclipseHelpMojo method createSplittingBuilder.
protected SplittingHtmlDocumentBuilder createSplittingBuilder(HtmlDocumentBuilder builder, SplitOutlineItem item, File htmlOutputFile, String relativePath) {
SplittingHtmlDocumentBuilder splittingBuilder = new SplittingHtmlDocumentBuilder();
splittingBuilder.setRootBuilder(builder);
splittingBuilder.setOutline(item);
splittingBuilder.setEmbeddedTableOfContents(embeddedTableOfContents);
splittingBuilder.setRootFile(htmlOutputFile);
splittingBuilder.setNavigationImages(navigationImages);
splittingBuilder.setNavigationImagePath(computeResourcePath(splittingBuilder.getNavigationImagePath(), relativePath));
splittingBuilder.setFormatting(formatOutput);
return splittingBuilder;
}
Aggregations