Search in sources :

Example 31 with IOMessageImpl

use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.

the class AbstractCachedSchemaReaderBase method execute.

@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    if (validCache(cache) && useCache(cache)) {
        reporter.info(new IOMessageImpl("Loading schema from cached result...", null));
        schema = loadFromCache(cache, progress, reporter);
    } else {
        try {
            schema = loadFromSource(progress, reporter);
        } catch (Exception e) {
            reporter.error("Error loading schema from source", e);
            if (reporter.isSuccess()) {
                reporter.setSuccess(false);
            }
        }
        if (provideCache && schema != null && reporter.isSuccess()) {
            try {
                cache = storeInCache(schema);
                reporter.info(new IOMessageImpl("Created cached schema representation", null));
            } catch (Exception e) {
                reporter.error(new IOMessageImpl("Failed to create a representation of the schema for caching", e));
                // invalidate cache
                cache = null;
            }
            cacheUpdate = true;
        }
        if (!reporter.isSuccess() && validCache(cache) && useCacheAsFallback()) {
            schema = loadFromCache(cache, progress, reporter);
        }
    }
    return reporter;
}
Also used : IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException)

Example 32 with IOMessageImpl

use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.

the class HaleSchemaWriter method execute.

@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    progress.begin("Save schema", ProgressIndicator.UNKNOWN);
    try (OutputStream out = getTarget().getOutput()) {
        // create DOM
        NSDOMBuilder builder = SchemaToXml.createBuilder();
        Element root = new SchemaToXml().schemasToXml(builder, getSchemas().getSchemas());
        // configure transformer for serialization
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        // $NON-NLS-1$
        transformer.setOutputProperty(OutputKeys.METHOD, "xml");
        // $NON-NLS-1$
        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
        // TODO configurable?!
        // $NON-NLS-1$
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        // serialize DOM
        DOMSource source = new DOMSource(root);
        StreamResult result = new StreamResult(out);
        transformer.transform(source, result);
        reporter.setSuccess(true);
    } catch (Exception e) {
        reporter.error(new IOMessageImpl(e.getMessage(), e));
        reporter.setSuccess(false);
    } finally {
        progress.end();
    }
    return reporter;
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) NSDOMBuilder(eu.esdihumboldt.util.groovy.xml.NSDOMBuilder) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) OutputStream(java.io.OutputStream) Element(org.w3c.dom.Element) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException)

Example 33 with IOMessageImpl

use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.

the class HaleSchemaReaderJson method execute.

@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    progress.begin("Load schema", ProgressIndicator.UNKNOWN);
    try (InputStream in = getSource().getInput();
        Reader reader = new InputStreamReader(in, getCharset())) {
        Iterable<Schema> schemas = new JsonToSchema(null, new OsgiClassResolver(), reporter).parseSchemas(reader);
        List<Schema> schemaList = StreamSupport.stream(schemas.spliterator(), false).collect(Collectors.toList());
        if (!schemaList.isEmpty()) {
            schema = HaleSchemaUtil.combineSchema(schemaList, reporter);
            reporter.setSuccess(true);
        } else {
            reporter.setSuccess(false);
            reporter.setSummary("No schema definition found");
        }
    } catch (Exception e) {
        reporter.error(new IOMessageImpl(e.getMessage(), e));
        reporter.setSuccess(false);
    } finally {
        progress.end();
    }
    return reporter;
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Schema(eu.esdihumboldt.hale.common.schema.model.Schema) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) AbstractSchemaReader(eu.esdihumboldt.hale.common.schema.io.impl.AbstractSchemaReader) OsgiClassResolver(eu.esdihumboldt.hale.common.schema.model.constraint.factory.OsgiClassResolver) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException)

Example 34 with IOMessageImpl

use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.

the class HaleSchemaWriterJson method execute.

@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    progress.begin("Save schema", ProgressIndicator.UNKNOWN);
    try (OutputStream out = getTarget().getOutput();
        Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8)) {
        // create DOM
        JsonStreamBuilder builder = new JsonStreamBuilder(writer, true);
        new SchemaToJson().schemasToJson(builder, getSchemas().getSchemas(), null);
        reporter.setSuccess(true);
    } catch (Exception e) {
        reporter.error(new IOMessageImpl(e.getMessage(), e));
        reporter.setSuccess(false);
    } finally {
        progress.end();
    }
    return reporter;
}
Also used : JsonStreamBuilder(eu.esdihumboldt.util.groovy.json.JsonStreamBuilder) OutputStream(java.io.OutputStream) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) AbstractSchemaWriter(eu.esdihumboldt.hale.common.schema.io.impl.AbstractSchemaWriter) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException)

Example 35 with IOMessageImpl

use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.

the class SLDStyleWriter method execute.

/**
 * @see AbstractIOProvider#execute(ProgressIndicator, IOReporter)
 */
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    progress.begin("Save styles to SLD", ProgressIndicator.UNKNOWN);
    SLDTransformer trans = new SLDTransformer();
    trans.setIndentation(2);
    OutputStream out = getTarget().getOutput();
    try {
        trans.transform(getStyle(), out);
        reporter.setSuccess(true);
    } catch (Exception e) {
        reporter.error(new IOMessageImpl("Saving the style as SLD failed.", e));
        reporter.setSuccess(false);
    } finally {
        out.close();
        progress.end();
    }
    return reporter;
}
Also used : SLDTransformer(org.geotools.styling.SLDTransformer) OutputStream(java.io.OutputStream) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException)

Aggregations

IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)85 IOException (java.io.IOException)43 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)33 QName (javax.xml.namespace.QName)20 URI (java.net.URI)15 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)14 InputStream (java.io.InputStream)13 File (java.io.File)12 HashMap (java.util.HashMap)11 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)9 FileOutputStream (java.io.FileOutputStream)9 ArrayList (java.util.ArrayList)9 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)8 OutputStream (java.io.OutputStream)8 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)7 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)7 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)6 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)5 PathUpdate (eu.esdihumboldt.hale.common.core.io.PathUpdate)4 Value (eu.esdihumboldt.hale.common.core.io.Value)4