use of eu.esdihumboldt.hale.io.html.svg.mapping.json.ValueRepresentation in project hale by halestudio.
the class MappingExporter method execute.
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
progress.begin("Generate mapping documentation", ProgressIndicator.UNKNOWN);
// retrieve template URL
URL templateUrl = getClass().getResource("mapping.html");
// generate Json representation
CellJsonExtension ext = new ExtendedCellRepresentation(getAlignment(), getServiceProvider());
ValueRepresentation rep = new JsonValueRepresentation();
StringWriter jsonWriter = new StringWriter();
JsonStreamBuilder json = new JsonStreamBuilder(jsonWriter, true);
Set<Locale> locales = AlignmentJson.alignmentInfoJSON(getAlignment(), json, getServiceProvider(), getProjectInfo(), ext, rep, Locale.getDefault(), getSourceSchema(), getTargetSchema());
// create language binding
String languageJson = getLanguageJson(locales);
// create template binding
Map<String, Object> binding = new HashMap<>();
binding.put("json", jsonWriter.toString());
String title = (getProjectInfo() != null && getProjectInfo().getName() != null) ? getProjectInfo().getName() : "Mapping documentation";
binding.put("title", title);
binding.put("languages", languageJson);
binding.put("halejsVersion", HALEJS_VERSION);
// initialize template engine
GStringTemplateEngine engine = new GStringTemplateEngine();
// bind and write template
try (Writer out = new OutputStreamWriter(getTarget().getOutput(), StandardCharsets.UTF_8)) {
Writable template = engine.createTemplate(templateUrl).make(binding);
template.writeTo(out);
reporter.setSuccess(true);
} catch (Exception e) {
reporter.error(new IOMessageImpl("Error creating mapping documentation", e));
reporter.setSuccess(false);
} finally {
progress.end();
}
return reporter;
}
Aggregations