|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectrice.p2p.util.XMLParser
public class XMLParser
This class is a memory-efficient implementation of most of the XML pull parsing API.
| Nested Class Summary | |
|---|---|
class |
XMLParser.CharArrayBuffer
This class implements a char array buffer |
| Field Summary | |
|---|---|
protected String[] |
attributeKeys
If the tag parsed was a start tag, the list of attribute-> value pairs |
protected String[] |
attributeValues
|
protected char[] |
buffer
The internal buffer used to process data |
static int |
BUFFER_SIZE
The size of the internal buffer to allocate |
protected int |
bufferLimit
|
protected int |
bufferPosition
Internal pointers into the buffer |
protected StringCache |
cache
The StringCache used to reduce the memory requirements |
static String[][] |
ENTITIES
|
protected boolean |
inTag
Whether or not we are currently in a tag... |
protected int |
mark
Internal variable which keeps track of the current mark |
protected XMLParser.CharArrayBuffer |
marked
|
static int |
MAX_ATTRIBUTES
|
protected String |
name
If the tag parsed was a start/end, the name of the tag |
protected int |
numAttributes
|
static char[] |
QUOTE
|
protected Reader |
reader
The internal reader used to read data |
static char[] |
SINGLE
|
static char[] |
TAG_END
|
protected Stack |
tags
The internal stack of tags which have been read |
protected String |
text
If the tag parsed was text, the text |
static char[] |
WHITESPACE
|
static char[] |
WHITESPACE_OR_EQUALS
|
static char[] |
WHITESPACE_OR_TAG_END
|
| Fields inherited from interface org.xmlpull.v1.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 | |
|---|---|
XMLParser()
Constructor |
|
| Method Summary | |
|---|---|
protected void |
addAttribute(String key,
String value)
Internal method which adds an attributes |
protected void |
clearAttributes()
Internal method which clears the list of attributes |
protected boolean |
contains(char[] chars,
char c)
Internal method which checks for existence |
protected String |
convert(String string)
Internal method which deconverts all of the HTML/XML entities like &, >, <, etc... |
protected char |
current()
Method which returns the current char in the buffer |
void |
defineEntityReplacementText(String entityName,
String replacementText)
|
protected void |
expect(char c)
An assertion method |
protected void |
fillBuffer()
Internal method which actually fills the buffer |
int |
getAttributeCount()
|
String |
getAttributeName(int index)
|
String |
getAttributeNamespace(int index)
|
String |
getAttributePrefix(int index)
|
String |
getAttributeType(int index)
|
String |
getAttributeValue(int index)
|
String |
getAttributeValue(String namespace,
String name)
Returns the attributes value identified by namespace URI and namespace localName. |
int |
getColumnNumber()
|
int |
getDepth()
|
int |
getEventType()
Returns the type of the current event (START_TAG, END_TAG, TEXT, etc.) |
boolean |
getFeature(String name)
|
String |
getInputEncoding()
|
int |
getLineNumber()
|
String |
getName()
For START_TAG or END_TAG events, the (local) name of the current element is returned when namespaces are enabled. |
String |
getNamespace()
|
String |
getNamespace(String prefix)
|
int |
getNamespaceCount(int depth)
|
String |
getNamespacePrefix(int pos)
|
String |
getNamespaceUri(int pos)
|
String |
getPositionDescription()
|
String |
getPrefix()
|
Object |
getProperty(String name)
|
String |
getText()
Returns the text content of the current event as String. |
char[] |
getTextCharacters(int[] holderForStartAndLength)
|
boolean |
isAttributeDefault(int index)
|
boolean |
isEmptyElementTag()
|
boolean |
isWhitespace()
Checks whether the current TEXT event contains only whitespace characters. |
boolean |
isWhitespace(String text)
Internal method which checks for existence |
protected void |
mark()
Sets the mark |
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). |
int |
nextTag()
|
String |
nextText()
|
int |
nextToken()
|
protected void |
parseAttributes()
Method which parses all of the attributes of a start tag |
protected int |
parseDocumentTag()
Method which parses a document tag |
protected int |
parseEndTag()
Method which parses an end tag of the form |
protected int |
parseEndTag(String tag)
Method which parses an end tag of the form |
protected int |
parseStartTag()
Method which parses a start tag |
protected int |
parseTag()
Internal method which parses a tag |
protected int |
parseText()
Method which parses an end tag of the form |
protected String |
parseUntil(char c)
Method which parses and returns up to the next token |
protected String |
parseUntil(char[] chars)
Method which parses and returns up to the next token |
protected void |
parseUntilNot(char[] chars)
Method which parses up to the next token |
void |
require(int type,
String namespace,
String name)
|
void |
setFeature(String name,
boolean state)
----- UNSUPPORTED METHODS ----- |
void |
setInput(InputStream inputStream,
String inputEncoding)
|
void |
setInput(Reader in)
Set the input source for parser to the given reader and resets the parser. |
void |
setProperty(String name,
Object value)
|
protected void |
step()
Method which steps forward in the buffer |
protected String |
unmark()
Unsets the mark |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int BUFFER_SIZE
public static final int MAX_ATTRIBUTES
public static final char[] QUOTE
public static final char[] TAG_END
public static final char[] WHITESPACE
public static final char[] WHITESPACE_OR_TAG_END
public static final char[] WHITESPACE_OR_EQUALS
public static final char[] SINGLE
public static final String[][] ENTITIES
protected Reader reader
protected char[] buffer
protected int bufferPosition
protected int bufferLimit
protected StringCache cache
protected Stack tags
protected String name
protected String text
protected String[] attributeKeys
protected String[] attributeValues
protected int numAttributes
protected boolean inTag
protected int mark
protected XMLParser.CharArrayBuffer marked
| Constructor Detail |
|---|
public XMLParser()
| Method Detail |
|---|
public void setInput(Reader in)
throws org.xmlpull.v1.XmlPullParserException
setInput in interface org.xmlpull.v1.XmlPullParserorg.xmlpull.v1.XmlPullParserExceptionpublic String getText()
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.
getText in interface org.xmlpull.v1.XmlPullParsergetEventType(),
next(),
nextToken()public String getName()
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..
getName in interface org.xmlpull.v1.XmlPullParser
public String getAttributeValue(String namespace,
String name)
NOTE: attribute value must be normalized (including entity replacement text if PROCESS_DOCDECL is false) as described in XML 1.0 section 3.3.3 Attribute-Value Normalization
getAttributeValue in interface org.xmlpull.v1.XmlPullParsernamespace - Namespace of the attribute if namespaces are enabled otherwise must be nullname - If namespaces enabled local name of attribute otherwise just attribute name
defineEntityReplacementText(java.lang.String, java.lang.String)
public int getEventType()
throws org.xmlpull.v1.XmlPullParserException
getEventType in interface org.xmlpull.v1.XmlPullParserorg.xmlpull.v1.XmlPullParserExceptionnext(),
nextToken()
public int next()
throws org.xmlpull.v1.XmlPullParserException,
IOException
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 ())
next in interface org.xmlpull.v1.XmlPullParserorg.xmlpull.v1.XmlPullParserException
IOExceptionisEmptyElementTag(),
XmlPullParser.START_TAG,
XmlPullParser.TEXT,
XmlPullParser.END_TAG,
XmlPullParser.END_DOCUMENT
public boolean isWhitespace()
throws org.xmlpull.v1.XmlPullParserException
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.
isWhitespace in interface org.xmlpull.v1.XmlPullParserorg.xmlpull.v1.XmlPullParserException
protected void fillBuffer()
throws IOException
IOException
protected char current()
throws IOException
IOExceptionprotected void step()
protected void mark()
protected String unmark()
protected void clearAttributes()
protected void addAttribute(String key,
String value)
protected void expect(char c)
throws org.xmlpull.v1.XmlPullParserException,
IOException
the - expected char
org.xmlpull.v1.XmlPullParserException
IOExceptionpublic boolean isWhitespace(String text)
chars - The chars to check forchar - The char
protected boolean contains(char[] chars,
char c)
chars - The chars to check forchar - The char
protected String parseUntil(char[] chars)
throws IOException
IOException
protected String parseUntil(char c)
throws IOException
IOException
protected void parseUntilNot(char[] chars)
throws IOException
IOException
protected int parseEndTag(String tag)
throws org.xmlpull.v1.XmlPullParserException,
IOException
The - name of the parsed tag
org.xmlpull.v1.XmlPullParserException
IOException
protected int parseTag()
throws org.xmlpull.v1.XmlPullParserException,
IOException
org.xmlpull.v1.XmlPullParserException
IOException
protected int parseEndTag()
throws org.xmlpull.v1.XmlPullParserException,
IOException
The - name of the parsed tag
org.xmlpull.v1.XmlPullParserException
IOException
protected int parseStartTag()
throws org.xmlpull.v1.XmlPullParserException,
IOException
org.xmlpull.v1.XmlPullParserException
IOException
protected int parseDocumentTag()
throws org.xmlpull.v1.XmlPullParserException,
IOException
org.xmlpull.v1.XmlPullParserException
IOException
protected void parseAttributes()
throws org.xmlpull.v1.XmlPullParserException,
IOException
org.xmlpull.v1.XmlPullParserException
IOException
protected int parseText()
throws org.xmlpull.v1.XmlPullParserException,
IOException
The - name of the parsed tag
org.xmlpull.v1.XmlPullParserException
IOExceptionprotected String convert(String string)
string - The string to convert
public void setFeature(String name,
boolean state)
throws org.xmlpull.v1.XmlPullParserException
setFeature in interface org.xmlpull.v1.XmlPullParserorg.xmlpull.v1.XmlPullParserExceptionpublic boolean getFeature(String name)
getFeature in interface org.xmlpull.v1.XmlPullParser
public void setProperty(String name,
Object value)
throws org.xmlpull.v1.XmlPullParserException
setProperty in interface org.xmlpull.v1.XmlPullParserorg.xmlpull.v1.XmlPullParserExceptionpublic Object getProperty(String name)
getProperty in interface org.xmlpull.v1.XmlPullParser
public void setInput(InputStream inputStream,
String inputEncoding)
throws org.xmlpull.v1.XmlPullParserException
setInput in interface org.xmlpull.v1.XmlPullParserorg.xmlpull.v1.XmlPullParserExceptionpublic String getInputEncoding()
getInputEncoding in interface org.xmlpull.v1.XmlPullParser
public void defineEntityReplacementText(String entityName,
String replacementText)
throws org.xmlpull.v1.XmlPullParserException
defineEntityReplacementText in interface org.xmlpull.v1.XmlPullParserorg.xmlpull.v1.XmlPullParserException
public int getNamespaceCount(int depth)
throws org.xmlpull.v1.XmlPullParserException
getNamespaceCount in interface org.xmlpull.v1.XmlPullParserorg.xmlpull.v1.XmlPullParserException
public String getNamespacePrefix(int pos)
throws org.xmlpull.v1.XmlPullParserException
getNamespacePrefix in interface org.xmlpull.v1.XmlPullParserorg.xmlpull.v1.XmlPullParserException
public String getNamespaceUri(int pos)
throws org.xmlpull.v1.XmlPullParserException
getNamespaceUri in interface org.xmlpull.v1.XmlPullParserorg.xmlpull.v1.XmlPullParserExceptionpublic String getNamespace(String prefix)
getNamespace in interface org.xmlpull.v1.XmlPullParserpublic int getDepth()
getDepth in interface org.xmlpull.v1.XmlPullParserpublic String getPositionDescription()
getPositionDescription in interface org.xmlpull.v1.XmlPullParserpublic int getLineNumber()
getLineNumber in interface org.xmlpull.v1.XmlPullParserpublic int getColumnNumber()
getColumnNumber in interface org.xmlpull.v1.XmlPullParserpublic char[] getTextCharacters(int[] holderForStartAndLength)
getTextCharacters in interface org.xmlpull.v1.XmlPullParserpublic String getNamespace()
getNamespace in interface org.xmlpull.v1.XmlPullParserpublic String getPrefix()
getPrefix in interface org.xmlpull.v1.XmlPullParser
public boolean isEmptyElementTag()
throws org.xmlpull.v1.XmlPullParserException
isEmptyElementTag in interface org.xmlpull.v1.XmlPullParserorg.xmlpull.v1.XmlPullParserExceptionpublic String getAttributeNamespace(int index)
getAttributeNamespace in interface org.xmlpull.v1.XmlPullParserpublic String getAttributePrefix(int index)
getAttributePrefix in interface org.xmlpull.v1.XmlPullParserpublic String getAttributeType(int index)
getAttributeType in interface org.xmlpull.v1.XmlPullParserpublic boolean isAttributeDefault(int index)
isAttributeDefault in interface org.xmlpull.v1.XmlPullParser
public int nextToken()
throws org.xmlpull.v1.XmlPullParserException,
IOException
nextToken in interface org.xmlpull.v1.XmlPullParserorg.xmlpull.v1.XmlPullParserException
IOException
public void require(int type,
String namespace,
String name)
throws org.xmlpull.v1.XmlPullParserException,
IOException
require in interface org.xmlpull.v1.XmlPullParserorg.xmlpull.v1.XmlPullParserException
IOException
public String nextText()
throws org.xmlpull.v1.XmlPullParserException,
IOException
nextText in interface org.xmlpull.v1.XmlPullParserorg.xmlpull.v1.XmlPullParserException
IOException
public int nextTag()
throws org.xmlpull.v1.XmlPullParserException,
IOException
nextTag in interface org.xmlpull.v1.XmlPullParserorg.xmlpull.v1.XmlPullParserException
IOExceptionpublic int getAttributeCount()
getAttributeCount in interface org.xmlpull.v1.XmlPullParserpublic String getAttributeName(int index)
getAttributeName in interface org.xmlpull.v1.XmlPullParserpublic String getAttributeValue(int index)
getAttributeValue in interface org.xmlpull.v1.XmlPullParser
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||