org.cdlib.xtf.util
Class XTFSaxonErrorListener

Object
  extended by XTFSaxonErrorListener
All Implemented Interfaces:
ErrorListener

public class XTFSaxonErrorListener
extends Object
implements ErrorListener

Replacement error listener that redirects Saxon error messages to the standard XTF Trace facility.

Author:
Martin Haye

Field Summary
private static ThreadLocal<ArrayList<String>> threadErrors
           
 
Constructor Summary
XTFSaxonErrorListener()
           
 
Method Summary
static void clearThreadErrors()
          Clear the thread-specific list of Saxon errors that have occurred.
 void error(TransformerException exception)
          Receive notification of a recoverable error.
 void fatalError(TransformerException exception)
          Receive notification of a non-recoverable error.
static String getExpandedMessage(TransformerException err)
          Get a string containing the message for this exception and all contained exceptions
private static String getInstructionName(InstructionInfoProvider inst, XPathContext context)
          Extract a name identifying the instruction at which an error occurred
private static String getLocationMessage(SourceLocator loc, XPathContext context)
           
static String getLocationMessage(TransformerException err)
          Get a string identifying the location of an error.
static String[] getThreadErrors()
          Retrieve an array of the Saxon errors that have occurred in the current thread since the last call to clearThreadErrors()
 void warning(TransformerException exception)
          Receive notification of a warning.
private static String wordWrap(String message)
          Wordwrap an error message into lines of 72 characters or less (if possible)
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

threadErrors

private static ThreadLocal<ArrayList<String>> threadErrors
Constructor Detail

XTFSaxonErrorListener

public XTFSaxonErrorListener()
Method Detail

warning

public void warning(TransformerException exception)
             throws TransformerException
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
Parameters:
exception - The warning information encapsulated in a transformer exception.
Throws:
TransformerException - if the application chooses to discontinue the transformation.
See Also:
TransformerException

error

public void error(TransformerException exception)
           throws TransformerException
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
Parameters:
exception - The error information encapsulated in a transformer exception.
Throws:
TransformerException - if the application chooses to discontinue the transformation.
See Also:
TransformerException

fatalError

public void fatalError(TransformerException exception)
                throws TransformerException
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
Parameters:
exception - The error information encapsulated in a transformer exception.
Throws:
TransformerException - if the application chooses to discontinue the transformation.
See Also:
TransformerException

getLocationMessage

public static String getLocationMessage(TransformerException err)
Get a string identifying the location of an error.


getThreadErrors

public static String[] getThreadErrors()
Retrieve an array of the Saxon errors that have occurred in the current thread since the last call to clearThreadErrors()


clearThreadErrors

public static void clearThreadErrors()
Clear the thread-specific list of Saxon errors that have occurred.


getLocationMessage

private static String getLocationMessage(SourceLocator loc,
                                         XPathContext context)

getExpandedMessage

public static String getExpandedMessage(TransformerException err)
Get a string containing the message for this exception and all contained exceptions


getInstructionName

private static String getInstructionName(InstructionInfoProvider inst,
                                         XPathContext context)
Extract a name identifying the instruction at which an error occurred


wordWrap

private static String wordWrap(String message)
Wordwrap an error message into lines of 72 characters or less (if possible)