Class StandardDiagnostics
- java.lang.Object
-
- net.sf.saxon.lib.StandardDiagnostics
-
- Direct Known Subclasses:
AbstractTraceListener,StandardErrorListener,StandardErrorReporter,StandardInvalidityHandler
public class StandardDiagnostics extends java.lang.ObjectThis class is an abstract superclass of classes such as theStandardErrorListenerandStandardInvalidityHandler, and exists to provide common utility methods for these classes, and for similar user-written classes if required
-
-
Field Summary
Fields Modifier and Type Field Description intMAX_MESSAGE_LENGTHVariable defining an absolute limit on the length of an error message; any message longer than this will be truncated by thewordWrap(String)method.intMAX_MESSAGE_LINE_LENGTHVariable defining a threshold for word-wrapping a message.intMIN_MESSAGE_LINE_LENGTHVariable defining a minimum length for parts of a word-wrapped a message.intTARGET_MESSAGE_LINE_LENGTHVariable defining a target line length for messages.
-
Constructor Summary
Constructors Constructor Description StandardDiagnostics()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringabbreviateLocationURI(java.lang.String uri)Abbreviate a URI for use in diagnostics.static java.lang.StringabbreviateLocationURIDefault(java.lang.String uri)Abbreviate a URI for use in diagnostics.java.lang.CharSequenceexpandSpecialCharacters(java.lang.CharSequence in, int threshold)Expand any special characters appearing in a message.protected java.lang.StringformatListOfOffendingNodes(ValidationFailure failure)AValidationFailurerelating to a failing assertion contains a (possibly empty) list of nodes responsible for the failure.java.lang.StringgetInstructionName(Instruction inst)Extract a name or phrase identifying the instruction at which an error occurred.static java.lang.StringgetInstructionNameDefault(Instruction inst)Extract a name or phrase identifying the instruction at which an error occurred.java.lang.StringgetLocationMessageText(javax.xml.transform.SourceLocator loc)Construct a message identifying the location of an errorvoidprintStackTrace(XPathContext context, Logger out, int level)Print a stack trace to a specified output destinationprotected java.lang.StringshowOriginator(ContextOriginator originator)Produce text identifying a construct that originates the context for an errorjava.lang.StringwordWrap(java.lang.String message)Wordwrap an error message into lines ofTARGET_MESSAGE_LINE_LENGTHcharacters or less (if possible).
-
-
-
Field Detail
-
MAX_MESSAGE_LENGTH
public 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 thewordWrap(String)method. The value can be assigned. Default value is 1000.
-
MAX_MESSAGE_LINE_LENGTH
public int MAX_MESSAGE_LINE_LENGTH
Variable defining a threshold for word-wrapping a message. If a message is longer than this, then thewordWrap(String)method will attempt to break it into shorter lines. The value can be assigned. Default value is 100.
-
MIN_MESSAGE_LINE_LENGTH
public int MIN_MESSAGE_LINE_LENGTH
Variable defining a minimum length for parts of a word-wrapped a message. ThewordWrap(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.
-
TARGET_MESSAGE_LINE_LENGTH
public int TARGET_MESSAGE_LINE_LENGTH
Variable defining a target line length for messages. If word-wrapping takes place, then it will take place at the last space character found before this column position. The value can be assigned. Default value is 90.
-
-
Method Detail
-
getLocationMessageText
public java.lang.String getLocationMessageText(javax.xml.transform.SourceLocator loc)
Construct a message identifying the location of an error- Parameters:
loc- the location of the error- Returns:
- a message describing the location
-
getInstructionName
public java.lang.String getInstructionName(Instruction inst)
Extract a name or phrase identifying the instruction at which an error occurred. This default implementation invokes the static methodgetInstructionNameDefault(Instruction).- Parameters:
inst- the instruction in question- Returns:
- the name or description of the instruction, in user-meaningful terms
-
getInstructionNameDefault
public static java.lang.String getInstructionNameDefault(Instruction inst)
Extract a name or phrase identifying the instruction at which an error occurred. This default implementation uses terminology that is neutral between XQuery and XSLT, for example "text node constructor" in preference to "xsl:text".- Parameters:
inst- the instruction in question- Returns:
- the name or description of the instruction, in user-meaningful terms
-
printStackTrace
public void printStackTrace(XPathContext context, Logger out, int level)
Print a stack trace to a specified output destination- Parameters:
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 variables
-
showOriginator
protected java.lang.String showOriginator(ContextOriginator originator)
Produce text identifying a construct that originates the context for an error- Parameters:
originator- theContextOriginatorresponsible for creating a new context- Returns:
- message text (suitable for use in a phrase such as "called by XXX") for inclusion in an error message.
-
formatListOfOffendingNodes
protected java.lang.String formatListOfOffendingNodes(ValidationFailure failure)
AValidationFailurerelating 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 formevery $x in XX satisfies Pit 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.
- Parameters:
failure- the validation failure being reported.- Returns:
- a string describing the list of nodes contributing to the failure of an assertion.
-
abbreviateLocationURI
public java.lang.String abbreviateLocationURI(java.lang.String uri)
Abbreviate a URI for use in diagnostics.This default implementation invokes the static method
abbreviateLocationURIDefault(String).This method is intended for use only for location URIs, not for namespace URIs.
- Parameters:
uri- the URI to be abbreviated- Returns:
- the abbreviated URI
-
abbreviateLocationURIDefault
public static java.lang.String abbreviateLocationURIDefault(java.lang.String uri)
Abbreviate a URI for use in diagnostics.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.
- Parameters:
uri- the URI to be abbreviated- Returns:
- the abbreviated URI
-
wordWrap
public java.lang.String wordWrap(java.lang.String message)
Wordwrap an error message into lines ofTARGET_MESSAGE_LINE_LENGTHcharacters or less (if possible). Note that existing newlines within the message will be retained.- Parameters:
message- the message to be word-wrapped- Returns:
- the message after applying word-wrapping
-
expandSpecialCharacters
public java.lang.CharSequence expandSpecialCharacters(java.lang.CharSequence in, int threshold)Expand any special characters appearing in a message. In the default implementation, special characters will be output as themselves, followed by a hex codepoint in the form [xHHHHH]: for exampleยง[xA7]- Parameters:
in- the message to be expandedthreshold- the codepoint above which characters are considered special.- Returns:
- the expanded message
-
-