public class StandardErrorListener extends StandardDiagnostics implements javax.xml.transform.ErrorListener
| Modifier and Type | Field and Description |
|---|---|
protected Logger |
logger |
MAX_MESSAGE_LENGTH, MAX_MESSAGE_LINE_LENGTH, MIN_MESSAGE_LINE_LENGTH, TARGET_MESSAGE_LINE_LENGTH| Constructor and Description |
|---|
StandardErrorListener()
Create a Standard Error Listener
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
constructFirstLine(javax.xml.transform.TransformerException exception,
XPathException xe,
java.lang.String langText,
java.lang.String kind)
Construct the first line of the error or warning message.
|
java.lang.String |
constructMessage(javax.xml.transform.TransformerException exception,
XPathException xe,
java.lang.String langText,
java.lang.String kind)
Construct an error or warning message.
|
java.lang.String |
constructSecondLine(javax.xml.transform.TransformerException err,
XPathException xe)
Construct the second line of the error message.
|
void |
error(javax.xml.transform.TransformerException exception)
Receive notification of a recoverable error.
|
java.lang.CharSequence |
expandSpecialCharacters(java.lang.CharSequence in)
Expand any special characters appearing in a message.
|
void |
fatalError(javax.xml.transform.TransformerException exception)
Receive notification of a non-recoverable error.
|
java.lang.String |
formatErrorCode(javax.xml.transform.TransformerException err)
Format the error code contained in the supplied exception object
|
java.lang.String |
formatErrorObject(Sequence errorObject)
Get a string representation of the error object associated with the exception (this represents
the final argument to fn:error, in the case of error triggered by calls on the fn:error function).
|
java.lang.String |
formatExtraContext(Expression failingExpression,
java.lang.String nearBy)
Create extra context information for locating the error from knowledge of the
containing expression or the nearby text retained by the tokenizer
|
java.lang.String |
formatNestedMessages(javax.xml.transform.TransformerException err,
java.lang.String message)
Construct a message by combining the message from the top-level exception
plus any messages associated with nested exceptions
|
java.lang.String |
getExpandedMessage(javax.xml.transform.TransformerException err)
Get a string containing the message for this exception and all contained exceptions.
|
java.lang.String |
getLocationMessage(javax.xml.transform.TransformerException err)
Get a string identifying the location of an error.
|
Logger |
getLogger()
Get the error output stream
|
int |
getMaximumNumberOfWarnings()
Get the maximum number of warnings that are reported; further warnings after this limit
are silently ignored
|
int |
getMaxOrdinaryCharacter(int max)
Set the maximum codepoint value for a character to be considered non-special.
|
int |
getStackTraceDetail()
Get the level of information to be included in a stack trace when a dynamic
error occurs.
|
boolean |
isReportingWarnings()
Ask whether the error listener is reporting warnings.
|
StandardErrorListener |
makeAnother(HostLanguage hostLanguage)
Make a clean copy of this ErrorListener.
|
protected void |
outputStackTrace(Logger out,
XPathContext context)
Generate a stack trace for a dynamic error.
|
void |
setLogger(Logger logger)
Set output destination for error messages (default is System.err)
|
void |
setMaximumNumberOfWarnings(int max)
Set the maximum number of warnings that are reported; further warnings after this limit
are silently ignored
|
void |
setMaxOrdinaryCharacter(int max)
Set the maximum codepoint value for a character to be considered non-special.
|
void |
setStackTraceDetail(int level)
Set the level of information to be included in a stack trace when a dynamic
error occurs.
|
void |
warning(javax.xml.transform.TransformerException exception)
Receive notification of a warning.
|
abbreviateLocationURI, abbreviateLocationURIDefault, expandSpecialCharacters, formatListOfOffendingNodes, getInstructionName, getInstructionNameDefault, getLocationMessageText, printStackTrace, showOriginator, wordWrapprotected transient Logger logger
public StandardErrorListener()
public StandardErrorListener makeAnother(HostLanguage hostLanguage)
hostLanguage - the host language (not used by this implementation)public void setLogger(Logger logger)
logger - The Logger to use for error messagespublic Logger getLogger()
public void setMaximumNumberOfWarnings(int max)
max - the maximum number of warnings outputpublic int getMaximumNumberOfWarnings()
public void setStackTraceDetail(int level)
level - set to 0 (zero) for no stack trace; 1 (one) for a stack trace
showing the templates and functions being executed; 2 (two) to
add values of local variables and parameters (available in Saxon-EE only)
Default is the maximum level available.public int getStackTraceDetail()
public void setMaxOrdinaryCharacter(int max)
max - the highest codepoint considered non-special (defaults to 255)public int getMaxOrdinaryCharacter(int max)
max - the highest codepoint considered non-special (defaults to 255)public void warning(javax.xml.transform.TransformerException exception)
Transformers can use this method to report conditions that are not errors or fatal errors. The default behaviour is to take no action.
After invoking this method, the Transformer must continue with the transformation. It should still be possible for the application to process the document through to the end.
warning in interface javax.xml.transform.ErrorListenerexception - The warning information encapsulated in a
transformer exception.TransformerExceptionpublic boolean isReportingWarnings()
public void error(javax.xml.transform.TransformerException exception)
The transformer must continue to provide normal parsing events after invoking this method. It should still be possible for the application to process the document through to the end.
The action of the standard error listener depends on the recovery policy that has been set, which may be one of RECOVER_SILENTLY, RECOVER_WITH_WARNING, or DO_NOT_RECOVER
error in interface javax.xml.transform.ErrorListenerexception - The error information encapsulated in a
transformer exception.TransformerExceptionpublic void fatalError(javax.xml.transform.TransformerException exception)
The application must assume that the transformation cannot continue after the Transformer has invoked this method, and should continue (if at all) only to collect addition error messages. In fact, Transformers are free to stop reporting events once this method has been invoked.
fatalError in interface javax.xml.transform.ErrorListenerexception - The error information encapsulated in a
transformer exception.public java.lang.String constructMessage(javax.xml.transform.TransformerException exception,
XPathException xe,
java.lang.String langText,
java.lang.String kind)
The default implementation outputs a two-line message: the first line is obtained
by calling constructFirstLine(TransformerException, XPathException, String, String),
the second by calling constructSecondLine(TransformerException, XPathException); these are
concatenated with a newline and two spaces separating them.
exception - the exception originally reported to the ErrorListenerxe - the result of converting the exception to an XPathException (possibly null).
This may be the original exception, or an XPathException nested within it.langText - a string such as "in expression" or "in query" identifying the kind of
construct that is in errorkind - the kind of error, for example "Syntax error", "Static error", "Type error"public java.lang.String constructFirstLine(javax.xml.transform.TransformerException exception,
XPathException xe,
java.lang.String langText,
java.lang.String kind)
exception - the exception originally reported to the ErrorListenerxe - the result of converting the exception to an XPathException (possibly null).
This may be the original exception, or an XPathException nested within it.langText - a string such as "in expression" or "in query" identifying the kind of
construct that is in errorkind - the kind of error, for example "Syntax error", "Static error", "Type error"public java.lang.String formatExtraContext(Expression failingExpression, java.lang.String nearBy)
failingExpression - the subexpression in which the failure occurs (possibly null)nearBy - text from the input buffer near the error, retained by the tokenizer
(possible null)public java.lang.String constructSecondLine(javax.xml.transform.TransformerException err,
XPathException xe)
The default implementation depends on the kind of exception:
ValidationException, it constructs a message containing
the error message together with explanations of which XSD Schema constraint
was violated;getExpandedMessage(TransformerException)
and then formatting the result using StandardDiagnostics.wordWrap(String) and expandSpecialCharacters(CharSequence).err - the original reported exceptionprotected void outputStackTrace(Logger out, XPathContext context)
StandardDiagnostics.printStackTrace(XPathContext, Logger, int) supplying as
the third argument the current setting of setStackTraceDetail(int),
which defaults to 2.out - the destination for the stack tracecontext - the context (which holds the information to be output)public java.lang.String getLocationMessage(javax.xml.transform.TransformerException err)
SourceLocator
object from this exception or from any nested exception, and then,
if a SourceLocator is found, calls StandardDiagnostics.getLocationMessageText(SourceLocator)
to format the location information.err - the exception containing the location informationpublic java.lang.String getExpandedMessage(javax.xml.transform.TransformerException err)
The default implementation outputs the concatenation (with space-separation) of:
formatErrorCode(TransformerException)formatErrorObject(Sequence) (whose
default implementation outputs nothing)formatNestedMessages(TransformerException, String) err - the exception containing the required informationpublic java.lang.String formatNestedMessages(javax.xml.transform.TransformerException err,
java.lang.String message)
The default implementation outputs the supplied message, followed by the messages from any nested (contained) exceptions, colon-separated, with some attempt to remove duplicated messages and certain redundant message prefixes (such as "net.sf.saxon.trans.XPathException: " and "TRaX Transform Exception")
err - the original reported exceptionmessage - the message as constructed so far, containing the error code,
error object, and the message from the original reported exceptionpublic java.lang.String formatErrorCode(javax.xml.transform.TransformerException err)
err - the exception object. The default implementation looks for an error
code both in this object (if it is an XPathException) or in
any wrapped XPathException. The default implementation ignores
the namespace part of the error code (which is in general a QName) if it
is the standard namespace NamespaceConstant.ERR; otherwise it displays
the code in the format prefix:localName.public java.lang.String formatErrorObject(Sequence errorObject)
errorObject - the error object passed as the last argument to fn:error. Note: this method is
not called if the error object is absent/nullpublic java.lang.CharSequence expandSpecialCharacters(java.lang.CharSequence in)
setMaxOrdinaryCharacter(int). The default implementation returns
the message unchanged if the registered Logger is unicode-aware.
This method is provided because a number of operating systems cannot display arbitrary Unicode characters on the system console, or cannot do so unless the console has been specially configured. The simplest way to prevent messages being expanded in this way is to mark the logger as being unicode-aware.
If messages are expanded, then they will be expanded using the method
StandardDiagnostics.expandSpecialCharacters(CharSequence, int), which can be overridden
to define the actual format in which special characters are displayed.
in - the message to be expandedCopyright (c) 2004-2021 Saxonica Limited. All rights reserved.