protected static String locationOf(XMLElement context) {
if (context == null) {
return "";
}
Location location = context.getLocation();
if (location != null) {
String displayFileName = location.getSystemId();
if (displayFileName == null) {
// We see this in the test cases that don't use actual source files
displayFileName = "Unknown";
} else {
// Parse the system id as a URI, which is almost always is
try {
URI uri = new URI(location.getSystemId());
String path = uri.getPath();
if (path != null) {
displayFileName = path.substring(path.lastIndexOf('/') + 1);
}
} catch (URISyntaxException e) {
// Fall back to the raw system id
}
}
// Log in a way that usually triggers IDE hyperlinks
return " Element " + context.toString() + " (" + displayFileName + ":"
+ location.getLineNumber() + ")";
} else {
/*
* This shouldn't occur unless the XMLElement came from a DOM Node created
* by something other than W3cDocumentBuilder.
*/