Package com.ctc.wstx.sax
Class WstxSAXParser
- java.lang.Object
-
- javax.xml.parsers.SAXParser
-
- com.ctc.wstx.sax.WstxSAXParser
-
- All Implemented Interfaces:
DTDEventListener
,org.xml.sax.Attributes
,org.xml.sax.ext.Attributes2
,org.xml.sax.ext.Locator2
,org.xml.sax.Locator
,org.xml.sax.Parser
,org.xml.sax.XMLReader
public class WstxSAXParser extends javax.xml.parsers.SAXParser implements org.xml.sax.Parser, org.xml.sax.XMLReader, org.xml.sax.ext.Attributes2, org.xml.sax.ext.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 Classes Modifier and Type Class Description (package private) static class
WstxSAXParser.AttributesWrapper
(package private) static class
WstxSAXParser.DocHandlerWrapper
(package private) class
WstxSAXParser.ResolverProxy
Simple helper class that converts from Stax API into SAX EntityResolver call(s)
-
Field Summary
Fields Modifier and Type Field Description (package private) static boolean
FEAT_DEFAULT_NS_PREFIXES
protected AttributeCollector
mAttrCollector
protected int
mAttrCount
Number of attributes accessible viaAttributes
andAttributes2
interfaces, for the current start element.protected ReaderConfig
mConfig
protected org.xml.sax.ContentHandler
mContentHandler
protected org.xml.sax.ext.DeclHandler
mDeclHandler
protected org.xml.sax.DTDHandler
mDTDHandler
protected InputElementStack
mElemStack
protected java.lang.String
mEncoding
protected org.xml.sax.EntityResolver
mEntityResolver
protected org.xml.sax.ErrorHandler
mErrorHandler
protected boolean
mFeatNsPrefixes
protected org.xml.sax.ext.LexicalHandler
mLexicalHandler
protected int
mNsCount
Need to keep track of number of namespaces, if namespace declarations are to be reported along with attributes (seemFeatNsPrefixes
).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 java.lang.String
mXmlVersion
-
Constructor Summary
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
attributeDecl(java.lang.String eName, java.lang.String aName, java.lang.String type, java.lang.String mode, java.lang.String value)
void
dtdComment(char[] data, int offset, int len)
void
dtdElementDecl(java.lang.String name, java.lang.String model)
void
dtdExternalEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
void
dtdInternalEntityDecl(java.lang.String name, java.lang.String value)
void
dtdNotationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.net.URL baseURL)
void
dtdProcessingInstruction(java.lang.String target, java.lang.String data)
boolean
dtdReportComments()
void
dtdSkippedEntity(java.lang.String name)
void
dtdUnparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName, java.net.URL baseURL)
private void
fireAuxEvent(int type, boolean inTree)
private void
fireEvents()
This is the actual "tight event loop" that will send all events between start and end document events.private void
fireStartTag()
int
getColumnNumber()
org.xml.sax.ContentHandler
getContentHandler()
org.xml.sax.DTDHandler
getDTDHandler()
java.lang.String
getEncoding()
org.xml.sax.EntityResolver
getEntityResolver()
org.xml.sax.ErrorHandler
getErrorHandler()
boolean
getFeature(java.lang.String name)
int
getIndex(java.lang.String qName)
int
getIndex(java.lang.String uri, java.lang.String localName)
int
getLength()
int
getLineNumber()
java.lang.String
getLocalName(int index)
org.xml.sax.Parser
getParser()
java.lang.Object
getProperty(java.lang.String name)
java.lang.String
getPublicId()
java.lang.String
getQName(int index)
ReaderConfig
getStaxConfig()
Accessor used to allow configuring all standard Stax configuration settings that the underlying reader uses.java.lang.String
getSystemId()
java.lang.String
getType(int index)
java.lang.String
getType(java.lang.String qName)
java.lang.String
getType(java.lang.String uri, java.lang.String localName)
java.lang.String
getURI(int index)
java.lang.String
getValue(int index)
java.lang.String
getValue(java.lang.String qName)
java.lang.String
getValue(java.lang.String uri, java.lang.String localName)
org.xml.sax.XMLReader
getXMLReader()
java.lang.String
getXMLVersion()
boolean
isDeclared(int index)
boolean
isDeclared(java.lang.String qName)
boolean
isDeclared(java.lang.String uri, java.lang.String localName)
boolean
isNamespaceAware()
boolean
isSpecified(int index)
boolean
isSpecified(java.lang.String qName)
boolean
isSpecified(java.lang.String uri, java.lang.String localName)
boolean
isValidating()
void
parse(java.lang.String systemId)
void
parse(org.xml.sax.InputSource input)
void
parse(org.xml.sax.InputSource is, org.xml.sax.HandlerBase hb)
void
parse(org.xml.sax.InputSource is, org.xml.sax.helpers.DefaultHandler dh)
void
setContentHandler(org.xml.sax.ContentHandler handler)
void
setDocumentHandler(org.xml.sax.DocumentHandler handler)
void
setDTDHandler(org.xml.sax.DTDHandler handler)
void
setEntityResolver(org.xml.sax.EntityResolver resolver)
void
setErrorHandler(org.xml.sax.ErrorHandler handler)
void
setFeature(java.lang.String name, boolean value)
void
setLocale(java.util.Locale locale)
void
setProperty(java.lang.String name, java.lang.Object value)
private void
throwNoSuchAttribute(int index)
private void
throwSaxException(java.lang.Exception src)
private void
throwSaxException(java.lang.String msg)
-
-
-
Field Detail
-
FEAT_DEFAULT_NS_PREFIXES
static final boolean FEAT_DEFAULT_NS_PREFIXES
- See Also:
- Constant Field Values
-
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 java.lang.String mEncoding
-
mXmlVersion
protected java.lang.String mXmlVersion
-
mStandalone
protected boolean mStandalone
-
mContentHandler
protected org.xml.sax.ContentHandler mContentHandler
-
mDTDHandler
protected org.xml.sax.DTDHandler mDTDHandler
-
mEntityResolver
protected org.xml.sax.EntityResolver mEntityResolver
-
mErrorHandler
protected org.xml.sax.ErrorHandler mErrorHandler
-
mLexicalHandler
protected org.xml.sax.ext.LexicalHandler mLexicalHandler
-
mDeclHandler
protected org.xml.sax.ext.DeclHandler mDeclHandler
-
mAttrCount
protected int mAttrCount
Number 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 mNsCount
Need to keep track of number of namespaces, if namespace declarations are to be reported along with attributes (seemFeatNsPrefixes
).
-
-
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 org.xml.sax.Parser getParser()
- Specified by:
getParser
in classjavax.xml.parsers.SAXParser
-
getXMLReader
public final org.xml.sax.XMLReader getXMLReader()
- Specified by:
getXMLReader
in classjavax.xml.parsers.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 classjavax.xml.parsers.SAXParser
-
isValidating
public boolean isValidating()
- Specified by:
isValidating
in classjavax.xml.parsers.SAXParser
-
getProperty
public java.lang.Object getProperty(java.lang.String name) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
- Specified by:
getProperty
in interfaceorg.xml.sax.XMLReader
- Specified by:
getProperty
in classjavax.xml.parsers.SAXParser
- Throws:
org.xml.sax.SAXNotRecognizedException
org.xml.sax.SAXNotSupportedException
-
setProperty
public void setProperty(java.lang.String name, java.lang.Object value) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
- Specified by:
setProperty
in interfaceorg.xml.sax.XMLReader
- Specified by:
setProperty
in classjavax.xml.parsers.SAXParser
- Throws:
org.xml.sax.SAXNotRecognizedException
org.xml.sax.SAXNotSupportedException
-
parse
public void parse(org.xml.sax.InputSource is, org.xml.sax.HandlerBase hb) throws org.xml.sax.SAXException, java.io.IOException
- Overrides:
parse
in classjavax.xml.parsers.SAXParser
- Throws:
org.xml.sax.SAXException
java.io.IOException
-
parse
public void parse(org.xml.sax.InputSource is, org.xml.sax.helpers.DefaultHandler dh) throws org.xml.sax.SAXException, java.io.IOException
- Overrides:
parse
in classjavax.xml.parsers.SAXParser
- Throws:
org.xml.sax.SAXException
java.io.IOException
-
getContentHandler
public org.xml.sax.ContentHandler getContentHandler()
- Specified by:
getContentHandler
in interfaceorg.xml.sax.XMLReader
-
getDTDHandler
public org.xml.sax.DTDHandler getDTDHandler()
- Specified by:
getDTDHandler
in interfaceorg.xml.sax.XMLReader
-
getEntityResolver
public org.xml.sax.EntityResolver getEntityResolver()
- Specified by:
getEntityResolver
in interfaceorg.xml.sax.XMLReader
-
getErrorHandler
public org.xml.sax.ErrorHandler getErrorHandler()
- Specified by:
getErrorHandler
in interfaceorg.xml.sax.XMLReader
-
getFeature
public boolean getFeature(java.lang.String name) throws org.xml.sax.SAXNotRecognizedException
- Specified by:
getFeature
in interfaceorg.xml.sax.XMLReader
- Throws:
org.xml.sax.SAXNotRecognizedException
-
setContentHandler
public void setContentHandler(org.xml.sax.ContentHandler handler)
- Specified by:
setContentHandler
in interfaceorg.xml.sax.XMLReader
-
setDTDHandler
public void setDTDHandler(org.xml.sax.DTDHandler handler)
- Specified by:
setDTDHandler
in interfaceorg.xml.sax.Parser
- Specified by:
setDTDHandler
in interfaceorg.xml.sax.XMLReader
-
setEntityResolver
public void setEntityResolver(org.xml.sax.EntityResolver resolver)
- Specified by:
setEntityResolver
in interfaceorg.xml.sax.Parser
- Specified by:
setEntityResolver
in interfaceorg.xml.sax.XMLReader
-
setErrorHandler
public void setErrorHandler(org.xml.sax.ErrorHandler handler)
- Specified by:
setErrorHandler
in interfaceorg.xml.sax.Parser
- Specified by:
setErrorHandler
in interfaceorg.xml.sax.XMLReader
-
setFeature
public void setFeature(java.lang.String name, boolean value) throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException
- Specified by:
setFeature
in interfaceorg.xml.sax.XMLReader
- Throws:
org.xml.sax.SAXNotRecognizedException
org.xml.sax.SAXNotSupportedException
-
parse
public void parse(org.xml.sax.InputSource input) throws org.xml.sax.SAXException
- Specified by:
parse
in interfaceorg.xml.sax.Parser
- Specified by:
parse
in interfaceorg.xml.sax.XMLReader
- Throws:
org.xml.sax.SAXException
-
parse
public void parse(java.lang.String systemId) throws org.xml.sax.SAXException
- Specified by:
parse
in interfaceorg.xml.sax.Parser
- Specified by:
parse
in interfaceorg.xml.sax.XMLReader
- Throws:
org.xml.sax.SAXException
-
fireEvents
private final void fireEvents() throws java.io.IOException, org.xml.sax.SAXException, javax.xml.stream.XMLStreamException
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.- Throws:
java.io.IOException
org.xml.sax.SAXException
javax.xml.stream.XMLStreamException
-
fireAuxEvent
private final void fireAuxEvent(int type, boolean inTree) throws java.io.IOException, org.xml.sax.SAXException, javax.xml.stream.XMLStreamException
- Throws:
java.io.IOException
org.xml.sax.SAXException
javax.xml.stream.XMLStreamException
-
fireStartTag
private final void fireStartTag() throws org.xml.sax.SAXException
- Throws:
org.xml.sax.SAXException
-
setDocumentHandler
public void setDocumentHandler(org.xml.sax.DocumentHandler handler)
- Specified by:
setDocumentHandler
in interfaceorg.xml.sax.Parser
-
setLocale
public void setLocale(java.util.Locale locale)
- Specified by:
setLocale
in interfaceorg.xml.sax.Parser
-
getIndex
public int getIndex(java.lang.String qName)
- Specified by:
getIndex
in interfaceorg.xml.sax.Attributes
-
getIndex
public int getIndex(java.lang.String uri, java.lang.String localName)
- Specified by:
getIndex
in interfaceorg.xml.sax.Attributes
-
getLength
public int getLength()
- Specified by:
getLength
in interfaceorg.xml.sax.Attributes
-
getLocalName
public java.lang.String getLocalName(int index)
- Specified by:
getLocalName
in interfaceorg.xml.sax.Attributes
-
getQName
public java.lang.String getQName(int index)
- Specified by:
getQName
in interfaceorg.xml.sax.Attributes
-
getType
public java.lang.String getType(int index)
- Specified by:
getType
in interfaceorg.xml.sax.Attributes
-
getType
public java.lang.String getType(java.lang.String qName)
- Specified by:
getType
in interfaceorg.xml.sax.Attributes
-
getType
public java.lang.String getType(java.lang.String uri, java.lang.String localName)
- Specified by:
getType
in interfaceorg.xml.sax.Attributes
-
getURI
public java.lang.String getURI(int index)
- Specified by:
getURI
in interfaceorg.xml.sax.Attributes
-
getValue
public java.lang.String getValue(int index)
- Specified by:
getValue
in interfaceorg.xml.sax.Attributes
-
getValue
public java.lang.String getValue(java.lang.String qName)
- Specified by:
getValue
in interfaceorg.xml.sax.Attributes
-
getValue
public java.lang.String getValue(java.lang.String uri, java.lang.String localName)
- Specified by:
getValue
in interfaceorg.xml.sax.Attributes
-
isDeclared
public boolean isDeclared(int index)
- Specified by:
isDeclared
in interfaceorg.xml.sax.ext.Attributes2
-
isDeclared
public boolean isDeclared(java.lang.String qName)
- Specified by:
isDeclared
in interfaceorg.xml.sax.ext.Attributes2
-
isDeclared
public boolean isDeclared(java.lang.String uri, java.lang.String localName)
- Specified by:
isDeclared
in interfaceorg.xml.sax.ext.Attributes2
-
isSpecified
public boolean isSpecified(int index)
- Specified by:
isSpecified
in interfaceorg.xml.sax.ext.Attributes2
-
isSpecified
public boolean isSpecified(java.lang.String qName)
- Specified by:
isSpecified
in interfaceorg.xml.sax.ext.Attributes2
-
isSpecified
public boolean isSpecified(java.lang.String uri, java.lang.String localName)
- Specified by:
isSpecified
in interfaceorg.xml.sax.ext.Attributes2
-
getColumnNumber
public int getColumnNumber()
- Specified by:
getColumnNumber
in interfaceorg.xml.sax.Locator
-
getLineNumber
public int getLineNumber()
- Specified by:
getLineNumber
in interfaceorg.xml.sax.Locator
-
getPublicId
public java.lang.String getPublicId()
- Specified by:
getPublicId
in interfaceorg.xml.sax.Locator
-
getSystemId
public java.lang.String getSystemId()
- Specified by:
getSystemId
in interfaceorg.xml.sax.Locator
-
getEncoding
public java.lang.String getEncoding()
- Specified by:
getEncoding
in interfaceorg.xml.sax.ext.Locator2
-
getXMLVersion
public java.lang.String getXMLVersion()
- Specified by:
getXMLVersion
in interfaceorg.xml.sax.ext.Locator2
-
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
public void dtdProcessingInstruction(java.lang.String target, java.lang.String data)
- Specified by:
dtdProcessingInstruction
in interfaceDTDEventListener
-
dtdSkippedEntity
public void dtdSkippedEntity(java.lang.String name)
- Specified by:
dtdSkippedEntity
in interfaceDTDEventListener
-
dtdNotationDecl
public void dtdNotationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.net.URL baseURL) throws javax.xml.stream.XMLStreamException
- Specified by:
dtdNotationDecl
in interfaceDTDEventListener
- Throws:
javax.xml.stream.XMLStreamException
-
dtdUnparsedEntityDecl
public void dtdUnparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName, java.net.URL baseURL) throws javax.xml.stream.XMLStreamException
- Specified by:
dtdUnparsedEntityDecl
in interfaceDTDEventListener
- Throws:
javax.xml.stream.XMLStreamException
-
attributeDecl
public void attributeDecl(java.lang.String eName, java.lang.String aName, java.lang.String type, java.lang.String mode, java.lang.String value)
- Specified by:
attributeDecl
in interfaceDTDEventListener
-
dtdElementDecl
public void dtdElementDecl(java.lang.String name, java.lang.String model)
- Specified by:
dtdElementDecl
in interfaceDTDEventListener
-
dtdExternalEntityDecl
public void dtdExternalEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
- Specified by:
dtdExternalEntityDecl
in interfaceDTDEventListener
-
dtdInternalEntityDecl
public void dtdInternalEntityDecl(java.lang.String name, java.lang.String value)
- Specified by:
dtdInternalEntityDecl
in interfaceDTDEventListener
-
throwSaxException
private void throwSaxException(java.lang.Exception src) throws org.xml.sax.SAXException
- Throws:
org.xml.sax.SAXException
-
throwSaxException
private void throwSaxException(java.lang.String msg) throws org.xml.sax.SAXException
- Throws:
org.xml.sax.SAXException
-
throwNoSuchAttribute
private void throwNoSuchAttribute(int index)
-
-