public class StandardDiagnostics
extends java.lang.Object
StandardErrorListener
and StandardInvalidityHandler
, and exists to provide common utility methods for these
classes, and for similar user-written classes if requiredModifier and Type | Field and Description |
---|---|
int |
MAX_MESSAGE_LENGTH
Variable defining an absolute limit on the length of an error message;
any message longer than this will be truncated by the
wordWrap(String)
method. |
int |
MAX_MESSAGE_LINE_LENGTH
Variable defining a threshold for word-wrapping a message.
|
int |
MIN_MESSAGE_LINE_LENGTH
Variable defining a minimum length for parts of a word-wrapped a message.
|
int |
TARGET_MESSAGE_LINE_LENGTH
Variable defining a target line length for messages.
|
Constructor and Description |
---|
StandardDiagnostics() |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
abbreviateLocationURI(java.lang.String uri)
Abbreviate a URI for use in diagnostics.
|
static java.lang.String |
abbreviateLocationURIDefault(java.lang.String uri)
Abbreviate a URI for use in diagnostics.
|
java.lang.String |
expandSpecialCharacters(java.lang.String in,
int threshold)
Expand any special characters appearing in a message.
|
protected java.lang.String |
formatListOfOffendingNodes(ValidationFailure failure)
A
ValidationFailure relating to a failing assertion contains a (possibly empty)
list of nodes responsible for the failure. |
java.lang.String |
getInstructionName(Instruction inst)
Extract a name or phrase identifying the instruction at which an error occurred.
|
static java.lang.String |
getInstructionNameDefault(Instruction inst)
Extract a name or phrase identifying the instruction at which an error occurred.
|
java.lang.String |
getLocationMessageText(javax.xml.transform.SourceLocator loc)
Construct a message identifying the location of an error
|
void |
logStackTrace(XPathContext context,
Logger out,
int level)
Print a stack trace to a specified output destination
|
protected java.lang.String |
showOriginator(ContextOriginator originator)
Produce text identifying a construct that originates the context for an error
|
java.lang.String |
wordWrap(java.lang.String message)
Wordwrap an error message into lines of
TARGET_MESSAGE_LINE_LENGTH
characters or less (if possible). |
public int MAX_MESSAGE_LENGTH
wordWrap(String)
method. The value can be assigned. Default value is 2000.public int MAX_MESSAGE_LINE_LENGTH
wordWrap(String)
method will attempt
to break it into shorter lines. The value can be assigned. Default value is 100.public int MIN_MESSAGE_LINE_LENGTH
wordWrap(String)
method will not split a message line if it would result
in a line shorter than this. The value can be assigned. Default value is 10.public int TARGET_MESSAGE_LINE_LENGTH
public java.lang.String getLocationMessageText(javax.xml.transform.SourceLocator loc)
loc
- the location of the errorpublic java.lang.String getInstructionName(Instruction inst)
getInstructionNameDefault(Instruction)
.inst
- the instruction in questionpublic static java.lang.String getInstructionNameDefault(Instruction inst)
inst
- the instruction in questionpublic void logStackTrace(XPathContext context, Logger out, int level)
context
- the XPath dynamic execution context (which holds the head of a linked
list of context objects, representing the execution stack)out
- the print stream to which the stack trace will be outputlevel
- the level of detail: 0=none, 1=name and location of function/template,
2=values of variablesprotected java.lang.String showOriginator(ContextOriginator originator)
originator
- the ContextOriginator
responsible for creating a new
contextprotected java.lang.String formatListOfOffendingNodes(ValidationFailure failure)
ValidationFailure
relating to a failing assertion contains a (possibly empty)
list of nodes responsible for the failure. This may be the node to which the assertion
applies, or in the case of an assertion in the form every $x in XX satisfies P
it may be the node in XX for which P was not satisfied. This method converts this list
of nodes into a string suitable for inclusion in error messages, typically as a complete
sentence. If the list of nodes is empty, the returned string should normally be empty.
The default implementation displays a message over several lines, starting with "Nodes for which the assertion fails:", and continuing with one line per node. In the typical case where the nodes are elements, subsequent lines will take the form "element(N) on line L column C of file.xml" if the location is not, or "at x/y/z" (where x/y/z is a path to the node) otherwise.
The method is provided so that it can be overridden in a subclass.
failure
- the validation failure being reported.public java.lang.String abbreviateLocationURI(java.lang.String uri)
This default implementation invokes the static method abbreviateLocationURIDefault(String)
.
This method is intended for use only for location URIs, not for namespace URIs.
uri
- the URI to be abbreviatedpublic static java.lang.String abbreviateLocationURIDefault(java.lang.String uri)
This default implementation displays the part of the URI after the last slash.
This method is intended for use only for location URIs, not for namespace URIs.
uri
- the URI to be abbreviatedpublic java.lang.String wordWrap(java.lang.String message)
TARGET_MESSAGE_LINE_LENGTH
characters or less (if possible). Note that existing newlines within the message
will be retained.message
- the message to be word-wrappedpublic java.lang.String expandSpecialCharacters(java.lang.String in, int threshold)
ยง[xA7]
in
- the message to be expandedthreshold
- the codepoint above which characters are considered special.Copyright (c) 2004-2022 Saxonica Limited. All rights reserved.