com.ctc.wstx.sax
Class WstxSAXParser

java.lang.Object
  extended by javax.xml.parsers.SAXParser
      extended by com.ctc.wstx.sax.WstxSAXParser
All Implemented Interfaces:
DTDEventListener, Attributes, Attributes2, Locator2, Locator, Parser, XMLReader

public class WstxSAXParser
extends SAXParser
implements Parser, XMLReader, Attributes2, Locator2, DTDEventListener

This class implements parser part of JAXP and SAX interfaces; and effectively offers an alternative to using Stax input factory / stream reader combination.


Field Summary
protected  AttributeCollector mAttrCollector
           
protected  int mAttrCount
          Number of attributes accessible via Attributes and Attributes2 interfaces, for the current start element.
protected  ReaderConfig mConfig
           
protected  ContentHandler mContentHandler
           
protected  DTDHandler mDTDHandler
           
protected  InputElementStack mElemStack
           
protected  String mEncoding
           
protected  boolean mFeatNsPrefixes
           
protected  int mNsCount
          Need to keep track of number of namespaces, if namespace declarations are to be reported along with attributes (see mFeatNsPrefixes).
protected  BasicStreamReader mScanner
          Since the stream reader would mostly be just a wrapper around the underlying scanner (its main job is to implement Stax interface), we can and should just use the scanner.
protected  boolean mStandalone
           
protected  WstxInputFactory mStaxFactory
          We will need the factory reference mostly for constructing underlying stream reader we use.
protected  String mXmlVersion
           
 
Constructor Summary
WstxSAXParser()
           
WstxSAXParser(WstxInputFactory sf, boolean nsPrefixes)
           NOTE: this was a protected constructor for versions 4.0 and 3.2; changed to public in 4.1
 
Method Summary
 void attributeDecl(String eName, String aName, String type, String mode, String value)
           
 void dtdComment(char[] data, int offset, int len)
           
 void dtdElementDecl(String name, String model)
           
 void dtdExternalEntityDecl(String name, String publicId, String systemId)
           
 void dtdInternalEntityDecl(String name, String value)
           
 void dtdNotationDecl(String name, String publicId, String systemId, URL baseURL)
           
 void dtdProcessingInstruction(String target, String data)
           
 boolean dtdReportComments()
           
 void dtdSkippedEntity(String name)
           
 void dtdUnparsedEntityDecl(String name, String publicId, String systemId, String notationName, URL baseURL)
           
 int getColumnNumber()
           
 ContentHandler getContentHandler()
           
 DTDHandler getDTDHandler()
           
 String getEncoding()
           
 EntityResolver getEntityResolver()
           
 ErrorHandler getErrorHandler()
           
 boolean getFeature(String name)
           
 int getIndex(String qName)
           
 int getIndex(String uri, String localName)
           
 int getLength()
           
 int getLineNumber()
           
 String getLocalName(int index)
           
 Parser getParser()
           
 Object getProperty(String name)
           
 String getPublicId()
           
 String getQName(int index)
           
 ReaderConfig getStaxConfig()
          Accessor used to allow configuring all standard Stax configuration settings that the underlying reader uses.
 String getSystemId()
           
 String getType(int index)
           
 String getType(String qName)
           
 String getType(String uri, String localName)
           
 String getURI(int index)
           
 String getValue(int index)
           
 String getValue(String qName)
           
 String getValue(String uri, String localName)
           
 XMLReader getXMLReader()
           
 String getXMLVersion()
           
 boolean isDeclared(int index)
           
 boolean isDeclared(String qName)
           
 boolean isDeclared(String uri, String localName)
           
 boolean isNamespaceAware()
           
 boolean isSpecified(int index)
           
 boolean isSpecified(String qName)
           
 boolean isSpecified(String uri, String localName)
           
 boolean isValidating()
           
 void parse(InputSource input)
           
 void parse(InputSource is, org.xml.sax.helpers.DefaultHandler dh)
           
 void parse(InputSource is, HandlerBase hb)
           
 void parse(String systemId)
           
 void setContentHandler(ContentHandler handler)
           
 void setDocumentHandler(DocumentHandler handler)
           
 void setDTDHandler(DTDHandler handler)
           
 void setEntityResolver(EntityResolver resolver)
           
 void setErrorHandler(ErrorHandler handler)
           
 void setFeature(String name, boolean value)
           
 void setLocale(Locale locale)
           
 void setProperty(String name, Object value)
           
 
Methods inherited from class javax.xml.parsers.SAXParser
getSchema, isXIncludeAware, parse, parse, parse, parse, parse, parse, parse, parse, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mStaxFactory

protected final WstxInputFactory mStaxFactory
We will need the factory reference mostly for constructing underlying stream reader we use.


mConfig

protected final ReaderConfig mConfig

mFeatNsPrefixes

protected boolean mFeatNsPrefixes

mScanner

protected BasicStreamReader mScanner
Since the stream reader would mostly be just a wrapper around the underlying scanner (its main job is to implement Stax interface), we can and should just use the scanner. In effect, this class is then a replacement of BasicStreamReader, when using SAX interfaces.


mAttrCollector

protected AttributeCollector mAttrCollector

mElemStack

protected InputElementStack mElemStack

mEncoding

protected String mEncoding

mXmlVersion

protected String mXmlVersion

mStandalone

protected boolean mStandalone

mContentHandler

protected ContentHandler mContentHandler

mDTDHandler

protected DTDHandler mDTDHandler

mAttrCount

protected int mAttrCount
Number of attributes accessible via Attributes and Attributes2 interfaces, for the current start element.

Note: does not include namespace declarations, even they are to be reported as attributes.


mNsCount

protected int mNsCount
Need to keep track of number of namespaces, if namespace declarations are to be reported along with attributes (see mFeatNsPrefixes).

Constructor Detail

WstxSAXParser

public WstxSAXParser(WstxInputFactory sf,
                     boolean nsPrefixes)

NOTE: this was a protected constructor for versions 4.0 and 3.2; changed to public in 4.1


WstxSAXParser

public WstxSAXParser()
Method Detail

getParser

public final Parser getParser()
Specified by:
getParser in class SAXParser

getXMLReader

public final XMLReader getXMLReader()
Specified by:
getXMLReader in class SAXParser

getStaxConfig

public final ReaderConfig getStaxConfig()
Accessor used to allow configuring all standard Stax configuration settings that the underlying reader uses.

Since:
4.0.8

isNamespaceAware

public boolean isNamespaceAware()
Specified by:
isNamespaceAware in class SAXParser

isValidating

public boolean isValidating()
Specified by:
isValidating in class SAXParser

getProperty

public Object getProperty(String name)
                   throws SAXNotRecognizedException,
                          SAXNotSupportedException
Specified by:
getProperty in interface XMLReader
Specified by:
getProperty in class SAXParser
Throws:
SAXNotRecognizedException
SAXNotSupportedException

setProperty

public void setProperty(String name,
                        Object value)
                 throws SAXNotRecognizedException,
                        SAXNotSupportedException
Specified by:
setProperty in interface XMLReader
Specified by:
setProperty in class SAXParser
Throws:
SAXNotRecognizedException
SAXNotSupportedException

parse

public void parse(InputSource is,
                  HandlerBase hb)
           throws SAXException,
                  IOException
Overrides:
parse in class SAXParser
Throws:
SAXException
IOException

parse

public void parse(InputSource is,
                  org.xml.sax.helpers.DefaultHandler dh)
           throws SAXException,
                  IOException
Overrides:
parse in class SAXParser
Throws:
SAXException
IOException

getContentHandler

public ContentHandler getContentHandler()
Specified by:
getContentHandler in interface XMLReader

getDTDHandler

public DTDHandler getDTDHandler()
Specified by:
getDTDHandler in interface XMLReader

getEntityResolver

public EntityResolver getEntityResolver()
Specified by:
getEntityResolver in interface XMLReader

getErrorHandler

public ErrorHandler getErrorHandler()
Specified by:
getErrorHandler in interface XMLReader

getFeature

public boolean getFeature(String name)
                   throws SAXNotRecognizedException
Specified by:
getFeature in interface XMLReader
Throws:
SAXNotRecognizedException

setContentHandler

public void setContentHandler(ContentHandler handler)
Specified by:
setContentHandler in interface XMLReader

setDTDHandler

public void setDTDHandler(DTDHandler handler)
Specified by:
setDTDHandler in interface Parser
Specified by:
setDTDHandler in interface XMLReader

setEntityResolver

public void setEntityResolver(EntityResolver resolver)
Specified by:
setEntityResolver in interface Parser
Specified by:
setEntityResolver in interface XMLReader

setErrorHandler

public void setErrorHandler(ErrorHandler handler)
Specified by:
setErrorHandler in interface Parser
Specified by:
setErrorHandler in interface XMLReader

setFeature

public void setFeature(String name,
                       boolean value)
                throws SAXNotRecognizedException,
                       SAXNotSupportedException
Specified by:
setFeature in interface XMLReader
Throws:
SAXNotRecognizedException
SAXNotSupportedException

parse

public void parse(InputSource input)
           throws SAXException
Specified by:
parse in interface Parser
Specified by:
parse in interface XMLReader
Throws:
SAXException

parse

public void parse(String systemId)
           throws SAXException
Specified by:
parse in interface Parser
Specified by:
parse in interface XMLReader
Throws:
SAXException

setDocumentHandler

public void setDocumentHandler(DocumentHandler handler)
Specified by:
setDocumentHandler in interface Parser

setLocale

public void setLocale(Locale locale)
Specified by:
setLocale in interface Parser

getIndex

public int getIndex(String qName)
Specified by:
getIndex in interface Attributes

getIndex

public int getIndex(String uri,
                    String localName)
Specified by:
getIndex in interface Attributes

getLength

public int getLength()
Specified by:
getLength in interface Attributes

getLocalName

public String getLocalName(int index)
Specified by:
getLocalName in interface Attributes

getQName

public String getQName(int index)
Specified by:
getQName in interface Attributes

getType

public String getType(int index)
Specified by:
getType in interface Attributes

getType

public String getType(String qName)
Specified by:
getType in interface Attributes

getType

public String getType(String uri,
                      String localName)
Specified by:
getType in interface Attributes

getURI

public String getURI(int index)
Specified by:
getURI in interface Attributes

getValue

public String getValue(int index)
Specified by:
getValue in interface Attributes

getValue

public String getValue(String qName)
Specified by:
getValue in interface Attributes

getValue

public String getValue(String uri,
                       String localName)
Specified by:
getValue in interface Attributes

isDeclared

public boolean isDeclared(int index)
Specified by:
isDeclared in interface Attributes2

isDeclared

public boolean isDeclared(String qName)
Specified by:
isDeclared in interface Attributes2

isDeclared

public boolean isDeclared(String uri,
                          String localName)
Specified by:
isDeclared in interface Attributes2

isSpecified

public boolean isSpecified(int index)
Specified by:
isSpecified in interface Attributes2

isSpecified

public boolean isSpecified(String qName)
Specified by:
isSpecified in interface Attributes2

isSpecified

public boolean isSpecified(String uri,
                           String localName)
Specified by:
isSpecified in interface Attributes2

getColumnNumber

public int getColumnNumber()
Specified by:
getColumnNumber in interface Locator

getLineNumber

public int getLineNumber()
Specified by:
getLineNumber in interface Locator

getPublicId

public String getPublicId()
Specified by:
getPublicId in interface Locator

getSystemId

public String getSystemId()
Specified by:
getSystemId in interface Locator

getEncoding

public String getEncoding()
Specified by:
getEncoding in interface Locator2

getXMLVersion

public String getXMLVersion()
Specified by:
getXMLVersion in interface Locator2

dtdReportComments

public boolean dtdReportComments()
Specified by:
dtdReportComments in interface DTDEventListener
Returns:
True, if there is a listener interested in getting comment events within DTD subset (since that's optional)

dtdComment

public void dtdComment(char[] data,
                       int offset,
                       int len)
Specified by:
dtdComment in interface DTDEventListener

dtdProcessingInstruction

public void dtdProcessingInstruction(String target,
                                     String data)
Specified by:
dtdProcessingInstruction in interface DTDEventListener

dtdSkippedEntity

public void dtdSkippedEntity(String name)
Specified by:
dtdSkippedEntity in interface DTDEventListener

dtdNotationDecl

public void dtdNotationDecl(String name,
                            String publicId,
                            String systemId,
                            URL baseURL)
                     throws XMLStreamException
Specified by:
dtdNotationDecl in interface DTDEventListener
Throws:
XMLStreamException

dtdUnparsedEntityDecl

public void dtdUnparsedEntityDecl(String name,
                                  String publicId,
                                  String systemId,
                                  String notationName,
                                  URL baseURL)
                           throws XMLStreamException
Specified by:
dtdUnparsedEntityDecl in interface DTDEventListener
Throws:
XMLStreamException

attributeDecl

public void attributeDecl(String eName,
                          String aName,
                          String type,
                          String mode,
                          String value)
Specified by:
attributeDecl in interface DTDEventListener

dtdElementDecl

public void dtdElementDecl(String name,
                           String model)
Specified by:
dtdElementDecl in interface DTDEventListener

dtdExternalEntityDecl

public void dtdExternalEntityDecl(String name,
                                  String publicId,
                                  String systemId)
Specified by:
dtdExternalEntityDecl in interface DTDEventListener

dtdInternalEntityDecl

public void dtdInternalEntityDecl(String name,
                                  String value)
Specified by:
dtdInternalEntityDecl in interface DTDEventListener


Copyright © 2011 Codehaus. All Rights Reserved.