Search in sources :

Example 1 with MappingExportReport

use of eu.esdihumboldt.hale.ui.io.legacy.mappingexport.MappingExportReport in project hale by halestudio.

the class RifMappingExportProvider method export.

/**
 * @see MappingExportProvider#export(Alignment, String, Collection, Collection)
 */
@Override
public MappingExportReport export(Alignment al, String path, Collection<SchemaElement> sourceSchema, Collection<SchemaElement> targetSchema) throws MappingExportException {
    MappingExportReport report = new MappingExportReport();
    try {
        HaleAlignment hal = new HaleAlignment(al, sourceSchema, targetSchema);
        Document document = AlignmentToRifTranslator.getInstance(report).translate(hal);
        DOMSource source = new DOMSource(document);
        File newFile = new File(path);
        OutputStream stream = new FileOutputStream(newFile);
        StreamResult result = new StreamResult(stream);
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transformer = tFactory.newTransformer();
        // $NON-NLS-1$
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        // $NON-NLS-1$ //$NON-NLS-2$
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        transformer.transform(source, result);
    } catch (TranslationException e) {
        throw new MappingExportException(e.getMessage(), e);
    } catch (FileNotFoundException e) {
        throw new MappingExportException(e.getMessage(), e);
    } catch (TransformerException e) {
        throw new MappingExportException(e.getMessage(), e);
    }
    return report;
}
Also used : HaleAlignment(com.onespatial.jrc.tns.oml_to_rif.HaleAlignment) DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) TranslationException(com.onespatial.jrc.tns.oml_to_rif.api.TranslationException) Document(org.w3c.dom.Document) MappingExportReport(eu.esdihumboldt.hale.ui.io.legacy.mappingexport.MappingExportReport) MappingExportException(eu.esdihumboldt.hale.ui.io.legacy.mappingexport.MappingExportException) FileOutputStream(java.io.FileOutputStream) File(java.io.File) TransformerException(javax.xml.transform.TransformerException)

Aggregations

HaleAlignment (com.onespatial.jrc.tns.oml_to_rif.HaleAlignment)1 TranslationException (com.onespatial.jrc.tns.oml_to_rif.api.TranslationException)1 MappingExportException (eu.esdihumboldt.hale.ui.io.legacy.mappingexport.MappingExportException)1 MappingExportReport (eu.esdihumboldt.hale.ui.io.legacy.mappingexport.MappingExportReport)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 Transformer (javax.xml.transform.Transformer)1 TransformerException (javax.xml.transform.TransformerException)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 DOMSource (javax.xml.transform.dom.DOMSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 Document (org.w3c.dom.Document)1