private void convertBelToXbel(final File inputFile,
final OutputStream output) {
try {
final String belText = FileUtils.readFileToString(inputFile, UTF_8);
final BELParseResults result = BELParser.parse(belText);
// Report any BEL parser warnings or errors if verbose mode is enabled
if (verbose) {
final List<BELParseWarningException> warnings =
result.getSyntaxWarnings();
final List<BELParseErrorException> errors =
result.getSyntaxErrors();
final String inputFilePath = inputFile.getAbsolutePath();
if (hasItems(warnings)) {
final int numWarnings = warnings.size();
reportable.output(format("%d BEL parser warning%s:",
numWarnings, (numWarnings == 1 ? "" : "s")));
int i = 0;
for (BELParseWarningException warning : warnings) {
final ValidationError err = new ValidationError(
inputFilePath,
warning.getMessage(),
warning.getLine(),
warning.getCharacter());
reportable.output(format("%5d. %s", ++i,
err.getUserFacingMessage()));
}
}
if (hasItems(errors)) {
final int numErrors = errors.size();
reportable.output(format("%d BEL parser error%s:",
numErrors, (numErrors == 1 ? "" : "s")));
int i = 0;
for (BELParseErrorException error : errors) {
final ValidationError err = new ValidationError(
inputFilePath,
error.getMessage(),
error.getLine(),
error.getCharacter());
reportable.output(format("%5d. %s", ++i,
err.getUserFacingMessage()));
}
}
}
final Document bel =
new BELDocumentConverter().convert(result.getDocument());
final org.openbel.framework.common.xbel.converters.DocumentConverter converter =
new org.openbel.framework.common.xbel.converters.DocumentConverter();
new XBELConverter().marshal(converter.convert(bel), output);