org.apache.xerces.impl

Class XMLErrorReporter

public class XMLErrorReporter extends Object implements XMLComponent

This class is a common element of all parser configurations and is used to report errors that occur. This component can be queried by parser components from the component manager using the following property ID:
   http://apache.org/xml/properties/internal/error-reporter
 

Errors are separated into domains that categorize a class of errors. In a parser configuration, the parser would register a MessageFormatter for each domain that is capable of localizing error messages and formatting them based on information about the error. Any parser component can invent new error domains and register additional message formatters to localize messages in those domains.

This component requires the following features and properties from the component manager that uses it:

This component can use the following features and properties but they are not required:

INTERNAL:

Usage of this class is not supported. It may be altered or removed at any time.

Version: $Id: XMLErrorReporter.java,v 1.16 2005/06/24 17:56:41 mrglavas Exp $

Author: Eric Ye, IBM Andy Clark, IBM

See Also:

Field Summary
protected static StringCONTINUE_AFTER_FATAL_ERROR
Feature identifier: continue after fatal error.
protected static StringERROR_HANDLER
Property identifier: error handler.
protected booleanfContinueAfterFatalError
Continue after fatal error feature.
protected XMLErrorHandlerfDefaultErrorHandler
Default error handler.
protected XMLErrorHandlerfErrorHandler
Error handler.
protected LocalefLocale
The locale to be used to format error messages.
protected XMLLocatorfLocator
Document locator.
protected HashtablefMessageFormatters
Mapping of Message formatters for domains.
static shortSEVERITY_ERROR
Severity: error.
static shortSEVERITY_FATAL_ERROR
Severity: fatal error.
static shortSEVERITY_WARNING
Severity: warning.
Constructor Summary
XMLErrorReporter()
Constructs an error reporter with a locator.
Method Summary
XMLErrorHandlergetErrorHandler()
Get the internal XMLErrrorHandler.
booleangetFeature(String featureId)
BooleangetFeatureDefault(String featureId)
Returns the default state for a feature, or null if this component does not want to report a default value for this feature.
LocalegetLocale()
Gets the current locale.
MessageFormattergetMessageFormatter(String domain)
Returns the message formatter associated with the specified domain, or null if no message formatter is registered for that domain.
ObjectgetPropertyDefault(String propertyId)
Returns the default state for a property, or null if this component does not want to report a default value for this property.
String[]getRecognizedFeatures()
Returns a list of feature identifiers that are recognized by this component.
String[]getRecognizedProperties()
Returns a list of property identifiers that are recognized by this component.
ErrorHandlergetSAXErrorHandler()
Gets the internal XMLErrorHandler as SAX ErrorHandler.
voidputMessageFormatter(String domain, MessageFormatter messageFormatter)
Registers a message formatter for the specified domain.
MessageFormatterremoveMessageFormatter(String domain)
Removes the message formatter for the specified domain and returns the removed message formatter.
voidreportError(String domain, String key, Object[] arguments, short severity)
Reports an error.
voidreportError(XMLLocator location, String domain, String key, Object[] arguments, short severity)
Reports an error at a specific location.
voidreset(XMLComponentManager componentManager)
Resets the component.
voidsetDocumentLocator(XMLLocator locator)
Sets the document locator.
voidsetFeature(String featureId, boolean state)
Sets the state of a feature.
voidsetLocale(Locale locale)
Sets the current locale.
voidsetProperty(String propertyId, Object value)
Sets the value of a property.

Field Detail

CONTINUE_AFTER_FATAL_ERROR

protected static final String CONTINUE_AFTER_FATAL_ERROR
Feature identifier: continue after fatal error.

ERROR_HANDLER

protected static final String ERROR_HANDLER
Property identifier: error handler.

fContinueAfterFatalError

protected boolean fContinueAfterFatalError
Continue after fatal error feature.

fDefaultErrorHandler

protected XMLErrorHandler fDefaultErrorHandler
Default error handler. This error handler is only used in the absence of a registered error handler so that errors are not "swallowed" silently. This is one of the most common "problems" reported by users of the parser.

fErrorHandler

protected XMLErrorHandler fErrorHandler
Error handler.

fLocale

protected Locale fLocale
The locale to be used to format error messages.

fLocator

protected XMLLocator fLocator
Document locator.

fMessageFormatters

protected Hashtable fMessageFormatters
Mapping of Message formatters for domains.

SEVERITY_ERROR

public static final short SEVERITY_ERROR
Severity: error. Common causes of errors are document structure and/or content that that does not conform to the grammar rules specified for the document. These are typically validation errors.

SEVERITY_FATAL_ERROR

public static final short SEVERITY_FATAL_ERROR
Severity: fatal error. Fatal errors are errors in the syntax of the XML document or invalid byte sequences for a given encoding. The XML 1.0 Specification mandates that errors of this type are not recoverable.

Note: The parser does have a "continue after fatal error" feature but it should be used with extreme caution and care.

SEVERITY_WARNING

public static final short SEVERITY_WARNING
Severity: warning. Warnings represent informational messages only that should not be considered serious enough to stop parsing or indicate an error in the document's validity.

Constructor Detail

XMLErrorReporter

public XMLErrorReporter()
Constructs an error reporter with a locator.

Method Detail

getErrorHandler

public XMLErrorHandler getErrorHandler()
Get the internal XMLErrrorHandler.

getFeature

public boolean getFeature(String featureId)

getFeatureDefault

public Boolean getFeatureDefault(String featureId)
Returns the default state for a feature, or null if this component does not want to report a default value for this feature.

Parameters: featureId The feature identifier.

Since: Xerces 2.2.0

getLocale

public Locale getLocale()
Gets the current locale.

Returns: the current Locale

getMessageFormatter

public MessageFormatter getMessageFormatter(String domain)
Returns the message formatter associated with the specified domain, or null if no message formatter is registered for that domain.

Parameters: domain The domain of the message formatter.

getPropertyDefault

public Object getPropertyDefault(String propertyId)
Returns the default state for a property, or null if this component does not want to report a default value for this property.

Parameters: propertyId The property identifier.

Since: Xerces 2.2.0

getRecognizedFeatures

public String[] getRecognizedFeatures()
Returns a list of feature identifiers that are recognized by this component. This method may return null if no features are recognized by this component.

getRecognizedProperties

public String[] getRecognizedProperties()
Returns a list of property identifiers that are recognized by this component. This method may return null if no properties are recognized by this component.

getSAXErrorHandler

public ErrorHandler getSAXErrorHandler()
Gets the internal XMLErrorHandler as SAX ErrorHandler.

putMessageFormatter

public void putMessageFormatter(String domain, MessageFormatter messageFormatter)
Registers a message formatter for the specified domain.

Note: Registering a message formatter for a domain when there is already a formatter registered will cause the previous formatter to be lost. This method replaces any previously registered message formatter for the specified domain.

Parameters: domain messageFormatter

removeMessageFormatter

public MessageFormatter removeMessageFormatter(String domain)
Removes the message formatter for the specified domain and returns the removed message formatter.

Parameters: domain The domain of the message formatter.

reportError

public void reportError(String domain, String key, Object[] arguments, short severity)
Reports an error. The error message passed to the error handler is formatted for the locale by the message formatter installed for the specified error domain.

Parameters: domain The error domain. key The key of the error message. arguments The replacement arguments for the error message, if needed. severity The severity of the error.

See Also: SEVERITY_WARNING SEVERITY_ERROR SEVERITY_FATAL_ERROR

reportError

public void reportError(XMLLocator location, String domain, String key, Object[] arguments, short severity)
Reports an error at a specific location.

Parameters: location The error location. domain The error domain. key The key of the error message. arguments The replacement arguments for the error message, if needed. severity The severity of the error.

See Also: SEVERITY_WARNING SEVERITY_ERROR SEVERITY_FATAL_ERROR

reset

public void reset(XMLComponentManager componentManager)
Resets the component. The component can query the component manager about any features and properties that affect the operation of the component.

Parameters: componentManager The component manager.

Throws: SAXException Thrown by component on initialization error. For example, if a feature or property is required for the operation of the component, the component manager may throw a SAXNotRecognizedException or a SAXNotSupportedException.

setDocumentLocator

public void setDocumentLocator(XMLLocator locator)
Sets the document locator.

Parameters: locator The locator.

setFeature

public void setFeature(String featureId, boolean state)
Sets the state of a feature. This method is called by the component manager any time after reset when a feature changes state.

Note: Components should silently ignore features that do not affect the operation of the component.

Parameters: featureId The feature identifier. state The state of the feature.

Throws: SAXNotRecognizedException The component should not throw this exception. SAXNotSupportedException The component should not throw this exception.

setLocale

public void setLocale(Locale locale)
Sets the current locale.

Parameters: locale The new locale.

setProperty

public void setProperty(String propertyId, Object value)
Sets the value of a property. This method is called by the component manager any time after reset when a property changes value.

Note: Components should silently ignore properties that do not affect the operation of the component.

Parameters: propertyId The property identifier. value The value of the property.

Throws: SAXNotRecognizedException The component should not throw this exception. SAXNotSupportedException The component should not throw this exception.

Copyright B) 1999-2005 Apache XML Project. All Rights Reserved.