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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations