Search in sources :

Example 1 with XsltGenerator

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);
        }
    }
}
Also used : XsltGenerator(eu.esdihumboldt.hale.io.xslt.internal.XsltGenerator) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) XmlIndex(eu.esdihumboldt.hale.io.xsd.model.XmlIndex) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) File(java.io.File) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException) XMLStreamException(javax.xml.stream.XMLStreamException)

Aggregations

IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)1 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)1 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)1 XmlIndex (eu.esdihumboldt.hale.io.xsd.model.XmlIndex)1 XsltGenerator (eu.esdihumboldt.hale.io.xslt.internal.XsltGenerator)1 File (java.io.File)1 IOException (java.io.IOException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1