Class StandardErrorListener

    • Field Detail

      • logger

        protected transient Logger logger
    • Constructor Detail

      • StandardErrorListener

        public StandardErrorListener()
        Create a Standard Error Listener
    • Method Detail

      • makeAnother

        public StandardErrorListener makeAnother​(int hostLanguage)
        Make a clean copy of this ErrorListener. This is necessary because the standard error listener is stateful (it remembers how many errors there have been)
        Parameters:
        hostLanguage - the host language (not used by this implementation)
        Returns:
        a copy of this error listener
      • setLogger

        public void setLogger​(Logger logger)
        Set output destination for error messages (default is System.err)
        Parameters:
        logger - The Logger to use for error messages
      • getLogger

        public Logger getLogger()
        Get the error output stream
        Returns:
        the error output stream
      • getRequestedRecoveryPolicy

        public int getRequestedRecoveryPolicy()
        Get the requested recovery policy. This returns the original policy, which may differ from the current policy, in the case where the current policy has switched from "warnings" to "silent" because too many warnings have been issued
        Returns:
        the original requested recovery policy
      • setMaximumNumberOfWarnings

        public void setMaximumNumberOfWarnings​(int max)
        Set the maximum number of warnings that are reported; further warnings after this limit are silently ignored
        Parameters:
        max - the maximum number of warnings output
      • getMaximumNumberOfWarnings

        public int getMaximumNumberOfWarnings()
        Get the maximum number of warnings that are reported; further warnings after this limit are silently ignored
        Returns:
        the maximum number of warnings output
      • setStackTraceDetail

        public void setStackTraceDetail​(int level)
        Set the level of information to be included in a stack trace when a dynamic error occurs.
        Parameters:
        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.
      • getStackTraceDetail

        public int getStackTraceDetail()
        Get the level of information to be included in a stack trace when a dynamic error occurs.
        Returns:
        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.
      • setMaxOrdinaryCharacter

        public void setMaxOrdinaryCharacter​(int max)
        Set the maximum codepoint value for a character to be considered non-special. Special characters (codepoints above this value) will be expanded in hex for extra clarity in the error message.
        Parameters:
        max - the highest codepoint considered non-special (defaults to 255)
      • getMaxOrdinaryCharacter

        public int getMaxOrdinaryCharacter​(int max)
        Set the maximum codepoint value for a character to be considered non-special. Special characters (codepoints above this value) will be expanded in hex for extra clarity in the error message.
        Parameters:
        max - the highest codepoint considered non-special (defaults to 255)
      • warning

        public void warning​(TransformerException exception)
        Receive notification of a warning.

        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.

        Specified by:
        warning in interface ErrorListener
        Specified by:
        warning in interface UnfailingErrorListener
        Parameters:
        exception - The warning information encapsulated in a transformer exception.
        See Also:
        TransformerException
      • error

        public void error​(TransformerException exception)
        Receive notification of a recoverable error.

        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

        Specified by:
        error in interface ErrorListener
        Specified by:
        error in interface UnfailingErrorListener
        Parameters:
        exception - The error information encapsulated in a transformer exception.
        See Also:
        TransformerException
      • fatalError

        public void fatalError​(TransformerException exception)
        Receive notification of a non-recoverable error.

        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.

        Specified by:
        fatalError in interface ErrorListener
        Specified by:
        fatalError in interface UnfailingErrorListener
        Parameters:
        exception - The error information encapsulated in a transformer exception.
      • outputStackTrace

        protected void outputStackTrace​(Logger out,
                                        XPathContext context)
        Generate a stack trace. This method is protected so it can be overridden in a subclass.
        Parameters:
        out - the destination for the stack trace
        context - the context (which holds the information to be output)
      • getLocationMessage

        public String getLocationMessage​(TransformerException err)
        Get a string identifying the location of an error.
        Parameters:
        err - the exception containing the location information
        Returns:
        a message string describing the location
      • abbreviatePath

        public static String abbreviatePath​(String uri)
        Abbreviate a URI (if requested)
        Parameters:
        uri - the URI to be abbreviated
        Returns:
        the abbreviated URI, unless full path names were requested, in which case the URI as supplied
      • getExpandedMessage

        public String getExpandedMessage​(TransformerException err)
        Get a string containing the message for this exception and all contained exceptions
        Parameters:
        err - the exception containing the required information
        Returns:
        a message that concatenates the message of this exception with its contained exceptions, also including information about the error code and location.
      • getErrorObjectString

        public String getErrorObjectString​(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). The standard implementation returns null, meaning that the error object is not displayed; but the method can be overridden in a subclass to create a custom display of the error object, which is then appended to the message text.
        Parameters:
        errorObject - the error object passed as the last argument to fn:error. Note: this method is not called if the error object is absent/null
        Returns:
        a string representation of the error object to be appended to the message, or null if no output of the error object is required
      • getInstructionName

        public static String getInstructionName​(Instruction inst)
        Extract a name identifying the instruction at which an error occurred
        Parameters:
        inst - the provider of information
        Returns:
        the name of the containing instruction or expression, in user-meaningful terms
      • wordWrap

        public static String wordWrap​(String message)
        Wordwrap an error message into lines of 72 characters or less (if possible)
        Parameters:
        message - the message to be word-wrapped
        Returns:
        the message after applying word-wrapping
      • printStackTrace

        public static 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 output
        level - the level of detail: 0=none, 1=name and location of function/template, 2=values of variables
      • expandSpecialCharacters

        public CharSequence expandSpecialCharacters​(CharSequence in)
        Expand any special characters appearing in a message. Special characters will be output as themselves, followed by a hex codepoint in the form [xHHHHH]. Characters are considered special if they have a codepoint above the value set using setMaxOrdinaryCharacter(int)
        Parameters:
        in - the message to be expanded
      • expandSpecialCharacters

        public static CharSequence expandSpecialCharacters​(CharSequence in,
                                                           int threshold)
        Expand any special characters appearing in a message. Special characters will be output as themselves, followed by a hex codepoint in the form [xHHHHH].
        Parameters:
        in - the message to be expanded
        threshold - the codepoint above which characters are considered special.