javanet.staxutils
Class StAXEventContentHandler

java.lang.Object
  extended byorg.xml.sax.helpers.DefaultHandler
      extended byjavanet.staxutils.StAXContentHandler
          extended byjavanet.staxutils.StAXEventContentHandler
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler, LexicalHandler

public class StAXEventContentHandler
extends StAXContentHandler

SAX ContentHandler that writes events to a StAX XMLEventConsumer.

Version:
$Revision: 1.5 $
Author:
Christian Niles

Field Summary
 
Fields inherited from class javanet.staxutils.StAXContentHandler
CDATABuffer, docLocator, isCDATA, namespaces, reporter
 
Constructor Summary
StAXEventContentHandler()
          Constructs a default instance with a default event factory.
StAXEventContentHandler(XMLEventConsumer consumer)
          Constructs an instance that writes events to the provided XMLEventConsumer.
StAXEventContentHandler(XMLEventConsumer consumer, XMLEventFactory factory)
          Constructs an instance that writes events constructed with the provided XMLEventFactory to the provided XMLEventConsumer
 
Method Summary
 void characters(char[] ch, int start, int length)
           
 void comment(char[] ch, int start, int length)
           
protected  Namespace createNamespace(java.lang.String prefix, java.lang.String uri)
           
protected  void createStartEvents(Attributes attributes, java.util.Collection[] events)
          Creates the Namespaceand Attributeevents associated with a StartElement.
 void endCDATA()
           
 void endDocument()
           
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
           
 XMLEventConsumer getEventConsumer()
          Returns a reference to the XMLEventConsumer to which events will be written.
 XMLEventFactory getEventFactory()
          Returns a reference to the XMLEventFactory used to construct events.
 void ignorableWhitespace(char[] ch, int start, int length)
           
 void processingInstruction(java.lang.String target, java.lang.String data)
           
 void setEventConsumer(XMLEventConsumer consumer)
          Sets the XMLEventConsumer to which events are written.
 void setEventFactory(XMLEventFactory factory)
          Sets the XMLEventFactory used to create events.
 void startDocument()
           
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, Attributes attributes)
           
 
Methods inherited from class javanet.staxutils.StAXContentHandler
endDTD, endEntity, endPrefixMapping, error, fatalError, getCurrentLocation, parseQName, reportException, setDocumentLocator, setXMLReporter, startCDATA, startDTD, startEntity, startPrefixMapping, warning
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
notationDecl, resolveEntity, skippedEntity, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StAXEventContentHandler

public StAXEventContentHandler()
Constructs a default instance with a default event factory. You must set the XMLEventConsumervia the setEventConsumer(XMLEventConsumer)method.


StAXEventContentHandler

public StAXEventContentHandler(XMLEventConsumer consumer)
Constructs an instance that writes events to the provided XMLEventConsumer. Events will be constructed from a default XMLEventFactory instance.

Parameters:
consumer - The XMLEventConsumerto which events will be written.

StAXEventContentHandler

public StAXEventContentHandler(XMLEventConsumer consumer,
                               XMLEventFactory factory)
Constructs an instance that writes events constructed with the provided XMLEventFactory to the provided XMLEventConsumer

Parameters:
consumer - The XMLEventConsumer to which events will be written.
factory - The XMLEventFactory used to construct events. If null, a default instance will be constructed.
Method Detail

getEventConsumer

public XMLEventConsumer getEventConsumer()
Returns a reference to the XMLEventConsumer to which events will be written.

Returns:
The XMLEventConsumer to which events will be written.

setEventConsumer

public void setEventConsumer(XMLEventConsumer consumer)
Sets the XMLEventConsumer to which events are written.

Parameters:
consumer - The XMLEventConsumer to which events will be written.

getEventFactory

public XMLEventFactory getEventFactory()
Returns a reference to the XMLEventFactory used to construct events.

Returns:
The XMLEventFactory used to construct events.

setEventFactory

public void setEventFactory(XMLEventFactory factory)
Sets the XMLEventFactory used to create events.

Parameters:
factory - The XMLEventFactory used to create events.

startDocument

public void startDocument()
                   throws SAXException
Specified by:
startDocument in interface ContentHandler
Overrides:
startDocument in class StAXContentHandler
Throws:
SAXException

endDocument

public void endDocument()
                 throws SAXException
Specified by:
endDocument in interface ContentHandler
Overrides:
endDocument in class StAXContentHandler
Throws:
SAXException

startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String qName,
                         Attributes attributes)
                  throws SAXException
Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class StAXContentHandler
Throws:
SAXException

endElement

public void endElement(java.lang.String uri,
                       java.lang.String localName,
                       java.lang.String qName)
                throws SAXException
Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class StAXContentHandler
Throws:
SAXException

comment

public void comment(char[] ch,
                    int start,
                    int length)
             throws SAXException
Specified by:
comment in interface LexicalHandler
Overrides:
comment in class StAXContentHandler
Throws:
SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
Specified by:
characters in interface ContentHandler
Overrides:
characters in class StAXContentHandler
Throws:
SAXException

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws SAXException
Throws:
SAXException

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws SAXException
Throws:
SAXException

endCDATA

public void endCDATA()
              throws SAXException
Specified by:
endCDATA in interface LexicalHandler
Overrides:
endCDATA in class StAXContentHandler
Throws:
SAXException

createStartEvents

protected void createStartEvents(Attributes attributes,
                                 java.util.Collection[] events)
Creates the Namespaceand Attributeevents associated with a StartElement.

Parameters:
attributes - The SAX attributes object.
events - An array used to return the two collections of Namespaceand Attributeevents. The namespaces will be placed at events[0] and the attributes as events[1].

createNamespace

protected Namespace createNamespace(java.lang.String prefix,
                                    java.lang.String uri)