public abstract class

DefaultContentHandler

extends DefaultHandler
java.lang.Object
   ↳ org.xml.sax.helpers.DefaultHandler
     ↳ com.microstrategy.utils.xml.DefaultContentHandler
Known Direct Subclasses

Class Overview

This class is used as a default base class for an XML ContentHandler. It provides the following features on top of DefaultHandler:

  • It manages the Locator object (capturing it in the setDocumentLocator(Locator) method). It exposes a getCurrentLineNumber() method to return this information.
  • It can format error messages to include file name and line number information. See generateErrorMessage(String).
  • Allows the subclass to report both validation and internal errors. The validationError(String) method is used to report an error condition that indicates invalid XML. The supplied message is formatted, the validation error count is incremented and the resulting message is sent to the supplied MessageRouter.
  • Validation errors are not immediately fatal--XML parsing continues, though upon completion the overall parse fails. In contrast, a call to internalError(String) formats an error message and packages it into a thrown org.xml.sax.SAXException. Parsing terminates at the point of an internal error.

Summary

Fields
protected Locator locator
protected MessageRouter messageRouter
protected String sourceLocation
protected int validationErrorCount
protected XMLReader xmlReader
Public Constructors
DefaultContentHandler(String sourceLocation, MessageRouter msgRouter)
Default constructor which takes a "location" string (may be null) and a MessageRouter object.
Public Methods
void characters(char[] ch, int start, int length)
Callback to indicate that characters have been found.
void endDocument()
What to do when the end of document is encountered.
void endElement(String uri, String localName, String qName)
Callback to indicate the end of an XML element.
String generateErrorMessage(String message)
Formats an error message supplied by the user.
void ignorableWhitespace(char[] ch, int start, int length)
Callback when ignorable whitespace has been encountered in an XML document.
void incrementValidationErrorCount()
Increment the number of validation errors.
void resetData()
Resets all data structures used in the previous parse operation.
void setDocumentLocator(Locator locator)
Callback method to record the document locator.
void setMessageRouter(MessageRouter messageRouter)
Specifies the Message Router to use for this parse operation.
void setSourceLocation(String sourceLocation)
Specifies the location of the source text being parsed.
void setXMLReader(XMLReader xmlReader)
Sets the XML Reader which is being used to parse the XML text.
void startElement(String uri, String localName, String qName, Attributes attributes)
Callback invoked when a new element is encountered.
Protected Methods
void clearChars()
Resets the characters collected.
String getCharacters()
Returns the last text area that was encountered.
int getCurrentLineNumber()
Returns the current line number (if we can determine it) or -1.
void internalError(String message)
Throws an internal SAXException error formatted with the supplied error message.
void validationError(String message)
Reports a validation error.
[Expand]
Inherited Methods
From class org.xml.sax.helpers.DefaultHandler
From class java.lang.Object
From interface org.xml.sax.ContentHandler
From interface org.xml.sax.DTDHandler
From interface org.xml.sax.EntityResolver
From interface org.xml.sax.ErrorHandler

Fields

protected Locator locator

protected MessageRouter messageRouter

protected String sourceLocation

protected int validationErrorCount

protected XMLReader xmlReader

Public Constructors

public DefaultContentHandler (String sourceLocation, MessageRouter msgRouter)

Default constructor which takes a "location" string (may be null) and a MessageRouter object.

Parameters
sourceLocation The location of the source being parsed.
msgRouter The MessageRouter object to use for reporting errors, warnings.

Public Methods

public void characters (char[] ch, int start, int length)

Callback to indicate that characters have been found.

Parameters
ch The character array.
start The starting index of the character encountered.
length The number of characters seen in this particular callback.
Throws
SAXException If the characters encountered were unexpected or some other internal error.

public void endDocument ()

What to do when the end of document is encountered. By default, it will check whether any validation errors have occurred. If so, it throws an exception.

Throws
SAXException If validation errors have occurred.

public void endElement (String uri, String localName, String qName)

Callback to indicate the end of an XML element.

Parameters
uri The URI of the element.
localName The local name of the element.
qName The qualified name of the element.
Throws
SAXException If an unexpected element was encountered.

public String generateErrorMessage (String message)

Formats an error message supplied by the user. The error message includes file name and line number information.

Parameters
message The underlying message to display
Returns
  • A String containing the full, displayable error message.

public void ignorableWhitespace (char[] ch, int start, int length)

Callback when ignorable whitespace has been encountered in an XML document.

Parameters
ch The character array.
start The starting index of the character encountered.
length The number of characters seen in this particular callback.
Throws
SAXException If the characters encountered were unexpected or some other internal error.

public void incrementValidationErrorCount ()

Increment the number of validation errors. This is only to be used by the org.xml.sax.ErrorHandler object (which reports DTD validation errors).

public void resetData ()

Resets all data structures used in the previous parse operation. This enables the same instance to be used repeatedly for different XML parse operations. After invoking the caller should call the setMessageRouter(MessageRouter) and setSourceLocation(String) methods to establish the new context.

public void setDocumentLocator (Locator locator)

Callback method to record the document locator.

Parameters
locator The Locator object created by the XML Reader.

public void setMessageRouter (MessageRouter messageRouter)

Specifies the Message Router to use for this parse operation.

Parameters
messageRouter The Message Router to use for this parse operation.

public void setSourceLocation (String sourceLocation)

Specifies the location of the source text being parsed.

Parameters
sourceLocation The source location of the text being parsed.

public void setXMLReader (XMLReader xmlReader)

Sets the XML Reader which is being used to parse the XML text.

Parameters
xmlReader The XML Reader which is being used to parse the XML text.

public void startElement (String uri, String localName, String qName, Attributes attributes)

Callback invoked when a new element is encountered.

Parameters
uri The URI of the element.
localName The local name of the element.
qName The qualified name of the element.
attributes The attributes associated with the element.
Throws
SAXException If an unexpected element appears in the configuration file.

Protected Methods

protected void clearChars ()

Resets the characters collected. This is normally done when a new element is started.

protected String getCharacters ()

Returns the last text area that was encountered. This includes all characters encountered between the most previous startElement and invocation of endElement.

Returns
  • The String representation of last text (character) area encountered.

protected int getCurrentLineNumber ()

Returns the current line number (if we can determine it) or -1.

Returns
  • The current line number that we are at in the input stream.

protected void internalError (String message)

Throws an internal SAXException error formatted with the supplied error message.

Parameters
message The message that contains the internal error.
Throws
SAXException This is used to get out of the current SAX parsing call.

protected void validationError (String message)

Reports a validation error. The supplied string is formatted and logged (as an error) with the associated MessageRouter.

Parameters
message The validation error message (used in a call to generateErrorMessage(String)).