public class StandardErrorReporter extends StandardDiagnostics implements ErrorReporter
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 |
---|
StandardErrorReporter()
Create a Standard Error Reporter
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
constructFirstLine(XmlProcessingError error,
java.lang.String langText,
java.lang.String kind)
Construct the first line of the error or warning message.
|
java.lang.String |
constructMessage(XmlProcessingError exception,
java.lang.String langText,
java.lang.String kind)
Construct an error or warning message.
|
java.lang.String |
constructSecondLine(XmlProcessingError err)
Construct the second line of the error message.
|
protected void |
error(XmlProcessingError err)
Receive notification of an error.
|
java.lang.String |
expandSpecialCharacters(java.lang.String in)
Expand any special characters appearing in a message.
|
java.lang.String |
formatErrorCode(XmlProcessingError err)
Format the error code contained in the supplied exception object
|
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(XmlProcessingError 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(XmlProcessingError err)
Get a string containing the message for this exception and all contained exceptions.
|
protected java.lang.String |
getLocationMessage(XmlProcessingError err)
Get a string identifying the location of an error.
|
Logger |
getLogger()
Get the error output stream
|
int |
getMaximumNumberOfErrors()
Get the maximum number of errors that are reported; further errors after this limit
result in the compilation being abandoned
|
int |
getMaximumNumberOfWarnings()
Get the maximum number of warnings that are reported; further warnings after this limit
are silently ignored
|
int |
getMaxOrdinaryCharacter()
Get 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.
|
protected void |
outputStackTrace(Logger out,
XPathContext context)
Generate a stack trace.
|
void |
report(XmlProcessingError processingError)
Report an error or warning
|
void |
setLogger(Logger logger)
Set output destination for error messages (default is System.err)
|
void |
setMaximumNumberOfErrors(int max)
Set the maximum number of errors that are reported; further errors after this limit
result in the compilation being abandoned
|
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 |
setOutputErrorCodes(boolean include)
Say whether error codes should be included in the message.
|
void |
setStackTraceDetail(int level)
Set the level of information to be included in a stack trace when a dynamic
error occurs.
|
protected void |
warning(XmlProcessingError error)
Receive notification of a warning.
|
abbreviateLocationURI, abbreviateLocationURIDefault, expandSpecialCharacters, formatListOfOffendingNodes, getInstructionName, getInstructionNameDefault, getLocationMessageText, logStackTrace, showOriginator, wordWrap
protected transient Logger logger
public StandardErrorReporter()
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 setMaximumNumberOfErrors(int max)
max
- the maximum number of errors output before the compilation is abandonedpublic int getMaximumNumberOfErrors()
public void setMaxOrdinaryCharacter(int max)
max
- the highest codepoint considered non-special (defaults to 255)public int getMaxOrdinaryCharacter()
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 setOutputErrorCodes(boolean include)
include
- if true (the default), then error codes are included in the messagepublic void report(XmlProcessingError processingError)
report
in interface ErrorReporter
processingError
- the error or warning being reportedprotected void warning(XmlProcessingError error)
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.
error
- The warning information encapsulated in a
transformer exception.TransformerException
public boolean isReportingWarnings()
protected void error(XmlProcessingError err)
After calling this method to report a static error, the compiler will normally
continue to detect and report further errors, but the method can abort the
compilation by calling XmlProcessingError.setTerminationMessage(String)
err
- The error information.public java.lang.String constructMessage(XmlProcessingError exception, java.lang.String langText, java.lang.String kind)
The default implementation outputs a two-line message: the first line is obtained
by calling constructFirstLine(XmlProcessingError, String, String)
,
the second by calling constructSecondLine(XmlProcessingError)
; these are
concatenated with a newline and two spaces separating them.
exception
- the exception originally reported to the ErrorListenerlangText
- 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(XmlProcessingError error, java.lang.String langText, java.lang.String kind)
error
- the error originally reported to the ErrorReporterlangText
- 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(XmlProcessingError err)
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(XmlProcessingError)
and then formatting the result using StandardDiagnostics.wordWrap(String)
and expandSpecialCharacters(String)
.err
- the original reported exceptionprotected java.lang.String getLocationMessage(XmlProcessingError 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(XmlProcessingError err)
The default implementation outputs the concatenation (with space-separation) of:
formatErrorCode(XmlProcessingError)
formatNestedMessages(XmlProcessingError, String)
err
- the exception containing the required informationpublic java.lang.String formatNestedMessages(XmlProcessingError 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(XmlProcessingError 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 expandSpecialCharacters(java.lang.String 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(String, int)
, which can be overridden
to define the actual format in which special characters are displayed.
in
- the message to be expandedprotected void outputStackTrace(Logger out, XPathContext context)
out
- the destination for the stack tracecontext
- the context (which holds the information to be output)Copyright (c) 2004-2022 Saxonica Limited. All rights reserved.