File tree 1 file changed +24
-8
lines changed
src/main/java/com/jcabi/xml
1 file changed +24
-8
lines changed Original file line number Diff line number Diff line change @@ -188,18 +188,34 @@ private static Iterable<String> print(
188
188
final Collection <SAXParseException > errors ) {
189
189
final Collection <String > lines = new ArrayList <>(errors .size ());
190
190
for (final SAXParseException error : errors ) {
191
- lines .add (
192
- String .format (
193
- "%d:%d: %s" ,
194
- error .getLineNumber (),
195
- error .getColumnNumber (),
196
- error .getMessage ()
197
- )
198
- );
191
+ lines .add (StrictXML .asMessage (error ));
199
192
}
200
193
return lines ;
201
194
}
202
195
196
+ /**
197
+ * Turn violation into a message.
198
+ * @param violation The violation
199
+ * @return The message
200
+ */
201
+ private static String asMessage (final SAXParseException violation ) {
202
+ final StringBuilder msg = new StringBuilder (100 );
203
+ if (violation .getLineNumber () >= 0 ) {
204
+ msg .append ('#' ).append (violation .getLineNumber ());
205
+ if (violation .getColumnNumber () >= 0 ) {
206
+ msg .append (':' ).append (violation .getColumnNumber ());
207
+ }
208
+ msg .append (' ' );
209
+ }
210
+ msg .append (violation .getLocalizedMessage ());
211
+ if (violation .getException () != null ) {
212
+ msg .append (" (" )
213
+ .append (violation .getException ().getClass ().getSimpleName ())
214
+ .append (')' );
215
+ }
216
+ return msg .toString ();
217
+ }
218
+
203
219
/**
204
220
* Joins many objects' string representations with the given separator
205
221
* string. The separator will not be appended to the beginning or the end.
You can’t perform that action at this time.
0 commit comments