use of org.eclipse.mylyn.wikitext.parser.builder.XslfoDocumentBuilder in project mylyn.docs by eclipse.
the class XslfoDocumentBuilderIntegrationTest method setUp.
@Override
protected void setUp() throws Exception {
out = new StringWriter();
documentBuilder = new XslfoDocumentBuilder(new DefaultXmlStreamWriter(out));
parser = new MarkupParser();
parser.setBuilder(documentBuilder);
}
use of org.eclipse.mylyn.wikitext.parser.builder.XslfoDocumentBuilder in project mylyn.docs by eclipse.
the class MarkupToXslfoTask method processFile.
/**
* process the file
*
* @param baseDir
* @param source
* @return
* @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("MarkupToXslfoTask.7"), source), Project.MSG_VERBOSE);
String markupContent = null;
String name = source.getName();
if (name.lastIndexOf('.') != -1) {
name = name.substring(0, name.lastIndexOf('.'));
}
File outputFile = computeXslfoFile(source, name);
if (targetdir != null) {
outputFile = new File(targetdir, outputFile.getName());
}
if (!outputFile.exists() || overwrite || outputFile.lastModified() < source.lastModified()) {
if (markupContent == null) {
markupContent = readFully(source);
}
performValidation(source, markupContent);
Writer out;
try {
// $NON-NLS-1$
out = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(outputFile)), "utf-8");
} catch (Exception e) {
throw new BuildException(MessageFormat.format(Messages.getString("MarkupToXslfoTask.8"), outputFile, e.getMessage()), // $NON-NLS-1$
e);
}
try {
XslfoDocumentBuilder builder = new XslfoDocumentBuilder(out);
XslfoDocumentBuilder.Configuration configuration = this.configuration.clone();
if (configuration.getTitle() == null) {
configuration.setTitle(name);
}
builder.setConfiguration(configuration);
builder.setBase(source.getParentFile().toURI());
MarkupParser parser = new MarkupParser();
parser.setMarkupLanguage(markupLanguage);
parser.setBuilder(builder);
if (generateBookmarks) {
OutlineItem outline = new OutlineParser(markupLanguage).parse(markupContent);
builder.setOutline(outline);
}
parser.parse(markupContent);
} finally {
try {
out.close();
} catch (Exception e) {
throw new BuildException(MessageFormat.format(// $NON-NLS-1$
Messages.getString("MarkupToXslfoTask.9"), // $NON-NLS-1$
outputFile, e.getMessage()), e);
}
}
}
return markupContent;
}
Aggregations