org.codehaus.plexus.util.xml.pull

Class MXParser

Implemented Interfaces:
XmlPullParser

public class MXParser
extends java.lang.Object
implements XmlPullParser

Absolutely minimal implementaion of XMLPULL V1 API
Author:
Aleksander Slominski

Field Summary

protected static String
FEATURE_NAMES_INTERNED
protected static String
FEATURE_XML_ROUNDTRIP
protected static int
LOOKUP_MAX
protected static char
LOOKUP_MAX_CHAR
protected static char[]
NCODING
protected static char[]
NO
protected static String
PROPERTY_LOCATION
protected static String
PROPERTY_XMLDECL_CONTENT
protected static String
PROPERTY_XMLDECL_STANDALONE
protected static String
PROPERTY_XMLDECL_VERSION
protected static int
READ_CHUNK_SIZE
protected static char[]
TANDALONE
private static boolean
TRACE_SIZING
protected static char[]
VERSION
protected static String
XMLNS_URI
protected static String
XML_URI
protected static char[]
YES
protected boolean
allStringsInterned
Implementation notice: the is instance variable that controls if newString() is interning.
protected int
attributeCount
protected String[]
attributeName
protected int[]
attributeNameHash
protected String[]
attributePrefix
protected String[]
attributeUri
protected String[]
attributeValue
protected char[]
buf
protected int
bufAbsoluteStart
protected int
bufEnd
protected int
bufLoadFactor
protected int
bufSoftLimit
protected int
bufStart
protected char[]
charRefOneCharBuf
protected int
columnNumber
protected int
depth
protected String[]
elName
protected int[]
elNamespaceCount
protected String[]
elPrefix
protected char[][]
elRawName
protected int[]
elRawNameEnd
protected int[]
elRawNameLine
protected String[]
elUri
protected boolean
emptyElementTag
protected int
entityEnd
protected String[]
entityName
protected char[][]
entityNameBuf
protected int[]
entityNameHash
protected String
entityRefName
protected String[]
entityReplacement
protected char[][]
entityReplacementBuf
protected int
eventType
protected String
inputEncoding
protected int
lineNumber
protected String
location
protected static boolean[]
lookupNameChar
protected static boolean[]
lookupNameStartChar
protected int
namespaceEnd
protected String[]
namespacePrefix
protected int[]
namespacePrefixHash
protected String[]
namespaceUri
protected boolean
pastEndTag
protected char[]
pc
protected int
pcEnd
protected int
pcStart
protected int
pos
protected int
posEnd
protected int
posStart
protected boolean
preventBufferCompaction
protected boolean
processNamespaces
protected boolean
reachedEnd
protected Reader
reader
protected boolean
roundtripSupported
protected boolean
seenAmpersand
protected boolean
seenDocdecl
protected boolean
seenEndTag
protected boolean
seenMarkup
protected boolean
seenRoot
protected boolean
seenStartTag
protected String
text
protected boolean
tokenize
protected boolean
usePC
protected String
xmlDeclContent
protected Boolean
xmlDeclStandalone
protected String
xmlDeclVersion

Fields inherited from interface org.codehaus.plexus.util.xml.pull.XmlPullParser

CDSECT, COMMENT, DOCDECL, END_DOCUMENT, END_TAG, ENTITY_REF, FEATURE_PROCESS_DOCDECL, FEATURE_PROCESS_NAMESPACES, FEATURE_REPORT_NAMESPACE_ATTRIBUTES, FEATURE_VALIDATION, IGNORABLE_WHITESPACE, NO_NAMESPACE, PROCESSING_INSTRUCTION, START_DOCUMENT, START_TAG, TEXT, TYPES

Constructor Summary

MXParser()

Method Summary

void
defineEntityReplacementText(String entityName, String replacementText)
Set new value for entity replacement text as defined in XML 1.0 Section 4.5 Construction of Internal Entity Replacement Text.
protected void
ensureAttributesCapacity(int size)
Make sure that in attributes temporary array is enough space.
protected void
ensureElementsCapacity()
Make sure that we have enough space to keep element stack if passed size.
protected void
ensureEntityCapacity()
protected void
ensureNamespacesCapacity(int size)
protected void
ensurePC(int end)
protected static int
fastHash(ch[] , int off, int len)
simplistic implementation of hash function that has constant time to compute - so it also means diminishing hash quality for long strings but for XML parsing it should be good enough ...
protected void
fillBuf()
private static int
findFragment(int bufMinPos, char[] b, int start, int end)
int
getAttributeCount()
Returns the number of attributes of the current start tag, or -1 if the current event type is not START_TAG
String
getAttributeName(int index)
Returns the local name of the specified attribute if namespaces are enabled or just attribute name if namespaces are disabled.
String
getAttributeNamespace(int index)
Returns the namespace URI of the attribute with the given index (starts from 0).
String
getAttributePrefix(int index)
Returns the prefix of the specified attribute Returns null if the element has no prefix.
String
getAttributeType(int index)
Returns the type of the specified attribute If parser is non-validating it MUST return CDATA.
String
getAttributeValue(String namespace, String name)
Returns the attributes value identified by namespace URI and namespace localName.
String
getAttributeValue(int index)
Returns the given attributes value.
int
getColumnNumber()
Returns the current column number, starting from 0.
int
getDepth()
Returns the current depth of the element.
int
getEventType()
Returns the type of the current event (START_TAG, END_TAG, TEXT, etc.)
boolean
getFeature(String name)
Unknown properties are always returned as false
String
getInputEncoding()
Returns the input encoding if known, null otherwise.
int
getLineNumber()
Returns the current line number, starting from 1.
String
getName()
For START_TAG or END_TAG events, the (local) name of the current element is returned when namespaces are enabled.
String
getNamespace()
Returns the namespace URI of the current element.
String
getNamespace(String prefix)
Returns the URI corresponding to the given prefix, depending on current state of the parser.
int
getNamespaceCount(int depth)
Returns the numbers of elements in the namespace stack for the given depth.
String
getNamespacePrefix(int pos)
Returns the namespace prefixe for the given position in the namespace stack.
String
getNamespaceUri(int pos)
Returns the namespace URI for the given position in the namespace stack If the position is out of range, an exception is thrown.
String
getPositionDescription()
Return string describing current position of parsers as text 'STATE [seen %s...] @line:column'.
String
getPrefix()
Returns the prefix of the current element.
Object
getProperty(String name)
Look up the value of a property.
String
getText()
Returns the text content of the current event as String.
char[]
getTextCharacters(int[] holderForStartAndLength)
Returns the buffer that contains the text of the current event, as well as the start offset and length relevant for the current event.
boolean
isAttributeDefault(int index)
Returns if the specified attribute was not in input was declared in XML.
boolean
isEmptyElementTag()
Returns true if the current event is START_TAG and the tag is degenerated (e.g.
protected boolean
isNameChar(char ch)
protected boolean
isNameStartChar(char ch)
protected boolean
isS(char ch)
boolean
isWhitespace()
Checks whether the current TEXT event contains only whitespace characters.
protected void
joinPC()
protected char[]
lookuEntityReplacement(int entitNameLen)
protected char
more()
protected String
newString(char[] cbuf, int off, int len)
protected String
newStringIntern(char[] cbuf, int off, int len)
int
next()
Get next parsing event - element content wil be coalesced and only one TEXT event must be returned for whole element content (comments and processing instructions will be ignored and emtity references must be expanded or exception mus be thrown if entity reerence can not be exapnded).
protected int
nextImpl()
int
nextTag()
Call next() and return event if it is START_TAG or END_TAG otherwise throw an exception.
String
nextText()
If current event is START_TAG then if next element is TEXT then element content is returned or if next event is END_TAG then empty string is returned, otherwise exception is thrown.
int
nextToken()
This method works similarly to next() but will expose additional event types (COMMENT, CDSECT, DOCDECL, ENTITY_REF, PROCESSING_INSTRUCTION, or IGNORABLE_WHITESPACE) if they are available in input.
protected char
parseAttribute()
protected void
parseCDSect(boolean hadCharData)
protected void
parseComment()
protected void
parseDocdecl()
int
parseEndTag()
protected char[]
parseEntityRef()
protected int
parseEpilog()
protected boolean
parsePI()
protected int
parseProlog()
int
parseStartTag()
protected void
parseXmlDecl(char ch)
protected void
parseXmlDeclWithVersion(int versionStart, int versionEnd)
protected String
printable(String s)
protected String
printable(char ch)
void
require(int type, String namespace, String name)
Test if the current event is of the given type and if the namespace and name do match.
protected char
requireInput(char ch, char[] input)
protected char
requireNextS()
protected void
reset()
protected void
resetStringCache()
void
setFeature(String name, boolean state)
Method setFeature
void
setInput(Reader in)
Set the input source for parser to the given reader and resets the parser.
void
setInput(java.io.InputStream inputStream, String inputEncoding)
private static void
setName(char ch)
private static void
setNameStart(char ch)
void
setProperty(String name, Object value)
Set the value of a property.
protected char
skipS(char ch)
void
skipSubTree()
Skip sub tree that is currently porser positioned on.

Field Details

FEATURE_NAMES_INTERNED

protected static final String FEATURE_NAMES_INTERNED

FEATURE_XML_ROUNDTRIP

protected static final String FEATURE_XML_ROUNDTRIP

LOOKUP_MAX

protected static final int LOOKUP_MAX
Field Value:
1024

LOOKUP_MAX_CHAR

protected static final char LOOKUP_MAX_CHAR
Field Value:
'\u0400'

NCODING

protected static final char[] NCODING

NO

protected static final char[] NO

PROPERTY_LOCATION

protected static final String PROPERTY_LOCATION

PROPERTY_XMLDECL_CONTENT

protected static final String PROPERTY_XMLDECL_CONTENT

PROPERTY_XMLDECL_STANDALONE

protected static final String PROPERTY_XMLDECL_STANDALONE

PROPERTY_XMLDECL_VERSION

protected static final String PROPERTY_XMLDECL_VERSION

READ_CHUNK_SIZE

protected static final int READ_CHUNK_SIZE
Field Value:
8192

TANDALONE

protected static final char[] TANDALONE

TRACE_SIZING

private static final boolean TRACE_SIZING
Field Value:
false

VERSION

protected static final char[] VERSION

XMLNS_URI

protected static final String XMLNS_URI

XML_URI

protected static final String XML_URI

YES

protected static final char[] YES

allStringsInterned

protected boolean allStringsInterned
Implementation notice: the is instance variable that controls if newString() is interning.

NOTE: newStringIntern always returns interned strings and newString MAY return interned String depending on this variable.

NOTE: by default in this minimal implementation it is false!


attributeCount

protected int attributeCount

attributeName

protected String[] attributeName

attributeNameHash

protected int[] attributeNameHash

attributePrefix

protected String[] attributePrefix

attributeUri

protected String[] attributeUri

attributeValue

protected String[] attributeValue

buf

protected char[] buf

bufAbsoluteStart

protected int bufAbsoluteStart

bufEnd

protected int bufEnd

bufLoadFactor

protected int bufLoadFactor

bufSoftLimit

protected int bufSoftLimit

bufStart

protected int bufStart

charRefOneCharBuf

protected char[] charRefOneCharBuf

columnNumber

protected int columnNumber

depth

protected int depth

elName

protected String[] elName

elNamespaceCount

protected int[] elNamespaceCount

elPrefix

protected String[] elPrefix

elRawName

protected char[][] elRawName

elRawNameEnd

protected int[] elRawNameEnd

elRawNameLine

protected int[] elRawNameLine

elUri

protected String[] elUri

emptyElementTag

protected boolean emptyElementTag

entityEnd

protected int entityEnd

entityName

protected String[] entityName

entityNameBuf

protected char[][] entityNameBuf

entityNameHash

protected int[] entityNameHash

entityRefName

protected String entityRefName

entityReplacement

protected String[] entityReplacement

entityReplacementBuf

protected char[][] entityReplacementBuf

eventType

protected int eventType

inputEncoding

protected String inputEncoding

lineNumber

protected int lineNumber

location

protected String location

lookupNameChar

protected static boolean[] lookupNameChar

lookupNameStartChar

protected static boolean[] lookupNameStartChar

namespaceEnd

protected int namespaceEnd

namespacePrefix

protected String[] namespacePrefix

namespacePrefixHash

protected int[] namespacePrefixHash

namespaceUri

protected String[] namespaceUri

pastEndTag

protected boolean pastEndTag

pc

protected char[] pc

pcEnd

protected int pcEnd

pcStart

protected int pcStart

pos

protected int pos

posEnd

protected int posEnd

posStart

protected int posStart

preventBufferCompaction

protected boolean preventBufferCompaction

processNamespaces

protected boolean processNamespaces

reachedEnd

protected boolean reachedEnd

reader

protected Reader reader

roundtripSupported

protected boolean roundtripSupported

seenAmpersand

protected boolean seenAmpersand

seenDocdecl

protected boolean seenDocdecl

seenEndTag

protected boolean seenEndTag

seenMarkup

protected boolean seenMarkup

seenRoot

protected boolean seenRoot

seenStartTag

protected boolean seenStartTag

text

protected String text

tokenize

protected boolean tokenize

usePC

protected boolean usePC

xmlDeclContent

protected String xmlDeclContent

xmlDeclStandalone

protected Boolean xmlDeclStandalone

xmlDeclVersion

protected String xmlDeclVersion

Constructor Details

MXParser

public MXParser()

Method Details

defineEntityReplacementText

public void defineEntityReplacementText(String entityName,
                                        String replacementText)
            throws XmlPullParserException
Set new value for entity replacement text as defined in XML 1.0 Section 4.5 Construction of Internal Entity Replacement Text. If FEATURE_PROCESS_DOCDECL or FEATURE_VALIDATION are set, calling this function will result in an exception -- when processing of DOCDECL is enabled, there is no need to the entity replacement text manually.

The motivation for this function is to allow very small implementations of XMLPULL that will work in J2ME environments. Though these implementations may not be able to process the document type declaration, they still can work with known DTDs by using this function.

Please notes: The given value is used literally as replacement text and it corresponds to declaring entity in DTD that has all special characters escaped: left angle bracket is replaced with <, ampersnad with & and so on.

Note: The given value is the literal replacement text and must not contain any other entity reference (if it contains any entity reference there will be no further replacement).

Note: The list of pre-defined entity names will always contain standard XML entities such as amp (&), lt (<), gt (>), quot ("), and apos ('). Those cannot be redefined by this method!

Specified by:
defineEntityReplacementText in interface XmlPullParser

ensureAttributesCapacity

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

ensureElementsCapacity

protected void ensureElementsCapacity()
Make sure that we have enough space to keep element stack if passed size. It will always create one additional slot then current depth

ensureEntityCapacity

protected void ensureEntityCapacity()

ensureNamespacesCapacity

protected void ensureNamespacesCapacity(int size)

ensurePC

protected void ensurePC(int end)

fastHash

protected static final int fastHash(ch[] ,
                                    int off,
                                    int len)
simplistic implementation of hash function that has constant time to compute - so it also means diminishing hash quality for long strings but for XML parsing it should be good enough ...

fillBuf

protected void fillBuf()
            throws IOException,
                   XmlPullParserException

findFragment

private static int findFragment(int bufMinPos,
                                char[] b,
                                int start,
                                int end)

getAttributeCount

public int getAttributeCount()
Returns the number of attributes of the current start tag, or -1 if the current event type is not START_TAG
Specified by:
getAttributeCount in interface XmlPullParser

getAttributeName

public String getAttributeName(int index)
Returns the local name of the specified attribute if namespaces are enabled or just attribute name if namespaces are disabled. Throws an IndexOutOfBoundsException if the index is out of range or current event type is not START_TAG.
Specified by:
getAttributeName in interface XmlPullParser
Parameters:
Returns:
attribute name (null is never returned)

getAttributeNamespace

public String getAttributeNamespace(int index)
Specified by:
getAttributeNamespace in interface XmlPullParser
Parameters:
Returns:
attribute namespace, empty string ("") is returned if namesapces processing is not enabled or namespaces processing is enabled but attribute has no namespace (it has no prefix).

getAttributePrefix

public String getAttributePrefix(int index)
Returns the prefix of the specified attribute Returns null if the element has no prefix. If namespaces are disabled it will always return null. Throws an IndexOutOfBoundsException if the index is out of range or current event type is not START_TAG.
Specified by:
getAttributePrefix in interface XmlPullParser
Parameters:
Returns:
attribute prefix or null if namespaces processing is not enabled.

getAttributeType

public String getAttributeType(int index)
Returns the type of the specified attribute If parser is non-validating it MUST return CDATA.
Specified by:
getAttributeType in interface XmlPullParser
Parameters:
Returns:
attribute type (null is never returned)

getAttributeValue

public String getAttributeValue(String namespace,
                                String name)
Specified by:
getAttributeValue in interface XmlPullParser
Parameters:
namespace - Namespace of the attribute if namespaces are enabled otherwise must be null
name - If namespaces enabled local name of attribute otherwise just attribute name
Returns:
value of attribute or null if attribute with given name does not exist

getAttributeValue

public String getAttributeValue(int index)
Specified by:
getAttributeValue in interface XmlPullParser
Parameters:
Returns:
value of attribute (null is never returned)

getColumnNumber

public int getColumnNumber()
Returns the current column number, starting from 0. When the parser does not know the current column number or can not determine it, -1 is returned (e.g. for WBXML).
Specified by:
getColumnNumber in interface XmlPullParser
Returns:
current column number or -1 if unknown.

getDepth

public int getDepth()
Returns the current depth of the element. Outside the root element, the depth is 0. The depth is incremented by 1 when a start tag is reached. The depth is decremented AFTER the end tag event was observed.
 <!-- outside -->     0
 <root>                  1
   sometext                 1
     <foobar>         2
     </foobar>        2
 </root>              1
 <!-- outside -->     0
 
Specified by:
getDepth in interface XmlPullParser

getEventType

public int getEventType()
            throws XmlPullParserException
Returns the type of the current event (START_TAG, END_TAG, TEXT, etc.)
Specified by:
getEventType in interface XmlPullParser

getFeature

public boolean getFeature(String name)
Unknown properties are always returned as false
Specified by:
getFeature in interface XmlPullParser

getInputEncoding

public String getInputEncoding()
Returns the input encoding if known, null otherwise. If setInput(InputStream, inputEncoding) was called with an inputEncoding value other than null, this value must be returned from this method. Otherwise, if inputEncoding is null and the parser suppports the encoding detection feature (http://xmlpull.org/v1/doc/features.html#detect-encoding), it must return the detected encoding. If setInput(Reader) was called, null is returned. After first call to next if XML declaration was present this method will return encoding declared.
Specified by:
getInputEncoding in interface XmlPullParser

getLineNumber

public int getLineNumber()
Returns the current line number, starting from 1. When the parser does not know the current line number or can not determine it, -1 is returned (e.g. for WBXML).
Specified by:
getLineNumber in interface XmlPullParser
Returns:
current line number or -1 if unknown.

getName

public String getName()
For START_TAG or END_TAG events, the (local) name of the current element is returned when namespaces are enabled. When namespace processing is disabled, the raw name is returned. For ENTITY_REF events, the entity name is returned. If the current event is not START_TAG, END_TAG, or ENTITY_REF, null is returned.

Please note: To reconstruct the raw element name when namespaces are enabled and the prefix is not null, you will need to add the prefix and a colon to localName..

Specified by:
getName in interface XmlPullParser

getNamespace

public String getNamespace()
Returns the namespace URI of the current element. The default namespace is represented as empty string. If namespaces are not enabled, an empty String ("") is always returned. The current event must be START_TAG or END_TAG; otherwise, null is returned.
Specified by:
getNamespace in interface XmlPullParser

getNamespace

public String getNamespace(String prefix)
Specified by:
getNamespace in interface XmlPullParser

getNamespaceCount

public int getNamespaceCount(int depth)
            throws XmlPullParserException
Returns the numbers of elements in the namespace stack for the given depth. If namespaces are not enabled, 0 is returned.

NOTE: when parser is on END_TAG then it is allowed to call this function with getDepth()+1 argument to retrieve position of namespace prefixes and URIs that were declared on corresponding START_TAG.

NOTE: to retrieve lsit of namespaces declared in current element:

       XmlPullParser pp = ...
       int nsStart = pp.getNamespaceCount(pp.getDepth()-1);
       int nsEnd = pp.getNamespaceCount(pp.getDepth());
       for (int i = nsStart; i <32nsEnd; i++) {
          String prefix = pp.getNamespacePrefix(i);
          String ns = pp.getNamespaceUri(i);
           // ...
      }
 
Specified by:
getNamespaceCount in interface XmlPullParser

getNamespacePrefix

public String getNamespacePrefix(int pos)
            throws XmlPullParserException
Returns the namespace prefixe for the given position in the namespace stack. Default namespace declaration (xmlns='...') will have null as prefix. If the given index is out of range, an exception is thrown.

Please note: when the parser is on an END_TAG, namespace prefixes that were declared in the corresponding START_TAG are still accessible although they are no longer in scope.

Specified by:
getNamespacePrefix in interface XmlPullParser

getNamespaceUri

public String getNamespaceUri(int pos)
            throws XmlPullParserException
Returns the namespace URI for the given position in the namespace stack If the position is out of range, an exception is thrown.

NOTE: when parser is on END_TAG then namespace prefixes that were declared in corresponding START_TAG are still accessible even though they are not in scope

Specified by:
getNamespaceUri in interface XmlPullParser

getPositionDescription

public String getPositionDescription()
Return string describing current position of parsers as text 'STATE [seen %s...] @line:column'.
Specified by:
getPositionDescription in interface XmlPullParser

getPrefix

public String getPrefix()
Returns the prefix of the current element. If the element is in the default namespace (has no prefix), null is returned. If namespaces are not enabled, or the current event is not START_TAG or END_TAG, null is returned.
Specified by:
getPrefix in interface XmlPullParser

getProperty

public Object getProperty(String name)
Look up the value of a property. The property name is any fully-qualified URI.

NOTE: unknown properties are always returned as null.

Specified by:
getProperty in interface XmlPullParser
Parameters:
name - The name of property to be retrieved.
Returns:
The value of named property.

getText

public String getText()
Returns the text content of the current event as String. The value returned depends on current event type, for example for TEXT event it is element content (this is typical case when next() is used). See description of nextToken() for detailed description of possible returned values for different types of events.

NOTE: in case of ENTITY_REF, this method returns the entity replacement text (or null if not available). This is the only case where getText() and getTextCharacters() return different values.

Specified by:
getText in interface XmlPullParser

getTextCharacters

public char[] getTextCharacters(int[] holderForStartAndLength)
Returns the buffer that contains the text of the current event, as well as the start offset and length relevant for the current event. See getText(), next() and nextToken() for description of possible returned values.

Please note: this buffer must not be modified and its content MAY change after a call to next() or nextToken(). This method will always return the same value as getText(), except for ENTITY_REF. In the case of ENTITY ref, getText() returns the replacement text and this method returns the actual input buffer containing the entity name. If getText() returns null, this method returns null as well and the values returned in the holder array MUST be -1 (both start and length).

Specified by:
getTextCharacters in interface XmlPullParser
Parameters:
holderForStartAndLength - Must hold an 2-element int array into which the start offset and length values will be written.
Returns:
char buffer that contains the text of the current event (null if the current event has no text associated).

isAttributeDefault

public boolean isAttributeDefault(int index)
Returns if the specified attribute was not in input was declared in XML. If parser is non-validating it MUST always return false. This information is part of XML infoset:
Specified by:
isAttributeDefault in interface XmlPullParser
Parameters:
Returns:
false if attribute was in input

isEmptyElementTag

public boolean isEmptyElementTag()
            throws XmlPullParserException
Returns true if the current event is START_TAG and the tag is degenerated (e.g. <foobar/>).

NOTE: if the parser is not on START_TAG, an exception will be thrown.

Specified by:
isEmptyElementTag in interface XmlPullParser

isNameChar

protected boolean isNameChar(char ch)

isNameStartChar

protected boolean isNameStartChar(char ch)

isS

protected boolean isS(char ch)

isWhitespace

public boolean isWhitespace()
            throws XmlPullParserException
Checks whether the current TEXT event contains only whitespace characters. For IGNORABLE_WHITESPACE, this is always true. For TEXT and CDSECT, false is returned when the current event text contains at least one non-white space character. For any other event type an exception is thrown.

Please note: non-validating parsers are not able to distinguish whitespace and ignorable whitespace, except from whitespace outside the root element. Ignorable whitespace is reported as separate event, which is exposed via nextToken only.

Specified by:
isWhitespace in interface XmlPullParser

joinPC

protected void joinPC()

lookuEntityReplacement

protected char[] lookuEntityReplacement(int entitNameLen)
            throws XmlPullParserException,
                   IOException

more

protected char more()
            throws IOException,
                   XmlPullParserException

newString

protected String newString(char[] cbuf,
                           int off,
                           int len)

newStringIntern

protected String newStringIntern(char[] cbuf,
                                 int off,
                                 int len)

next

public int next()
            throws XmlPullParserException,
                   IOException
Get next parsing event - element content wil be coalesced and only one TEXT event must be returned for whole element content (comments and processing instructions will be ignored and emtity references must be expanded or exception mus be thrown if entity reerence can not be exapnded). If element content is empty (content is "") then no TEXT event will be reported.

NOTE: empty element (such as <tag/>) will be reported with two separate events: START_TAG, END_TAG - it must be so to preserve parsing equivalency of empty element to <tag></tag>. (see isEmptyElementTag ())

Specified by:
next in interface XmlPullParser

nextImpl

protected int nextImpl()
            throws XmlPullParserException,
                   IOException

nextTag

public int nextTag()
            throws XmlPullParserException,
                   IOException
Call next() and return event if it is START_TAG or END_TAG otherwise throw an exception. It will skip whitespace TEXT before actual tag if any.

essentially it does this

   int eventType = next();
   if(eventType == TEXT &&  isWhitespace()) {   // skip whitespace
      eventType = next();
   }
   if (eventType != START_TAG &&  eventType != END_TAG) {
      throw new XmlPullParserException("expected start or end tag", this, null);
   }
   return eventType;
 
Specified by:
nextTag in interface XmlPullParser

nextText

public String nextText()
            throws XmlPullParserException,
                   IOException
If current event is START_TAG then if next element is TEXT then element content is returned or if next event is END_TAG then empty string is returned, otherwise exception is thrown. After calling this function successfully parser will be positioned on END_TAG.

The motivation for this function is to allow to parse consistently both empty elements and elements that has non empty content, for example for input:

  1. <tag>foo</tag>
  2. <tag></tag> (which is equivalent to <tag/> both input can be parsed with the same code:
       p.nextTag()
       p.requireEvent(p.START_TAG, "", "tag");
       String content = p.nextText();
       p.requireEvent(p.END_TAG, "", "tag");
     
    This function together with nextTag make it very easy to parse XML that has no mixed content.

    Essentially it does this

      if(getEventType() != START_TAG) {
         throw new XmlPullParserException(
           "parser must be on START_TAG to read next text", this, null);
      }
      int eventType = next();
      if(eventType == TEXT) {
         String result = getText();
         eventType = next();
         if(eventType != END_TAG) {
           throw new XmlPullParserException(
              "event TEXT it must be immediately followed by END_TAG", this, null);
          }
          return result;
      } else if(eventType == END_TAG) {
         return "";
      } else {
         throw new XmlPullParserException(
           "parser must be on START_TAG or TEXT to read text", this, null);
      }
     
Specified by:
nextText in interface XmlPullParser

nextToken

public int nextToken()
            throws XmlPullParserException,
                   IOException
This method works similarly to next() but will expose additional event types (COMMENT, CDSECT, DOCDECL, ENTITY_REF, PROCESSING_INSTRUCTION, or IGNORABLE_WHITESPACE) if they are available in input.

If special feature FEATURE_XML_ROUNDTRIP (identified by URI: http://xmlpull.org/v1/doc/features.html#xml-roundtrip) is enabled it is possible to do XML document round trip ie. reproduce exectly on output the XML input using getText(): returned content is always unnormalized (exactly as in input). Otherwise returned content is end-of-line normalized as described XML 1.0 End-of-Line Handling and. Also when this feature is enabled exact content of START_TAG, END_TAG, DOCDECL and PROCESSING_INSTRUCTION is available.

Here is the list of tokens that can be returned from nextToken() and what getText() and getTextCharacters() returns:



inside

NOTE:are different
NOTE:
NOTE:not
 " titlepage SYSTEM "http://www.foo.bar/dtds/typo.dtd"
 [<!ENTITY % active.links "INCLUDE">]"

 <!DOCTYPE titlepage SYSTEM "http://www.foo.bar/dtds/typo.dtd"
 [<!ENTITY % active.links "INCLUDE">]>

NOTE: there is no gurantee that there will only one TEXT or IGNORABLE_WHITESPACE event from nextToken() as parser may chose to deliver element content in multiple tokens (dividing element content into chunks)

NOTE: whether returned text of token is end-of-line normalized is depending on FEATURE_XML_ROUNDTRIP.

NOTE: XMLDecl (<?xml ...?>) is not reported but its content is available through optional properties (see class description above).

Specified by:
nextToken in interface XmlPullParser

parseAttribute

protected char parseAttribute()
            throws XmlPullParserException,
                   IOException

parseCDSect

protected void parseCDSect(boolean hadCharData)
            throws XmlPullParserException,
                   IOException

parseComment

protected void parseComment()
            throws XmlPullParserException,
                   IOException

parseDocdecl

protected void parseDocdecl()
            throws XmlPullParserException,
                   IOException

parseEndTag

public int parseEndTag()
            throws XmlPullParserException,
                   IOException

parseEntityRef

protected char[] parseEntityRef()
            throws XmlPullParserException,
                   IOException

parseEpilog

protected int parseEpilog()
            throws XmlPullParserException,
                   IOException

parsePI

protected boolean parsePI()
            throws XmlPullParserException,
                   IOException

parseProlog

protected int parseProlog()
            throws XmlPullParserException,
                   IOException

parseStartTag

public int parseStartTag()
            throws XmlPullParserException,
                   IOException

parseXmlDecl

protected void parseXmlDecl(char ch)
            throws XmlPullParserException,
                   IOException

parseXmlDeclWithVersion

protected void parseXmlDeclWithVersion(int versionStart,
                                       int versionEnd)
            throws XmlPullParserException,
                   IOException

printable

protected String printable(String s)

printable

protected String printable(char ch)

require

public void require(int type,
                    String namespace,
                    String name)
            throws XmlPullParserException,
                   IOException
Test if the current event is of the given type and if the namespace and name do match. null will match any namespace and any name. If the test is not passed, an exception is thrown. The exception text indicates the parser position, the expected event and the current event that is not meeting the requirement.

Essentially it does this

  if (type != getEventType()
  || (namespace != null &&  !namespace.equals( getNamespace () ) )
  || (name != null &&  !name.equals( getName() ) ) )
     throw new XmlPullParserException( "expected "+ TYPES[ type ]+getPositionDescription());
 
Specified by:
require in interface XmlPullParser

requireInput

protected char requireInput(char ch,
                            char[] input)
            throws XmlPullParserException,
                   IOException

requireNextS

protected char requireNextS()
            throws XmlPullParserException,
                   IOException

reset

protected void reset()

resetStringCache

protected void resetStringCache()

setFeature

public void setFeature(String name,
                       boolean state)
            throws XmlPullParserException
Method setFeature
Specified by:
setFeature in interface XmlPullParser
Parameters:
name - a String
state - a boolean

setInput

public void setInput(Reader in)
            throws XmlPullParserException
Set the input source for parser to the given reader and resets the parser. The event type is set to the initial value START_DOCUMENT. Setting the reader to null will just stop parsing and reset parser state, allowing the parser to free internal resources such as parsing buffers.
Specified by:
setInput in interface XmlPullParser

setInput

public void setInput(java.io.InputStream inputStream,
                     String inputEncoding)
            throws XmlPullParserException

setName

private static final void setName(char ch)

setNameStart

private static final void setNameStart(char ch)

setProperty

public void setProperty(String name,
                        Object value)
            throws XmlPullParserException
Set the value of a property. The property name is any fully-qualified URI.
Specified by:
setProperty in interface XmlPullParser
Throws:
XmlPullParserException - If the property is not supported or can not be set

skipS

protected char skipS(char ch)
            throws XmlPullParserException,
                   IOException

skipSubTree

public void skipSubTree()
            throws XmlPullParserException,
                   IOException
Skip sub tree that is currently porser positioned on.
NOTE: parser must be on START_TAG and when funtion returns parser will be positioned on corresponding END_TAG