public void error(Throwable exception) {
log.error(exceptionMessage(exception) + exception.getMessage());
}
private String exceptionMessage(Throwable exception) {
StructuredQName qCode = null;
SourceLocator loc = null;
String message = "";
if (exception instanceof XPathException) {
qCode = ((XPathException) exception).getErrorCodeQName();
}
if (exception instanceof TransformerException) {
TransformerException tx = (TransformerException) exception;
if (qCode == null && tx.getException() instanceof XPathException) {
qCode = ((XPathException) tx.getException()).getErrorCodeQName();
}
if (tx.getLocator() != null) {
loc = tx.getLocator();
boolean done = false;
while (!done && loc == null) {
if (tx.getException() instanceof TransformerException) {
tx = (TransformerException) tx.getException();
loc = tx.getLocator();
} else if (exception.getCause() instanceof TransformerException) {
tx = (TransformerException) exception.getCause();
loc = tx.getLocator();
} else {
done = true;
}
}
}
}
if (exception instanceof XProcException) {
XProcException err = (XProcException) exception;
loc = err.getLocator();
if (err.getErrorCode() != null) {
QName n = err.getErrorCode();
qCode = new StructuredQName(n.getPrefix(),n.getNamespaceURI(),n.getLocalName());
}
if (err.getStep() != null) {
message = message + err.getStep() + ":";
}
}
if (loc != null) {
if (loc.getSystemId() != null && !"".equals(loc.getSystemId())) {
message = message + loc.getSystemId() + ":";
}
if (loc.getLineNumber() != -1) {
message = message + loc.getLineNumber() + ":";
}
if (loc.getColumnNumber() != -1) {
message = message + loc.getColumnNumber() + ":";
}
}
if (qCode != null) {
message = message + qCode.getDisplayName() + ":";
}
return message;
}