Class X2PullParser
java.lang.Object
org.gjt.xpp.x2impl.x2pullparser.X2PullParser
- All Implemented Interfaces:
org.apache.xerces.xni.parser.XMLErrorHandler, org.apache.xerces.xni.XMLDocumentHandler, XmlPullParser, XmlPullParserBufferControl, XmlPullParserEventPosition
public class X2PullParser
extends Object
implements XmlPullParser, XmlPullParserEventPosition, XmlPullParserBufferControl, org.apache.xerces.xni.parser.XMLErrorHandler, org.apache.xerces.xni.XMLDocumentHandler
This is Xerces 2 driver that uses XNI pull parsing capabilities to
implement XML Pull Parser API.
Advantages:
- uses Xerces 2 and bases in stable and standard compliant parser
- uses Xerces 2 XNI in pull parser mode but hides complexity of working with XNI with simple PullParser API
- this is alpha version - may have still bugs :-)
- Author:
- Aleksander Slominski
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected X2Attribute[]temporary array of current attributesprotected intindex for last attribute in attrPos arrayprotected intsize of attrPos arrayprotected org.apache.xerces.xni.QNameprotected StringBufferContent of current element if in CONTENT stateprotected intprotected intprotected X2PullParser.CumulativeReaderprotected booleanprotected X2ElementContent[]temprary array to keep ElementContent stackprotected inthow many elements are on elStackprotected intsize of elStack arrayprotected booleanHave we read empty element?protected intend position of current event in tokenizer bifferprotected intstart position of current event in tokenizer bifferprotected org.apache.xerces.xni.parser.XMLDocumentSourceDocument sourceprotected booleanprotected org.apache.xerces.xni.parser.XMLInputSourceprotected org.apache.xerces.xni.XMLLocatorprotected booleanprotected static final Stringprotected static final Stringprotected booleanprotected byteprotected booleanfinal Stringfinal Stringprotected Hashtablemapping of names prefixes to urisprotected org.apache.xerces.xni.parser.XMLPullParserConfigurationprotected booleanshould parser report namespace xmlns* attributes ?protected booleanprotected booleanprotected Exceptionprotected booleanHave we seen root elementprotected booleanprotected booleanprotected bytewhat is current event type as returned from next()?protected booleanshould parser support namespaces?Fields inherited from interface XmlPullParser
CONTENT, END_DOCUMENT, END_TAG, START_TAG -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcharacters(org.apache.xerces.xni.XMLString text, org.apache.xerces.xni.Augmentations augs) voidcomment(org.apache.xerces.xni.XMLString text, org.apache.xerces.xni.Augmentations augs) voiddoctypeDecl(String rootElement, String publicId, String systemId, org.apache.xerces.xni.Augmentations augs) voidemptyElement(org.apache.xerces.xni.QName element, org.apache.xerces.xni.XMLAttributes attributes, org.apache.xerces.xni.Augmentations augs) voidendCDATA(org.apache.xerces.xni.Augmentations augs) voidendDocument(org.apache.xerces.xni.Augmentations augs) voidendElement(org.apache.xerces.xni.QName element, org.apache.xerces.xni.Augmentations augs) voidvoidendGeneralEntity(String name, org.apache.xerces.xni.Augmentations augs) voidendPrefixMapping(String prefix, org.apache.xerces.xni.Augmentations augs) protected voidensureAttribs(int size) Make sure that in attributes temporary array is enough space.protected voidensureCapacity(int size) Make sure that we have enough space to keep element stack if passed size.voidError.voidfatalError(String domain, String key, org.apache.xerces.xni.parser.XMLParseException ex) Fatal error.intintintReturn how big is content.intgetDepth()Returns the current depth of the element.org.apache.xerces.xni.parser.XMLDocumentSourceReturns the document sourcechar[]NOTE: This may be internal buffer and is valud only until call to method next()- do NOT attempt modify !intintbyteReturns the type of the current element (START_TAG, END_TAG, CONTENT, etc)intintReturns the local name of the current element (current event must be START_TAG or END_TAG)intgetNamespacesLength(int depth) Returns the namespace URI of the current element Returns null if not applicable (current event must be START_TAG or END_TAG)Return string describing current position of parser in input stream as text 'at line %d (row) and column %d (colum) [seen %s...]'.Returns the prefix of the current element or null if elemet has no prefix.getQNameLocal(String qName) Return local part of qname.getQNameUri(String qName) Return uri part of qname.Returns the raw name (prefix + ':' + localName) of the current element (current event must be START_TAG or END_TAG)intvoidignorableWhitespace(org.apache.xerces.xni.XMLString text, org.apache.xerces.xni.Augmentations augs) booleanIs mixed element context allowed?booleanbooleanIs parser going to report namespace attributes (xmlns*) ?booleanIs parser namespace aware?booleanReturn true if just read CONTENT contained only white spaces.bytenext()This is a key method - translates XNI callbacks into XPP events (such as START_TAG, END_TAG, CONTENT).voidprocessingInstruction(String target, org.apache.xerces.xni.XMLString data, org.apache.xerces.xni.Augmentations augs) Return String that contains just read CONTENT.voidreadEndTag(XmlEndTag etag) Read value of just read END_TAG into passed as argument EndTag.voidreadNamespacesPrefixes(int depth, String[] prefixes, int off, int len) Return namespace prefixes for element at depthvoidreadNamespacesUris(int depth, String[] uris, int off, int len) Return namespace URIs for element at depthbyteRead subtree into node: call readNodeWithoutChildren and then parse subtree adding children (values obtained with readXontent or readNodeWithoutChildren).voidRead node: it calls readStartTag and then if parser is namespaces aware currently declared nemaspeces will be added and defaultNamespace will be set.voidreadStartTag(XmlStartTag stag) Read value of just read START_TAG into passed as argument StartTag.voidreset()Reset parser state so it can be used to parse newprotected voidvoidsetAllowedMixedContent(boolean enable) Allow for mixed element content.voidsetBufferShrinkable(boolean shrinkable) voidsetDocumentSource(org.apache.xerces.xni.parser.XMLDocumentSource source) Sets the document sourcevoidsetHardLimit(int value) voidsetInput(char[] buf) Reset parser and set new input.voidsetInput(char[] buf, int off, int len) Set the input for parser.voidReset parser and set new input.voidsetNamespaceAttributesReporting(boolean enable) Make parser to report xmlns* attributes.voidsetNamespaceAware(boolean awareness) Set support of namespaces.voidsetSoftLimit(int value) byteskipNode()If parser has just read start tag it allows to skip whoole subtree contined in this element.voidstartCDATA(org.apache.xerces.xni.Augmentations augs) voidstartDocument(org.apache.xerces.xni.XMLLocator locator, String encoding, org.apache.xerces.xni.Augmentations augs) voidstartDocument(org.apache.xerces.xni.XMLLocator locator, String encoding, org.apache.xerces.xni.NamespaceContext namespaceContext, org.apache.xerces.xni.Augmentations augs) voidstartElement(org.apache.xerces.xni.QName element, org.apache.xerces.xni.XMLAttributes attributes, org.apache.xerces.xni.Augmentations augs) voidstartEntity(String name, String publicId, String systemId, String baseSystemId, String encoding, org.apache.xerces.xni.Augmentations augs) voidstartGeneralEntity(String name, org.apache.xerces.xni.XMLResourceIdentifier identifier, String encoding, org.apache.xerces.xni.Augmentations augs) voidstartPrefixMapping(String prefix, String uri, org.apache.xerces.xni.Augmentations augs) voidvoidWarning.voidxmlDecl(String version, String encoding, String standalone, org.apache.xerces.xni.Augmentations augs)
-
Field Details
-
NAMESPACES_FEATURE_ID
- See Also:
-
NAMESPACE_PREFIXES_FEATURE_ID
- See Also:
-
pullParserConfiguration
protected org.apache.xerces.xni.parser.XMLPullParserConfiguration pullParserConfiguration -
locator
protected org.apache.xerces.xni.XMLLocator locator -
attrQName
protected org.apache.xerces.xni.QName attrQName -
needToSetInput
protected boolean needToSetInput -
cumulativeReader
-
inputSource
protected org.apache.xerces.xni.parser.XMLInputSource inputSource -
shrinkable
protected boolean shrinkable -
emptyElement
protected boolean emptyElementHave we read empty element? -
supportNs
protected boolean supportNsshould parser support namespaces? -
reportNsAttribs
protected boolean reportNsAttribsshould parser report namespace xmlns* attributes ? -
allowedMixedContent
protected boolean allowedMixedContent -
seenException
-
disableOffsetTracking
protected boolean disableOffsetTracking -
contentEventStart
protected int contentEventStart -
contentEventEnd
protected int contentEventEnd -
eventStart
protected int eventStartstart position of current event in tokenizer biffer -
eventEnd
protected int eventEndend position of current event in tokenizer biffer -
seenRootElement
protected boolean seenRootElementHave we seen root element -
contentBuf
Content of current element if in CONTENT state -
state
protected byte statewhat is current event type as returned from next()? -
prefix2Ns
mapping of names prefixes to uris -
attrPosEnd
protected int attrPosEndindex for last attribute in attrPos array -
attrPosSize
protected int attrPosSizesize of attrPos array -
attrPos
temporary array of current attributes -
elStackDepth
protected int elStackDepthhow many elements are on elStack -
elStackSize
protected int elStackSizesize of elStack array -
elStack
temprary array to keep ElementContent stack -
startTagInitialized
protected boolean startTagInitialized -
seenContent
protected boolean seenContent -
gotContent
protected boolean gotContent -
nonWhitespaceContent
protected boolean nonWhitespaceContent -
seenCR
protected boolean seenCR -
mixInElement
protected boolean mixInElement -
nextState
protected byte nextState -
fDocumentSource
protected org.apache.xerces.xni.parser.XMLDocumentSource fDocumentSourceDocument source -
POS_ABSOLUTE_START
- See Also:
-
POS_ABSOLUTE_END
- See Also:
-
-
Constructor Details
-
X2PullParser
Create instance of pull parser.- Throws:
XmlPullParserException
-
-
Method Details
-
warning
-
error
-
fatalError
-
setDocumentSource
public void setDocumentSource(org.apache.xerces.xni.parser.XMLDocumentSource source) Sets the document source- Specified by:
setDocumentSourcein interfaceorg.apache.xerces.xni.XMLDocumentHandler
-
getDocumentSource
public org.apache.xerces.xni.parser.XMLDocumentSource getDocumentSource()Returns the document source- Specified by:
getDocumentSourcein interfaceorg.apache.xerces.xni.XMLDocumentHandler
-
startDocument
public void startDocument(org.apache.xerces.xni.XMLLocator locator, String encoding, org.apache.xerces.xni.NamespaceContext namespaceContext, org.apache.xerces.xni.Augmentations augs) throws org.apache.xerces.xni.XNIException - Specified by:
startDocumentin interfaceorg.apache.xerces.xni.XMLDocumentHandler- Throws:
org.apache.xerces.xni.XNIException
-
startDocument
public void startDocument(org.apache.xerces.xni.XMLLocator locator, String encoding, org.apache.xerces.xni.Augmentations augs) throws org.apache.xerces.xni.XNIException - Throws:
org.apache.xerces.xni.XNIException
-
xmlDecl
-
doctypeDecl
-
comment
public void comment(org.apache.xerces.xni.XMLString text, org.apache.xerces.xni.Augmentations augs) throws org.apache.xerces.xni.XNIException - Specified by:
commentin interfaceorg.apache.xerces.xni.XMLDocumentHandler- Throws:
org.apache.xerces.xni.XNIException
-
processingInstruction
public void processingInstruction(String target, org.apache.xerces.xni.XMLString data, org.apache.xerces.xni.Augmentations augs) throws org.apache.xerces.xni.XNIException - Specified by:
processingInstructionin interfaceorg.apache.xerces.xni.XMLDocumentHandler- Throws:
org.apache.xerces.xni.XNIException
-
startGeneralEntity
public void startGeneralEntity(String name, org.apache.xerces.xni.XMLResourceIdentifier identifier, String encoding, org.apache.xerces.xni.Augmentations augs) throws org.apache.xerces.xni.XNIException - Specified by:
startGeneralEntityin interfaceorg.apache.xerces.xni.XMLDocumentHandler- Throws:
org.apache.xerces.xni.XNIException
-
endGeneralEntity
public void endGeneralEntity(String name, org.apache.xerces.xni.Augmentations augs) throws org.apache.xerces.xni.XNIException - Specified by:
endGeneralEntityin interfaceorg.apache.xerces.xni.XMLDocumentHandler- Throws:
org.apache.xerces.xni.XNIException
-
startPrefixMapping
-
startElement
public void startElement(org.apache.xerces.xni.QName element, org.apache.xerces.xni.XMLAttributes attributes, org.apache.xerces.xni.Augmentations augs) throws org.apache.xerces.xni.XNIException - Specified by:
startElementin interfaceorg.apache.xerces.xni.XMLDocumentHandler- Throws:
org.apache.xerces.xni.XNIException
-
emptyElement
public void emptyElement(org.apache.xerces.xni.QName element, org.apache.xerces.xni.XMLAttributes attributes, org.apache.xerces.xni.Augmentations augs) throws org.apache.xerces.xni.XNIException - Specified by:
emptyElementin interfaceorg.apache.xerces.xni.XMLDocumentHandler- Throws:
org.apache.xerces.xni.XNIException
-
startEntity
-
textDecl
-
endEntity
public void endEntity(String name, org.apache.xerces.xni.Augmentations augs) throws org.apache.xerces.xni.XNIException - Throws:
org.apache.xerces.xni.XNIException
-
characters
public void characters(org.apache.xerces.xni.XMLString text, org.apache.xerces.xni.Augmentations augs) throws org.apache.xerces.xni.XNIException - Specified by:
charactersin interfaceorg.apache.xerces.xni.XMLDocumentHandler- Throws:
org.apache.xerces.xni.XNIException
-
ignorableWhitespace
public void ignorableWhitespace(org.apache.xerces.xni.XMLString text, org.apache.xerces.xni.Augmentations augs) throws org.apache.xerces.xni.XNIException - Specified by:
ignorableWhitespacein interfaceorg.apache.xerces.xni.XMLDocumentHandler- Throws:
org.apache.xerces.xni.XNIException
-
endElement
public void endElement(org.apache.xerces.xni.QName element, org.apache.xerces.xni.Augmentations augs) throws org.apache.xerces.xni.XNIException - Specified by:
endElementin interfaceorg.apache.xerces.xni.XMLDocumentHandler- Throws:
org.apache.xerces.xni.XNIException
-
endPrefixMapping
public void endPrefixMapping(String prefix, org.apache.xerces.xni.Augmentations augs) throws org.apache.xerces.xni.XNIException - Throws:
org.apache.xerces.xni.XNIException
-
startCDATA
public void startCDATA(org.apache.xerces.xni.Augmentations augs) throws org.apache.xerces.xni.XNIException - Specified by:
startCDATAin interfaceorg.apache.xerces.xni.XMLDocumentHandler- Throws:
org.apache.xerces.xni.XNIException
-
endCDATA
public void endCDATA(org.apache.xerces.xni.Augmentations augs) throws org.apache.xerces.xni.XNIException - Specified by:
endCDATAin interfaceorg.apache.xerces.xni.XMLDocumentHandler- Throws:
org.apache.xerces.xni.XNIException
-
endDocument
public void endDocument(org.apache.xerces.xni.Augmentations augs) throws org.apache.xerces.xni.XNIException - Specified by:
endDocumentin interfaceorg.apache.xerces.xni.XMLDocumentHandler- Throws:
org.apache.xerces.xni.XNIException
-
next
This is a key method - translates XNI callbacks into XPP events (such as START_TAG, END_TAG, CONTENT). or END_DOCUMENT if no more input.- Specified by:
nextin interfaceXmlPullParser- Throws:
XmlPullParserExceptionIOException
-
setInput
Reset parser and set new input.- Specified by:
setInputin interfaceXmlPullParser- Throws:
XmlPullParserException
-
setInput
Reset parser and set new input.- Specified by:
setInputin interfaceXmlPullParser- Throws:
XmlPullParserException
-
setInput
Description copied from interface:XmlPullParserSet the input for parser.- Specified by:
setInputin interfaceXmlPullParser- Throws:
XmlPullParserException
-
reset
public void reset()Reset parser state so it can be used to parse new- Specified by:
resetin interfaceXmlPullParser
-
isAllowedMixedContent
public boolean isAllowedMixedContent()Description copied from interface:XmlPullParserIs mixed element context allowed?- Specified by:
isAllowedMixedContentin interfaceXmlPullParser
-
setAllowedMixedContent
Allow for mixed element content. Enabled by default. When disbaled element must containt either text or other elements.- Specified by:
setAllowedMixedContentin interfaceXmlPullParser- Throws:
XmlPullParserException
-
isNamespaceAware
public boolean isNamespaceAware()Description copied from interface:XmlPullParserIs parser namespace aware?- Specified by:
isNamespaceAwarein interfaceXmlPullParser
-
setNamespaceAware
Set support of namespaces. Disabled by default.- Specified by:
setNamespaceAwarein interfaceXmlPullParser- Throws:
XmlPullParserException
-
isNamespaceAttributesReporting
public boolean isNamespaceAttributesReporting()Description copied from interface:XmlPullParserIs parser going to report namespace attributes (xmlns*) ?- Specified by:
isNamespaceAttributesReportingin interfaceXmlPullParser
-
setNamespaceAttributesReporting
Make parser to report xmlns* attributes. Disabled by default. Only meaningful when namespaces are enabled (when namespaces are disabled all attributes are always reported).- Specified by:
setNamespaceAttributesReportingin interfaceXmlPullParser- Throws:
XmlPullParserException
-
getNamespaceUri
Description copied from interface:XmlPullParserReturns the namespace URI of the current element Returns null if not applicable (current event must be START_TAG or END_TAG)- Specified by:
getNamespaceUriin interfaceXmlPullParser
-
getLocalName
Description copied from interface:XmlPullParserReturns the local name of the current element (current event must be START_TAG or END_TAG)- Specified by:
getLocalNamein interfaceXmlPullParser
-
getPrefix
Description copied from interface:XmlPullParserReturns the prefix of the current element or null if elemet has no prefix. (current event must be START_TAG or END_TAG)- Specified by:
getPrefixin interfaceXmlPullParser
-
getRawName
Description copied from interface:XmlPullParserReturns the raw name (prefix + ':' + localName) of the current element (current event must be START_TAG or END_TAG)- Specified by:
getRawNamein interfaceXmlPullParser
-
getQNameLocal
Description copied from interface:XmlPullParserReturn local part of qname. For example for 'xsi:type' it returns 'type'.- Specified by:
getQNameLocalin interfaceXmlPullParser
-
getQNameUri
Description copied from interface:XmlPullParserReturn uri part of qname. It is depending on current state of parser to find what namespace uri is mapped from namespace prefix. For example for 'xsi:type' if xsi namespace prefix was declared to 'urn:foo' it will return 'urn:foo'.- Specified by:
getQNameUriin interfaceXmlPullParser- Throws:
XmlPullParserException
-
getDepth
public int getDepth()Description copied from interface:XmlPullParserReturns the current depth of the element.- Specified by:
getDepthin interfaceXmlPullParser
-
getNamespacesLength
public int getNamespacesLength(int depth) - Specified by:
getNamespacesLengthin interfaceXmlPullParser
-
readNamespacesPrefixes
public void readNamespacesPrefixes(int depth, String[] prefixes, int off, int len) throws XmlPullParserException Return namespace prefixes for element at depth- Specified by:
readNamespacesPrefixesin interfaceXmlPullParser- Throws:
XmlPullParserException
-
readNamespacesUris
public void readNamespacesUris(int depth, String[] uris, int off, int len) throws XmlPullParserException Return namespace URIs for element at depth- Specified by:
readNamespacesUrisin interfaceXmlPullParser- Throws:
XmlPullParserException
-
getPosDesc
Return string describing current position of parser in input stream as text 'at line %d (row) and column %d (colum) [seen %s...]'.- Specified by:
getPosDescin interfaceXmlPullParser
-
getLineNumber
public int getLineNumber()- Specified by:
getLineNumberin interfaceXmlPullParser
-
getColumnNumber
public int getColumnNumber()- Specified by:
getColumnNumberin interfaceXmlPullParser
-
getEventType
public byte getEventType()Description copied from interface:XmlPullParserReturns the type of the current element (START_TAG, END_TAG, CONTENT, etc)- Specified by:
getEventTypein interfaceXmlPullParser
-
isWhitespaceContent
Return true if just read CONTENT contained only white spaces.- Specified by:
isWhitespaceContentin interfaceXmlPullParser- Throws:
XmlPullParserException
-
getContentLength
Description copied from interface:XmlPullParserReturn how big is content.NOTE: parser must be on CONTENT event.
- Specified by:
getContentLengthin interfaceXmlPullParser- Throws:
XmlPullParserException
-
readContent
Return String that contains just read CONTENT.- Specified by:
readContentin interfaceXmlPullParser- Throws:
XmlPullParserException
-
readEndTag
Read value of just read END_TAG into passed as argument EndTag.- Specified by:
readEndTagin interfaceXmlPullParser- Throws:
XmlPullParserException
-
readStartTag
Read value of just read START_TAG into passed as argument StartTag.- Specified by:
readStartTagin interfaceXmlPullParser- Throws:
XmlPullParserException
-
readNodeWithoutChildren
Description copied from interface:XmlPullParserRead node: it calls readStartTag and then if parser is namespaces aware currently declared nemaspeces will be added and defaultNamespace will be set.NOTE: parser must be on START_TAG event. and all events will written into node!
- Specified by:
readNodeWithoutChildrenin interfaceXmlPullParser- Throws:
XmlPullParserException
-
readNode
Description copied from interface:XmlPullParserRead subtree into node: call readNodeWithoutChildren and then parse subtree adding children (values obtained with readXontent or readNodeWithoutChildren).NOTE: parser must be on START_TAG event. and all events will written into node!
- Specified by:
readNodein interfaceXmlPullParser- Throws:
XmlPullParserExceptionIOException
-
skipNode
If parser has just read start tag it allows to skip whoole subtree contined in this element. Returns when encounters end tag matching the start tag.- Specified by:
skipNodein interfaceXmlPullParser- Throws:
XmlPullParserExceptionIOException
-
getHardLimit
public int getHardLimit()- Specified by:
getHardLimitin interfaceXmlPullParserBufferControl
-
setHardLimit
- Specified by:
setHardLimitin interfaceXmlPullParserBufferControl- Throws:
XmlPullParserException
-
getSoftLimit
public int getSoftLimit()- Specified by:
getSoftLimitin interfaceXmlPullParserBufferControl
-
setSoftLimit
- Specified by:
setSoftLimitin interfaceXmlPullParserBufferControl- Throws:
XmlPullParserException
-
getBufferShrinkOffset
public int getBufferShrinkOffset()- Specified by:
getBufferShrinkOffsetin interfaceXmlPullParserBufferControl
-
setBufferShrinkable
- Specified by:
setBufferShrinkablein interfaceXmlPullParserBufferControl- Throws:
XmlPullParserException
-
isBufferShrinkable
public boolean isBufferShrinkable()- Specified by:
isBufferShrinkablein interfaceXmlPullParserBufferControl
-
getEventStart
public int getEventStart()- Specified by:
getEventStartin interfaceXmlPullParserEventPosition
-
getEventEnd
public int getEventEnd()- Specified by:
getEventEndin interfaceXmlPullParserEventPosition
-
getEventBuffer
public char[] getEventBuffer()Description copied from interface:XmlPullParserEventPositionNOTE: This may be internal buffer and is valud only until call to method next()- do NOT attempt modify !
- Specified by:
getEventBufferin interfaceXmlPullParserEventPosition
-
ensureCapacity
protected void ensureCapacity(int size) Make sure that we have enough space to keep element stack if passed size. -
ensureAttribs
protected void ensureAttribs(int size) Make sure that in attributes temporary array is enough space. -
resetState
protected void resetState()
-