use of massbank.RecordParser in project MassBank-web by MassBank.
the class Validator method validate.
/**
* Validate a <code>recordString</code> and return the parsed information in a {@link Record}
* or <code>null</code> if the validation was not successful. Options are given in
* <code>config</code>.
*/
public static Record validate(String recordString, String contributor, Set<String> config) {
Record record = new Record(contributor);
RecordParser recordparser = new RecordParser(record, config);
Result res = recordparser.parse(recordString);
if (res.isFailure()) {
logger.error(res.getMessage());
int position = res.getPosition();
String[] tokens = recordString.split("\\n");
int line = 0, col = 0, offset = 0;
for (String token : tokens) {
offset = offset + token.length() + 1;
if (position < offset) {
col = position - (offset - (token.length() + 1));
logger.error(tokens[line]);
StringBuilder error_at = new StringBuilder(StringUtils.repeat(" ", col));
error_at.append('^');
logger.error(error_at);
break;
}
line++;
}
return null;
}
return record;
}
use of massbank.RecordParser in project MassBank-web by MassBank.
the class Validator2 method validate.
public static Record validate(String recordstring, String contributor) {
// test non standard ASCII chars and print warnings
for (int i = 0; i < recordstring.length(); i++) {
if (recordstring.charAt(i) > 0x7F) {
String[] tokens = recordstring.split("\\r?\\n");
System.out.println("Warning: non standard ASCII charactet found. This might be an error. Please check carefully.");
int line = 0, col = 0, offset = 0;
for (String token : tokens) {
offset = offset + token.length() + 1;
if (i < offset) {
col = i - (offset - (token.length() + 1));
System.out.println(tokens[line]);
StringBuilder error_at = new StringBuilder(StringUtils.repeat(" ", tokens[line].length()));
error_at.setCharAt(col, '^');
System.out.println(error_at);
break;
}
line++;
}
}
}
Record record = new Record(contributor);
Parser recordparser = new RecordParser(record);
Result res = recordparser.parse(recordstring);
if (res.isFailure()) {
System.err.println();
System.err.println(res.getMessage());
int position = res.getPosition();
String[] tokens = recordstring.split("\\n");
int line = 0, col = 0, offset = 0;
for (String token : tokens) {
offset = offset + token.length() + 1;
if (position < offset) {
col = position - (offset - (token.length() + 1));
System.err.println(tokens[line]);
StringBuilder error_at = new StringBuilder(StringUtils.repeat(" ", col));
error_at.append('^');
System.err.println(error_at);
// record = new Record();
break;
}
line++;
}
return null;
} else
return record;
}
Aggregations