| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.testdriver; |
| 9 |
|
| 10 |
import net.sf.saxon.lib.NamespaceConstant; |
| 11 |
import net.sf.saxon.lib.StandardErrorListener; |
| 12 |
import net.sf.saxon.trans.QuitParsingException; |
| 13 |
import net.sf.saxon.trans.XPathException; |
| 14 |
|
| 15 |
import javax.xml.transform.TransformerException; |
| 16 |
import java.util.HashSet; |
| 17 |
import java.util.Set; |
| 18 |
|
| 19 |
public class ErrorCollector extends StandardErrorListener { |
| 20 |
|
| 21 |
private Set<String> errorCodes = new HashSet<String>(); |
| 22 |
private boolean foundWarnings = false; |
| 23 |
private boolean madeEarlyExit = false; |
| 24 |
|
| 25 |
public TransformerException lastException; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
@Override |
| 41 |
public void warning(TransformerException exception) { |
| 42 |
if (exception instanceof QuitParsingException) { |
| 43 |
System.err.println("** Early exit from parsing"); |
| 44 |
madeEarlyExit = true; |
| 45 |
} else { |
| 46 |
foundWarnings = true; |
| 47 |
} |
| 48 |
super.warning(exception); |
| 49 |
} |
| 50 |
|
| 51 |
@Override |
| 52 |
public void error(TransformerException exception) { |
| 53 |
lastException = exception; |
| 54 |
addErrorCode(exception); |
| 55 |
super.error(exception); |
| 56 |
} |
| 57 |
|
| 58 |
@Override |
| 59 |
public void fatalError(TransformerException exception) { |
| 60 |
addErrorCode(exception); |
| 61 |
super.fatalError(exception); |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
@Override |
| 72 |
public StandardErrorListener makeAnother(int hostLanguage) { |
| 73 |
return this; |
| 74 |
} |
| 75 |
|
| 76 |
private void addErrorCode(TransformerException exception) { |
| 77 |
if (exception instanceof XPathException) { |
| 78 |
String errorCode = ((XPathException) exception).getErrorCodeLocalPart(); |
| 79 |
if (errorCode != null) { |
| 80 |
String ns = ((XPathException) exception).getErrorCodeNamespace(); |
| 81 |
if (ns != null && !NamespaceConstant.ERR.equals(ns)) { |
| 82 |
errorCode = "Q{" + ns + "}" + errorCode; |
| 83 |
} |
| 84 |
errorCodes.add(errorCode); |
| 85 |
} else { |
| 86 |
errorCodes.add("error-with-no-error-code"); |
| 87 |
} |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
public Set<String> getErrorCodes() { |
| 92 |
return errorCodes; |
| 93 |
} |
| 94 |
|
| 95 |
public boolean getFoundWarnings() { |
| 96 |
return foundWarnings; |
| 97 |
} |
| 98 |
|
| 99 |
public boolean isMadeEarlyExit() { |
| 100 |
return madeEarlyExit; |
| 101 |
} |
| 102 |
} |