org.gjt.xpp.x2impl.x2pullparser

Class X2PullParser

Implemented Interfaces:
XmlPullParser, XmlPullParserBufferControl, XmlPullParserEventPosition, XMLDocumentHandler, XMLErrorHandler

public class X2PullParser
extends java.lang.Object
implements XmlPullParser, XmlPullParserEventPosition, XmlPullParserBufferControl, XMLErrorHandler, XMLDocumentHandler

This is Xerces 2 driver that uses XNI pull parsing capabilities to implement XML Pull Parser API. Advantages: Limitations:
Author:
Aleksander Slominski

Nested Class Summary

protected class
X2PullParser.CumulativeReader

Field Summary

protected static String
NAMESPACES_FEATURE_ID
protected static String
NAMESPACE_PREFIXES_FEATURE_ID
String
POS_ABSOLUTE_END
String
POS_ABSOLUTE_START
protected boolean
allowedMixedContent
protected X2Attribute[]
attrPos
temporary array of current attributes
protected int
attrPosEnd
index for last attribute in attrPos array
protected int
attrPosSize
size of attrPos array
protected QName
attrQName
protected StringBuffer
contentBuf
Content of current element if in CONTENT state
protected int
contentEventEnd
protected int
contentEventStart
protected X2PullParser.CumulativeReader
cumulativeReader
protected boolean
disableOffsetTracking
protected X2ElementContent[]
elStack
temprary array to keep ElementContent stack
protected int
elStackDepth
how many elements are on elStack
protected int
elStackSize
size of elStack array
protected boolean
emptyElement
Have we read empty element?
protected int
eventEnd
end position of current event in tokenizer biffer
protected int
eventStart
start position of current event in tokenizer biffer
protected XMLDocumentSource
fDocumentSource
Document source
protected boolean
gotContent
protected XMLInputSource
inputSource
protected XMLLocator
locator
protected boolean
mixInElement
protected boolean
needToSetInput
protected byte
nextState
protected boolean
nonWhitespaceContent
protected Hashtable
prefix2Ns
mapping of names prefixes to uris
protected XMLPullParserConfiguration
pullParserConfiguration
protected boolean
reportNsAttribs
should parser report namespace xmlns* attributes ?
protected boolean
seenCR
protected boolean
seenContent
protected Exception
seenException
protected boolean
seenRootElement
Have we seen root element
protected boolean
shrinkable
protected boolean
startTagInitialized
protected byte
state
what is current event type as returned from next()?
protected boolean
supportNs
should parser support namespaces?

Fields inherited from interface org.gjt.xpp.XmlPullParser

CONTENT, END_DOCUMENT, END_TAG, START_TAG

Constructor Summary

X2PullParser()
Create instance of pull parser.

Method Summary

void
characters(XMLString text, Augmentations augs)
void
comment(XMLString text, Augmentations augs)
void
doctypeDecl(String rootElement, String publicId, String systemId, Augmentations augs)
void
emptyElement(QName element, XMLAttributes attributes, Augmentations augs)
void
endCDATA(Augmentations augs)
void
endDocument(Augmentations augs)
void
endElement(QName element, Augmentations augs)
void
endEntity(String name, Augmentations augs)
void
endGeneralEntity(String name, Augmentations augs)
void
endPrefixMapping(String prefix, Augmentations augs)
protected void
ensureAttribs(int size)
Make sure that in attributes temporary array is enough space.
protected void
ensureCapacity(int size)
Make sure that we have enough space to keep element stack if passed size.
void
error(String domain, String key, XMLParseException ex)
Error.
void
fatalError(String domain, String key, XMLParseException ex)
Fatal error.
int
getBufferShrinkOffset()
int
getColumnNumber()
int
getContentLength()
Return how big is content.
int
getDepth()
Returns the current depth of the element.
XMLDocumentSource
getDocumentSource()
Returns the document source
char[]
getEventBuffer()
int
getEventEnd()
int
getEventStart()
byte
getEventType()
Returns the type of the current element (START_TAG, END_TAG, CONTENT, etc)
int
getHardLimit()
int
getLineNumber()
String
getLocalName()
Returns the local name of the current element (current event must be START_TAG or END_TAG)
String
getNamespaceUri()
Returns the namespace URI of the current element Returns null if not applicable (current event must be START_TAG or END_TAG)
int
getNamespacesLength(int depth)
String
getPosDesc()
Return string describing current position of parser in input stream as text 'at line %d (row) and column %d (colum) [seen %s...]'.
String
getPrefix()
Returns the prefix of the current element or null if elemet has no prefix.
String
getQNameLocal(String qName)
Return local part of qname.
String
getQNameUri(String qName)
Return uri part of qname.
String
getRawName()
Returns the raw name (prefix + ':' + localName) of the current element (current event must be START_TAG or END_TAG)
int
getSoftLimit()
void
ignorableWhitespace(XMLString text, Augmentations augs)
boolean
isAllowedMixedContent()
Is mixed element context allowed?
boolean
isBufferShrinkable()
boolean
isNamespaceAttributesReporting()
Is parser going to report namespace attributes (xmlns*) ?
boolean
isNamespaceAware()
Is parser namespace aware?
boolean
isWhitespaceContent()
Return true if just read CONTENT contained only white spaces.
byte
next()
This is a key method - translates XNI callbacks into XPP events (such as START_TAG, END_TAG, CONTENT).
void
processingInstruction(String target, XMLString data, Augmentations augs)
String
readContent()
Return String that contains just read CONTENT.
void
readEndTag(XmlEndTag etag)
Read value of just read END_TAG into passed as argument EndTag.
void
readNamespacesPrefixes(int depth, String[] prefixes, int off, int len)
Return namespace prefixes for element at depth
void
readNamespacesUris(int depth, String[] uris, int off, int len)
Return namespace URIs for element at depth
byte
readNode(XmlNode node)
Read subtree into node: call readNodeWithoutChildren and then parse subtree adding children (values obtained with readXontent or readNodeWithoutChildren).
void
readNodeWithoutChildren(XmlNode node)
Read node: it calls readStartTag and then if parser is namespaces aware currently declared nemaspeces will be added and defaultNamespace will be set.
void
readStartTag(XmlStartTag stag)
Read value of just read START_TAG into passed as argument StartTag.
void
reset()
Reset parser state so it can be used to parse new
protected void
resetState()
void
setAllowedMixedContent(boolean enable)
Allow for mixed element content.
void
setBufferShrinkable(boolean shrinkable)
void
setDocumentSource(XMLDocumentSource source)
Sets the document source
void
setHardLimit(int value)
void
setInput(Reader reader)
Reset parser and set new input.
void
setInput(char[] buf)
Reset parser and set new input.
void
setInput(char[] buf, int off, int len)
Set the input for parser.
void
setNamespaceAttributesReporting(boolean enable)
Make parser to report xmlns* attributes.
void
setNamespaceAware(boolean awareness)
Set support of namespaces.
void
setSoftLimit(int value)
byte
skipNode()
If parser has just read start tag it allows to skip whoole subtree contined in this element.
void
startCDATA(Augmentations augs)
void
startDocument(XMLLocator locator, String encoding, Augmentations augs)
void
startDocument(XMLLocator locator, String encoding, NamespaceContext namespaceContext, Augmentations augs)
void
startElement(QName element, XMLAttributes attributes, Augmentations augs)
void
startEntity(String name, String publicId, String systemId, String baseSystemId, String encoding, Augmentations augs)
void
startGeneralEntity(String name, XMLResourceIdentifier identifier, String encoding, Augmentations augs)
void
startPrefixMapping(String prefix, String uri, Augmentations augs)
void
textDecl(String version, String encoding, Augmentations augs)
void
warning(String domain, String key, XMLParseException ex)
Warning.
void
xmlDecl(String version, String encoding, String standalone, Augmentations augs)

Field Details

NAMESPACES_FEATURE_ID

protected static final String NAMESPACES_FEATURE_ID

NAMESPACE_PREFIXES_FEATURE_ID

protected static final String NAMESPACE_PREFIXES_FEATURE_ID

POS_ABSOLUTE_END

public final String POS_ABSOLUTE_END

POS_ABSOLUTE_START

public final String POS_ABSOLUTE_START

allowedMixedContent

protected boolean allowedMixedContent

attrPos

protected X2Attribute[] attrPos
temporary array of current attributes

attrPosEnd

protected int attrPosEnd
index for last attribute in attrPos array

attrPosSize

protected int attrPosSize
size of attrPos array

attrQName

protected QName attrQName

contentBuf

protected StringBuffer contentBuf
Content of current element if in CONTENT state

contentEventEnd

protected int contentEventEnd

contentEventStart

protected int contentEventStart

cumulativeReader

protected X2PullParser.CumulativeReader cumulativeReader

disableOffsetTracking

protected boolean disableOffsetTracking

elStack

protected X2ElementContent[] elStack
temprary array to keep ElementContent stack

elStackDepth

protected int elStackDepth
how many elements are on elStack

elStackSize

protected int elStackSize
size of elStack array

emptyElement

protected boolean emptyElement
Have we read empty element?

eventEnd

protected int eventEnd
end position of current event in tokenizer biffer

eventStart

protected int eventStart
start position of current event in tokenizer biffer

fDocumentSource

protected XMLDocumentSource fDocumentSource
Document source

gotContent

protected boolean gotContent

inputSource

protected XMLInputSource inputSource

locator

protected XMLLocator locator

mixInElement

protected boolean mixInElement

needToSetInput

protected boolean needToSetInput

nextState

protected byte nextState

nonWhitespaceContent

protected boolean nonWhitespaceContent

prefix2Ns

protected Hashtable prefix2Ns
mapping of names prefixes to uris

pullParserConfiguration

protected XMLPullParserConfiguration pullParserConfiguration

reportNsAttribs

protected boolean reportNsAttribs
should parser report namespace xmlns* attributes ?

seenCR

protected boolean seenCR

seenContent

protected boolean seenContent

seenException

protected Exception seenException

seenRootElement

protected boolean seenRootElement
Have we seen root element

shrinkable

protected boolean shrinkable

startTagInitialized

protected boolean startTagInitialized

state

protected byte state
what is current event type as returned from next()?

supportNs

protected boolean supportNs
should parser support namespaces?

Constructor Details

X2PullParser

public X2PullParser()
            throws XmlPullParserException
Create instance of pull parser.

Method Details

characters

public void characters(XMLString text,
                       Augmentations augs)
            throws XNIException

comment

public void comment(XMLString text,
                    Augmentations augs)
            throws XNIException

doctypeDecl

public void doctypeDecl(String rootElement,
                        String publicId,
                        String systemId,
                        Augmentations augs)
            throws XNIException

emptyElement

public void emptyElement(QName element,
                         XMLAttributes attributes,
                         Augmentations augs)
            throws XNIException

endCDATA

public void endCDATA(Augmentations augs)
            throws XNIException

endDocument

public void endDocument(Augmentations augs)
            throws XNIException

endElement

public void endElement(QName element,
                       Augmentations augs)
            throws XNIException

endEntity

public void endEntity(String name,
                      Augmentations augs)
            throws XNIException

endGeneralEntity

public void endGeneralEntity(String name,
                             Augmentations augs)
            throws XNIException

endPrefixMapping

public void endPrefixMapping(String prefix,
                             Augmentations augs)
            throws XNIException

ensureAttribs

protected void ensureAttribs(int size)
Make sure that in attributes temporary array is enough space.

ensureCapacity

protected void ensureCapacity(int size)
Make sure that we have enough space to keep element stack if passed size.

error

public void error(String domain,
                  String key,
                  XMLParseException ex)
            throws XNIException
Error.

fatalError

public void fatalError(String domain,
                       String key,
                       XMLParseException ex)
            throws XNIException
Fatal error.

getBufferShrinkOffset

public int getBufferShrinkOffset()
Specified by:
getBufferShrinkOffset in interface XmlPullParserBufferControl

getColumnNumber

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

getContentLength

public int getContentLength()
            throws XmlPullParserException
Return how big is content.

NOTE: parser must be on CONTENT event.

Specified by:
getContentLength in interface XmlPullParser

getDepth

public int getDepth()
Returns the current depth of the element.
Specified by:
getDepth in interface XmlPullParser

getDocumentSource

public XMLDocumentSource getDocumentSource()
Returns the document source

getEventBuffer

public char[] getEventBuffer()
Specified by:
getEventBuffer in interface XmlPullParserEventPosition

getEventEnd

public int getEventEnd()
Specified by:
getEventEnd in interface XmlPullParserEventPosition

getEventStart

public int getEventStart()
Specified by:
getEventStart in interface XmlPullParserEventPosition

getEventType

public byte getEventType()
Returns the type of the current element (START_TAG, END_TAG, CONTENT, etc)
Specified by:
getEventType in interface XmlPullParser

getHardLimit

public int getHardLimit()
Specified by:
getHardLimit in interface XmlPullParserBufferControl

getLineNumber

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

getLocalName

public String getLocalName()
Returns the local name of the current element (current event must be START_TAG or END_TAG)
Specified by:
getLocalName in interface XmlPullParser

getNamespaceUri

public String getNamespaceUri()
Returns the namespace URI of the current element Returns null if not applicable (current event must be START_TAG or END_TAG)
Specified by:
getNamespaceUri in interface XmlPullParser

getNamespacesLength

public int getNamespacesLength(int depth)
Specified by:
getNamespacesLength in interface XmlPullParser

getPosDesc

public String 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:
getPosDesc in interface XmlPullParser

getPrefix

public String getPrefix()
Returns the prefix of the current element or null if elemet has no prefix. (current event must be START_TAG or END_TAG)
Specified by:
getPrefix in interface XmlPullParser

getQNameLocal

public String getQNameLocal(String qName)
Return local part of qname. For example for 'xsi:type' it returns 'type'.
Specified by:
getQNameLocal in interface XmlPullParser

getQNameUri

public String getQNameUri(String qName)
            throws XmlPullParserException
Return 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:
getQNameUri in interface XmlPullParser

getRawName

public String getRawName()
Returns the raw name (prefix + ':' + localName) of the current element (current event must be START_TAG or END_TAG)
Specified by:
getRawName in interface XmlPullParser

getSoftLimit

public int getSoftLimit()
Specified by:
getSoftLimit in interface XmlPullParserBufferControl

ignorableWhitespace

public void ignorableWhitespace(XMLString text,
                                Augmentations augs)
            throws XNIException

isAllowedMixedContent

public boolean isAllowedMixedContent()
Is mixed element context allowed?
Specified by:
isAllowedMixedContent in interface XmlPullParser

isBufferShrinkable

public boolean isBufferShrinkable()
Specified by:
isBufferShrinkable in interface XmlPullParserBufferControl

isNamespaceAttributesReporting

public boolean isNamespaceAttributesReporting()
Is parser going to report namespace attributes (xmlns*) ?
Specified by:
isNamespaceAttributesReporting in interface XmlPullParser

isNamespaceAware

public boolean isNamespaceAware()
Is parser namespace aware?
Specified by:
isNamespaceAware in interface XmlPullParser

isWhitespaceContent

public boolean isWhitespaceContent()
            throws XmlPullParserException
Return true if just read CONTENT contained only white spaces.
Specified by:
isWhitespaceContent in interface XmlPullParser

next

public byte next()
            throws XmlPullParserException,
                   IOException
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:
next in interface XmlPullParser

processingInstruction

public void processingInstruction(String target,
                                  XMLString data,
                                  Augmentations augs)
            throws XNIException

readContent

public String readContent()
            throws XmlPullParserException
Return String that contains just read CONTENT.
Specified by:
readContent in interface XmlPullParser

readEndTag

public void readEndTag(XmlEndTag etag)
            throws XmlPullParserException
Read value of just read END_TAG into passed as argument EndTag.
Specified by:
readEndTag in interface XmlPullParser

readNamespacesPrefixes

public void readNamespacesPrefixes(int depth,
                                   String[] prefixes,
                                   int off,
                                   int len)
            throws XmlPullParserException
Return namespace prefixes for element at depth
Specified by:
readNamespacesPrefixes in interface XmlPullParser

readNamespacesUris

public void readNamespacesUris(int depth,
                               String[] uris,
                               int off,
                               int len)
            throws XmlPullParserException
Return namespace URIs for element at depth
Specified by:
readNamespacesUris in interface XmlPullParser

readNode

public byte readNode(XmlNode node)
            throws XmlPullParserException,
                   IOException
Read 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:
readNode in interface XmlPullParser

readNodeWithoutChildren

public void readNodeWithoutChildren(XmlNode node)
            throws XmlPullParserException
Read 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:
readNodeWithoutChildren in interface XmlPullParser

readStartTag

public void readStartTag(XmlStartTag stag)
            throws XmlPullParserException
Read value of just read START_TAG into passed as argument StartTag.
Specified by:
readStartTag in interface XmlPullParser

reset

public void reset()
Reset parser state so it can be used to parse new
Specified by:
reset in interface XmlPullParser

resetState

protected void resetState()

setAllowedMixedContent

public void setAllowedMixedContent(boolean enable)
            throws XmlPullParserException
Allow for mixed element content. Enabled by default. When disbaled element must containt either text or other elements.
Specified by:
setAllowedMixedContent in interface XmlPullParser

setBufferShrinkable

public void setBufferShrinkable(boolean shrinkable)
            throws XmlPullParserException
Specified by:
setBufferShrinkable in interface XmlPullParserBufferControl

setDocumentSource

public void setDocumentSource(XMLDocumentSource source)
Sets the document source

setHardLimit

public void setHardLimit(int value)
            throws XmlPullParserException
Specified by:
setHardLimit in interface XmlPullParserBufferControl

setInput

public void setInput(Reader reader)
            throws XmlPullParserException
Reset parser and set new input.
Specified by:
setInput in interface XmlPullParser

setInput

public void setInput(char[] buf)
            throws XmlPullParserException
Reset parser and set new input.
Specified by:
setInput in interface XmlPullParser

setInput

public void setInput(char[] buf,
                     int off,
                     int len)
            throws XmlPullParserException
Set the input for parser.
Specified by:
setInput in interface XmlPullParser

setNamespaceAttributesReporting

public void setNamespaceAttributesReporting(boolean enable)
            throws XmlPullParserException
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:
setNamespaceAttributesReporting in interface XmlPullParser

setNamespaceAware

public void setNamespaceAware(boolean awareness)
            throws XmlPullParserException
Set support of namespaces. Disabled by default.
Specified by:
setNamespaceAware in interface XmlPullParser

setSoftLimit

public void setSoftLimit(int value)
            throws XmlPullParserException
Specified by:
setSoftLimit in interface XmlPullParserBufferControl

skipNode

public byte skipNode()
            throws XmlPullParserException,
                   IOException
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:
skipNode in interface XmlPullParser

startCDATA

public void startCDATA(Augmentations augs)
            throws XNIException

startDocument

public void startDocument(XMLLocator locator,
                          String encoding,
                          Augmentations augs)
            throws XNIException

startDocument

public void startDocument(XMLLocator locator,
                          String encoding,
                          NamespaceContext namespaceContext,
                          Augmentations augs)
            throws XNIException

startElement

public void startElement(QName element,
                         XMLAttributes attributes,
                         Augmentations augs)
            throws XNIException

startEntity

public void startEntity(String name,
                        String publicId,
                        String systemId,
                        String baseSystemId,
                        String encoding,
                        Augmentations augs)
            throws XNIException

startGeneralEntity

public void startGeneralEntity(String name,
                               XMLResourceIdentifier identifier,
                               String encoding,
                               Augmentations augs)
            throws XNIException

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri,
                               Augmentations augs)
            throws XNIException

textDecl

public void textDecl(String version,
                     String encoding,
                     Augmentations augs)
            throws XNIException

warning

public void warning(String domain,
                    String key,
                    XMLParseException ex)
            throws XNIException
Warning.

xmlDecl

public void xmlDecl(String version,
                    String encoding,
                    String standalone,
                    Augmentations augs)
            throws XNIException

Copyright (c) 2003 IU Extreme! Lab http://www.extreme.indiana.edu/ All Rights Reserved.

Note this package is deprecated by
XPP3 that implements XmlPull API