Class XMLErrorReporter
- All Implemented Interfaces:
org.apache.xerces.xni.parser.XMLComponent
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:
- http://apache.org/xml/properties/internal/error-handler
This component can use the following features and properties but they are not required:
- http://apache.org/xml/features/continue-after-fatal-error
INTERNAL:
- Usage of this class is not supported. It may be altered or removed at any time.
- Version:
- $Id: XMLErrorReporter.java 718856 2008-11-19 04:54:03Z mrglavas $
- Author:
- Eric Ye, IBM, Andy Clark, IBM
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final String
Feature identifier: continue after fatal error.protected static final String
Property identifier: error handler.protected boolean
Continue after fatal error feature.protected org.apache.xerces.xni.parser.XMLErrorHandler
Default error handler.protected org.apache.xerces.xni.parser.XMLErrorHandler
Error handler.protected Locale
The locale to be used to format error messages.protected org.apache.xerces.xni.XMLLocator
Document locator.protected Hashtable
Mapping of Message formatters for domains.static final short
Severity: error.static final short
Severity: fatal error.static final short
Severity: warning. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.xerces.xni.parser.XMLErrorHandler
Get the internal XMLErrrorHandler.boolean
getFeature
(String featureId) 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.Gets the current locale.getMessageFormatter
(String domain) Returns the message formatter associated with the specified domain, or null if no message formatter is registered for that domain.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.String[]
Returns a list of feature identifiers that are recognized by this component.String[]
Returns a list of property identifiers that are recognized by this component.Gets the internal XMLErrorHandler as SAX ErrorHandler.void
putMessageFormatter
(String domain, MessageFormatter messageFormatter) Registers a message formatter for the specified domain.removeMessageFormatter
(String domain) Removes the message formatter for the specified domain and returns the removed message formatter.reportError
(String domain, String key, Object[] arguments, short severity) Reports an error.reportError
(String domain, String key, Object[] arguments, short severity, Exception exception) Reports an error.reportError
(org.apache.xerces.xni.XMLLocator location, String domain, String key, Object[] arguments, short severity) Reports an error at a specific location.reportError
(org.apache.xerces.xni.XMLLocator location, String domain, String key, Object[] arguments, short severity, Exception exception) Reports an error at a specific location.void
reset
(org.apache.xerces.xni.parser.XMLComponentManager componentManager) Resets the component.void
setDocumentLocator
(org.apache.xerces.xni.XMLLocator locator) Sets the document locator.void
setFeature
(String featureId, boolean state) Sets the state of a feature.void
Sets the current locale.void
setProperty
(String propertyId, Object value) Sets the value of a property.
-
Field Details
-
SEVERITY_WARNING
public static final short SEVERITY_WARNINGSeverity: 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.- See Also:
-
SEVERITY_ERROR
public static final short SEVERITY_ERRORSeverity: 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.- See Also:
-
SEVERITY_FATAL_ERROR
public static final short SEVERITY_FATAL_ERRORSeverity: 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.
- See Also:
-
CONTINUE_AFTER_FATAL_ERROR
Feature identifier: continue after fatal error.- See Also:
-
ERROR_HANDLER
Property identifier: error handler.- See Also:
-
fLocale
The locale to be used to format error messages. -
fMessageFormatters
Mapping of Message formatters for domains. -
fErrorHandler
protected org.apache.xerces.xni.parser.XMLErrorHandler fErrorHandlerError handler. -
fLocator
protected org.apache.xerces.xni.XMLLocator fLocatorDocument locator. -
fContinueAfterFatalError
protected boolean fContinueAfterFatalErrorContinue after fatal error feature. -
fDefaultErrorHandler
protected org.apache.xerces.xni.parser.XMLErrorHandler fDefaultErrorHandlerDefault 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.
-
-
Constructor Details
-
XMLErrorReporter
public XMLErrorReporter()Constructs an error reporter with a locator.
-
-
Method Details
-
setLocale
Sets the current locale.- Parameters:
locale
- The new locale.
-
getLocale
Gets the current locale.- Returns:
- the current Locale
-
setDocumentLocator
public void setDocumentLocator(org.apache.xerces.xni.XMLLocator locator) Sets the document locator.- Parameters:
locator
- The locator.
-
putMessageFormatter
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
-
-
getMessageFormatter
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.
-
removeMessageFormatter
Removes the message formatter for the specified domain and returns the removed message formatter.- Parameters:
domain
- The domain of the message formatter.
-
reportError
public String reportError(String domain, String key, Object[] arguments, short severity) throws org.apache.xerces.xni.XNIException 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.- Returns:
- The formatted error message.
- Throws:
org.apache.xerces.xni.XNIException
- See Also:
-
reportError
public String reportError(String domain, String key, Object[] arguments, short severity, Exception exception) throws org.apache.xerces.xni.XNIException 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.exception
- The exception to wrap.- Returns:
- The formatted error message.
- Throws:
org.apache.xerces.xni.XNIException
- See Also:
-
reportError
public String reportError(org.apache.xerces.xni.XMLLocator location, String domain, String key, Object[] arguments, short severity) throws org.apache.xerces.xni.XNIException 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.- Returns:
- The formatted error message.
- Throws:
org.apache.xerces.xni.XNIException
- See Also:
-
reportError
public String reportError(org.apache.xerces.xni.XMLLocator location, String domain, String key, Object[] arguments, short severity, Exception exception) throws org.apache.xerces.xni.XNIException 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.exception
- The exception to wrap.- Returns:
- The formatted error message.
- Throws:
org.apache.xerces.xni.XNIException
- See Also:
-
reset
public void reset(org.apache.xerces.xni.parser.XMLComponentManager componentManager) throws org.apache.xerces.xni.XNIException Resets the component. The component can query the component manager about any features and properties that affect the operation of the component.- Specified by:
reset
in interfaceorg.apache.xerces.xni.parser.XMLComponent
- Parameters:
componentManager
- The component manager.
-
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.- Specified by:
getRecognizedFeatures
in interfaceorg.apache.xerces.xni.parser.XMLComponent
-
setFeature
public void setFeature(String featureId, boolean state) throws org.apache.xerces.xni.parser.XMLConfigurationException 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.
- Specified by:
setFeature
in interfaceorg.apache.xerces.xni.parser.XMLComponent
- Parameters:
featureId
- The feature identifier.state
- The state of the feature.
-
getFeature
public boolean getFeature(String featureId) throws org.apache.xerces.xni.parser.XMLConfigurationException - Throws:
org.apache.xerces.xni.parser.XMLConfigurationException
-
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.- Specified by:
getRecognizedProperties
in interfaceorg.apache.xerces.xni.parser.XMLComponent
-
setProperty
public void setProperty(String propertyId, Object value) throws org.apache.xerces.xni.parser.XMLConfigurationException 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.
- Specified by:
setProperty
in interfaceorg.apache.xerces.xni.parser.XMLComponent
- Parameters:
propertyId
- The property identifier.value
- The value of the property.
-
getFeatureDefault
Returns the default state for a feature, or null if this component does not want to report a default value for this feature.- Specified by:
getFeatureDefault
in interfaceorg.apache.xerces.xni.parser.XMLComponent
- Parameters:
featureId
- The feature identifier.- Since:
- Xerces 2.2.0
-
getPropertyDefault
Returns the default state for a property, or null if this component does not want to report a default value for this property.- Specified by:
getPropertyDefault
in interfaceorg.apache.xerces.xni.parser.XMLComponent
- Parameters:
propertyId
- The property identifier.- Since:
- Xerces 2.2.0
-
getErrorHandler
public org.apache.xerces.xni.parser.XMLErrorHandler getErrorHandler()Get the internal XMLErrrorHandler. -
getSAXErrorHandler
Gets the internal XMLErrorHandler as SAX ErrorHandler.
-