Package com.ctc.wstx.sax
Class WstxSAXParser
java.lang.Object
javax.xml.parsers.SAXParser
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
(package private) static final class
(package private) final class
Simple helper class that converts from Stax API into SAX EntityResolver call(s) -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final boolean
protected AttributeCollector
protected int
Number of attributes accessible viaAttributes
andAttributes2
interfaces, for the current start element.protected final ReaderConfig
protected ContentHandler
protected DeclHandler
protected DTDHandler
protected InputElementStack
protected String
protected EntityResolver
protected ErrorHandler
protected boolean
protected LexicalHandler
protected int
Need to keep track of number of namespaces, if namespace declarations are to be reported along with attributes (seemFeatNsPrefixes
).protected BasicStreamReader
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
protected final WstxInputFactory
We will need the factory reference mostly for constructing underlying stream reader we use.protected String
-
Constructor Summary
ConstructorsConstructorDescriptionWstxSAXParser
(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
Modifier and TypeMethodDescriptionvoid
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
void
dtdSkippedEntity
(String name) void
dtdUnparsedEntityDecl
(String name, String publicId, String systemId, String notationName, URL baseURL) private final void
fireAuxEvent
(int type, boolean inTree) private final void
This is the actual "tight event loop" that will send all events between start and end document events.private final void
int
boolean
getFeature
(String name) int
int
int
int
getLocalName
(int index) final Parser
getProperty
(String name) getQName
(int index) final ReaderConfig
Accessor used to allow configuring all standard Stax configuration settings that the underlying reader uses.getType
(int index) getURI
(int index) getValue
(int index) final XMLReader
boolean
isDeclared
(int index) boolean
isDeclared
(String qName) boolean
isDeclared
(String uri, String localName) boolean
boolean
isSpecified
(int index) boolean
isSpecified
(String qName) boolean
isSpecified
(String uri, String localName) boolean
void
void
parse
(InputSource input) void
parse
(InputSource is, HandlerBase hb) void
parse
(InputSource is, DefaultHandler dh) 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
void
setProperty
(String name, Object value) private void
throwNoSuchAttribute
(int index) private void
private void
throwSaxException
(String msg)
-
Field Details
-
FEAT_DEFAULT_NS_PREFIXES
static final boolean FEAT_DEFAULT_NS_PREFIXES- See Also:
-
mStaxFactory
We will need the factory reference mostly for constructing underlying stream reader we use. -
mConfig
-
mFeatNsPrefixes
protected boolean mFeatNsPrefixes -
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
-
mElemStack
-
mEncoding
-
mXmlVersion
-
mStandalone
protected boolean mStandalone -
mContentHandler
-
mDTDHandler
-
mEntityResolver
-
mErrorHandler
-
mLexicalHandler
-
mDeclHandler
-
mAttrCount
protected int mAttrCountNumber of attributes accessible viaAttributes
andAttributes2
interfaces, for the current start element.Note: does not include namespace declarations, even they are to be reported as attributes.
-
mNsCount
protected int mNsCountNeed to keep track of number of namespaces, if namespace declarations are to be reported along with attributes (seemFeatNsPrefixes
).
-
-
Constructor Details
-
WstxSAXParser
NOTE: this was a protected constructor for versions 4.0 and 3.2; changed to public in 4.1
-
WstxSAXParser
public WstxSAXParser()
-
-
Method Details
-
getParser
-
getXMLReader
- Specified by:
getXMLReader
in classSAXParser
-
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 classSAXParser
-
isValidating
public boolean isValidating()- Specified by:
isValidating
in classSAXParser
-
getProperty
- Specified by:
getProperty
in interfaceXMLReader
- Specified by:
getProperty
in classSAXParser
- Throws:
SAXNotRecognizedException
SAXNotSupportedException
-
setProperty
public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException - Specified by:
setProperty
in interfaceXMLReader
- Specified by:
setProperty
in classSAXParser
- Throws:
SAXNotRecognizedException
SAXNotSupportedException
-
parse
- Overrides:
parse
in classSAXParser
- Throws:
SAXException
IOException
-
parse
- Overrides:
parse
in classSAXParser
- Throws:
SAXException
IOException
-
getContentHandler
- Specified by:
getContentHandler
in interfaceXMLReader
-
getDTDHandler
- Specified by:
getDTDHandler
in interfaceXMLReader
-
getEntityResolver
- Specified by:
getEntityResolver
in interfaceXMLReader
-
getErrorHandler
- Specified by:
getErrorHandler
in interfaceXMLReader
-
getFeature
- Specified by:
getFeature
in interfaceXMLReader
- Throws:
SAXNotRecognizedException
-
setContentHandler
- Specified by:
setContentHandler
in interfaceXMLReader
-
setDTDHandler
- Specified by:
setDTDHandler
in interfaceParser
- Specified by:
setDTDHandler
in interfaceXMLReader
-
setEntityResolver
- Specified by:
setEntityResolver
in interfaceParser
- Specified by:
setEntityResolver
in interfaceXMLReader
-
setErrorHandler
- Specified by:
setErrorHandler
in interfaceParser
- Specified by:
setErrorHandler
in interfaceXMLReader
-
setFeature
public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException - Specified by:
setFeature
in interfaceXMLReader
- Throws:
SAXNotRecognizedException
SAXNotSupportedException
-
parse
- Specified by:
parse
in interfaceParser
- Specified by:
parse
in interfaceXMLReader
- Throws:
SAXException
-
parse
- Specified by:
parse
in interfaceParser
- Specified by:
parse
in interfaceXMLReader
- Throws:
SAXException
-
fireEvents
This is the actual "tight event loop" that will send all events between start and end document events. Although we could use the stream reader here, there's not much as it mostly just forwards requests to the scanner: and so we can as well just copy the little code stream reader's next() method has. -
fireAuxEvent
private final void fireAuxEvent(int type, boolean inTree) throws IOException, SAXException, XMLStreamException -
fireStartTag
- Throws:
SAXException
-
setDocumentHandler
- Specified by:
setDocumentHandler
in interfaceParser
-
setLocale
-
getIndex
- Specified by:
getIndex
in interfaceAttributes
-
getIndex
- Specified by:
getIndex
in interfaceAttributes
-
getLength
public int getLength()- Specified by:
getLength
in interfaceAttributes
-
getLocalName
- Specified by:
getLocalName
in interfaceAttributes
-
getQName
- Specified by:
getQName
in interfaceAttributes
-
getType
- Specified by:
getType
in interfaceAttributes
-
getType
- Specified by:
getType
in interfaceAttributes
-
getType
- Specified by:
getType
in interfaceAttributes
-
getURI
- Specified by:
getURI
in interfaceAttributes
-
getValue
- Specified by:
getValue
in interfaceAttributes
-
getValue
- Specified by:
getValue
in interfaceAttributes
-
getValue
- Specified by:
getValue
in interfaceAttributes
-
isDeclared
public boolean isDeclared(int index) - Specified by:
isDeclared
in interfaceAttributes2
-
isDeclared
- Specified by:
isDeclared
in interfaceAttributes2
-
isDeclared
- Specified by:
isDeclared
in interfaceAttributes2
-
isSpecified
public boolean isSpecified(int index) - Specified by:
isSpecified
in interfaceAttributes2
-
isSpecified
- Specified by:
isSpecified
in interfaceAttributes2
-
isSpecified
- Specified by:
isSpecified
in interfaceAttributes2
-
getColumnNumber
public int getColumnNumber()- Specified by:
getColumnNumber
in interfaceLocator
-
getLineNumber
public int getLineNumber()- Specified by:
getLineNumber
in interfaceLocator
-
getPublicId
- Specified by:
getPublicId
in interfaceLocator
-
getSystemId
- Specified by:
getSystemId
in interfaceLocator
-
getEncoding
- Specified by:
getEncoding
in interfaceLocator2
-
getXMLVersion
- Specified by:
getXMLVersion
in interfaceLocator2
-
dtdReportComments
public boolean dtdReportComments()- Specified by:
dtdReportComments
in interfaceDTDEventListener
- 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 interfaceDTDEventListener
-
dtdProcessingInstruction
- Specified by:
dtdProcessingInstruction
in interfaceDTDEventListener
-
dtdSkippedEntity
- Specified by:
dtdSkippedEntity
in interfaceDTDEventListener
-
dtdNotationDecl
public void dtdNotationDecl(String name, String publicId, String systemId, URL baseURL) throws XMLStreamException - Specified by:
dtdNotationDecl
in interfaceDTDEventListener
- Throws:
XMLStreamException
-
dtdUnparsedEntityDecl
public void dtdUnparsedEntityDecl(String name, String publicId, String systemId, String notationName, URL baseURL) throws XMLStreamException - Specified by:
dtdUnparsedEntityDecl
in interfaceDTDEventListener
- Throws:
XMLStreamException
-
attributeDecl
- Specified by:
attributeDecl
in interfaceDTDEventListener
-
dtdElementDecl
- Specified by:
dtdElementDecl
in interfaceDTDEventListener
-
dtdExternalEntityDecl
- Specified by:
dtdExternalEntityDecl
in interfaceDTDEventListener
-
dtdInternalEntityDecl
- Specified by:
dtdInternalEntityDecl
in interfaceDTDEventListener
-
throwSaxException
- Throws:
SAXException
-
throwSaxException
- Throws:
SAXException
-
throwNoSuchAttribute
private void throwNoSuchAttribute(int index)
-