use of eu.esdihumboldt.hale.io.xslt.internal.XsltGenerator in project hale by halestudio.
the class XsltExport method execute.
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
File templateDir = Files.createTempDir();
progress.begin("Generate XSLT", ProgressIndicator.UNKNOWN);
try {
log.info("Template directory: " + templateDir.getAbsolutePath());
XmlIndex targetIndex = StreamGmlWriter.getXMLIndex(getTargetSchema());
if (targetIndex == null) {
throw new IllegalStateException("Target schema contains no XML schema");
}
XmlIndex sourceIndex = StreamGmlWriter.getXMLIndex(getSourceSchema());
if (sourceIndex == null) {
throw new IllegalStateException("Source schema contains no XML schema");
}
init(sourceIndex, targetIndex);
XmlElement containerElement = StreamGmlWriter.getConfiguredContainerElement(this, targetIndex);
if (containerElement == null) {
throw new IllegalStateException("No target container element specified");
}
XsltGenerator generator = new XsltGenerator(templateDir, getAlignment(), sourceIndex, targetIndex, reporter, progress, containerElement, getSourceContext(), projectInfo) {
@Override
protected void writeContainerIntro(XMLStreamWriter writer, XsltGenerationContext context) throws XMLStreamException, IOException {
XsltExport.this.writeContainerIntro(writer, context);
}
};
return generator.write(getTarget());
} catch (Exception e) {
reporter.error(new IOMessageImpl("XSLT generation failed", e));
reporter.setSuccess(false);
return reporter;
} finally {
progress.end();
try {
FileUtils.deleteDirectory(templateDir);
} catch (Exception e) {
// failure to delete the directory is not fatal
log.warn("Failed to delete temporary directory", e);
}
}
}
Aggregations