diff --git a/src/main/java/com/yegor256/xsline/StSchema.java b/src/main/java/com/yegor256/xsline/StSchema.java index 4fd3acd..ac54926 100644 --- a/src/main/java/com/yegor256/xsline/StSchema.java +++ b/src/main/java/com/yegor256/xsline/StSchema.java @@ -97,19 +97,7 @@ private static XML validate(final XML schema, final XML xml) { if (!violations.isEmpty()) { final Collection 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( @@ -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