Package org.eclipse.birt.core.framework.parser

# Class XMLParserHandler

java.lang.Object
org.xml.sax.helpers.DefaultHandler
org.eclipse.birt.core.framework.parser.XMLParserHandler

All Implemented Interfaces:
  `ContentHandler`, `DTDHandler`, `EntityResolver`, `ErrorHandler`

public abstract class XMLParserHandler extends DefaultHandler
Framework for parsing an XML file using a SAX parser. This framework provides a separate class for each element. These classes are called "state" classes because they represent the state of the parser. Generally, a state represents some object being created. This handler manages the stack of active states, and routes the SAX callbacks to the current state.

See Also:
  - `AbstractParseState`
  - `AnyElementState`
  - `ParseState`
  - `XMLParserException`

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`class`
`XMLParserHandler.InnerAnyTagState`
Parses any valid XML; handles unimplemented tags.
`class`
`XMLParserHandler.InnerParseState`
Base class provides the parse state framework.

## Field Summary

Fields
Modifier and Type
Field
Description
`protected String`
`currentElement`
The current element being parsed.
`protected ArrayList`
`errors`
The list contains errors encountered when parsing a XML file.
`protected Locator`
`locator`
SAX `Locator` for reporting errors.
`protected Stack`
`stateStack`
Stack of active parse states.

## Constructor Summary

Constructors
Constructor
Description
`XMLParserHandler()`
Constructor

## Method Summary

Modifier and Type
Method
Description
`void`
`characters(char[] ch, int start, int length)`
`abstract AbstractParseState`
`createStartState()`
Parser handlers must implement this method to return the "start state": the state that will recognize the top-level element(s) in the XML file.
`void`
`endDocument()`
`void`
`endElement(String namespaceURI, String localName, String qName)`
Ends the parse state for an element.
`void`
`error(SAXParseException e)`
`void`
`fatalError(SAXParseException e)`
`List`
`getErrors()`
Returns the error list when parsing xml file.
`protected void`
`pushState(AbstractParseState state)`
Private method to add a parse state to the state stack.
`void`
`semanticError(Exception e)`
Add a recoverable semantic error to the error list.
`abstract void`
`semanticError(XMLParserException e)`
Add a recoverable semantic error to the error list.
`void`
`setDocumentLocator(Locator theLocator)`
`void`
`startDocument()`
`void`
`startElement(String namespaceURI, String localName, String qName, Attributes atts)`
Starts an XML element.
`protected AbstractParseState`
`topState()`
Private method to return the top of the state stack.
`void`
`warning(SAXParseException e)`

### Methods inherited from class org.xml.sax.helpers.DefaultHandler

`endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, skippedEntity, startPrefixMapping, unparsedEntityDecl`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.xml.sax.ContentHandler

`declaration`

## Field Details

### currentElement

protected String currentElement
The current element being parsed.

### stateStack

protected Stack stateStack
Stack of active parse states. Corresponds to the stack of currently active elements.

### locator

protected Locator locator
SAX `Locator` for reporting errors.

### errors

protected ArrayList errors
The list contains errors encountered when parsing a XML file.

## Constructor Details

### XMLParserHandler

public XMLParserHandler()
Constructor

## Method Details

### startDocument

public void startDocument() throws SAXException

Specified by:
  `startDocument` in interface `ContentHandler`
Overrides:
  `startDocument` in class `DefaultHandler`
Throws:
  `SAXException`

### endDocument

public void endDocument() throws SAXException

Specified by:
  `endDocument` in interface `ContentHandler`
Overrides:
  `endDocument` in class `DefaultHandler`
Throws:
  `SAXException`

### semanticError

public void semanticError(Exception e)
Add a recoverable semantic error to the error list.

Parameters:
  `e` - The exception to log.

### semanticError

public abstract void semanticError(XMLParserException e)
Add a recoverable semantic error to the error list.

Parameters:
  `e` - The exception to log.

### pushState

protected void pushState(AbstractParseState state)
Private method to add a parse state to the state stack.

Parameters:
  `state` - the state to push

### topState

protected AbstractParseState topState()
Private method to return the top of the state stack.

Returns:
  the state at the top of the state stack

### startElement

public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException
Starts an XML element. Delegates to the current state the task of creating a new parse state for the new element.

Specified by:
  `startElement` in interface `ContentHandler`
Overrides:
  `startElement` in class `DefaultHandler`
Throws:
  `SAXException`
See Also:
  - `ContentHandler.startElement(String, String, String, Attributes)`

### endElement

public void endElement(String namespaceURI, String localName, String qName) throws SAXException
Ends the parse state for an element.

Specified by:
  `endElement` in interface `ContentHandler`
Overrides:
  `endElement` in class `DefaultHandler`
Throws:
  `SAXException`
See Also:
  - `ContentHandler.endElement(String, String, String)`

### characters

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

Specified by:
  `characters` in interface `ContentHandler`
Overrides:
  `characters` in class `DefaultHandler`
Throws:
  `SAXException`
See Also:
  - `ContentHandler.characters(char[], int, int)`

### createStartState

public abstract AbstractParseState createStartState()
Parser handlers must implement this method to return the "start state": the state that will recognize the top-level element(s) in the XML file.

Returns:
  the start state specific to the derived parser

### setDocumentLocator

public void setDocumentLocator(Locator theLocator)

Specified by:
  `setDocumentLocator` in interface `ContentHandler`
Overrides:
  `setDocumentLocator` in class `DefaultHandler`

### error

public void error(SAXParseException e) throws SAXException

Specified by:
  `error` in interface `ErrorHandler`
Overrides:
  `error` in class `DefaultHandler`
Throws:
  `SAXException`

### warning

public void warning(SAXParseException e) throws SAXException

Specified by:
  `warning` in interface `ErrorHandler`
Overrides:
  `warning` in class `DefaultHandler`
Throws:
  `SAXException`

### fatalError

public void fatalError(SAXParseException e) throws SAXException

Specified by:
  `fatalError` in interface `ErrorHandler`
Overrides:
  `fatalError` in class `DefaultHandler`
Throws:
  `SAXException`

### getErrors

public List getErrors()
Returns the error list when parsing xml file.

Returns:
  the errors