Skip to content

Commit

Permalink
#137 skip line number of negative
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Dec 2, 2024
1 parent 94162ce commit 605fb0d
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions src/main/java/com/yegor256/xsline/StSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,7 @@ private static XML validate(final XML schema, final XML xml) {
if (!violations.isEmpty()) {
final Collection<String> msgs = new ArrayList<>(violations.size());
for (final SAXParseException violation : violations) {
final StringBuilder msg = new StringBuilder()
.append('#')
.append(violation.getLineNumber())
.append(':')
.append(violation.getColumnNumber())
.append(' ')
.append(violation.getLocalizedMessage());
if (violation.getException() != null) {
msg.append(" (")
.append(violation.getException().getClass().getSimpleName())
.append(')');
}
msgs.add(msg.toString());
msgs.add(StSchema.asMessage(violation));
}
if (Logger.isDebugEnabled(StSchema.class)) {
Logger.debug(
Expand All @@ -130,6 +118,29 @@ private static XML validate(final XML schema, final XML xml) {
return xml;
}

/**
* Turn violation into a message.
* @param violation The violation
* @return The message
*/
private static String asMessage(final SAXParseException violation) {
final StringBuilder msg = new StringBuilder(100);
if (violation.getLineNumber() >= 0) {
msg.append('#').append(violation.getLineNumber());
if (violation.getColumnNumber() >= 0) {
msg.append(':').append(violation.getColumnNumber());
}
msg.append(' ');
}
msg.append(violation.getLocalizedMessage());
if (violation.getException() != null) {
msg.append(" (")
.append(violation.getException().getClass().getSimpleName())
.append(')');
}
return msg.toString();
}

/**
* Make XSD safely.
* @param path Path in classpath
Expand Down

0 comments on commit 605fb0d

Please sign in to comment.