|
ePOST API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object rice.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 java.lang.String[] |
attributeKeys
If the tag parsed was a start tag, the list of attribute-> value pairs |
protected java.lang.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 java.lang.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 java.lang.String |
name
If the tag parsed was a start/end, the name of the tag |
protected int |
numAttributes
|
static char[] |
QUOTE
|
protected java.io.Reader |
reader
The internal reader used to read data |
static char[] |
SINGLE
|
static char[] |
TAG_END
|
protected java.util.Stack |
tags
The internal stack of tags which have been read |
protected java.lang.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(java.lang.String key,
java.lang.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 java.lang.String |
convert(java.lang.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(java.lang.String entityName,
java.lang.String replacementText)
|
protected void |
expect(char c)
An assertion method |
protected void |
fillBuffer()
Internal method which actually fills the buffer |
int |
getAttributeCount()
|
java.lang.String |
getAttributeName(int index)
|
java.lang.String |
getAttributeNamespace(int index)
|
java.lang.String |
getAttributePrefix(int index)
|
java.lang.String |
getAttributeType(int index)
|
java.lang.String |
getAttributeValue(int index)
|
java.lang.String |
getAttributeValue(java.lang.String namespace,
java.lang.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(java.lang.String name)
|
java.lang.String |
getInputEncoding()
|
int |
getLineNumber()
|
java.lang.String |
getName()
For START_TAG or END_TAG events, the (local) name of the current element is returned when namespaces are enabled. |
java.lang.String |
getNamespace()
|
java.lang.String |
getNamespace(java.lang.String prefix)
|
int |
getNamespaceCount(int depth)
|
java.lang.String |
getNamespacePrefix(int pos)
|
java.lang.String |
getNamespaceUri(int pos)
|
java.lang.String |
getPositionDescription()
|
java.lang.String |
getPrefix()
|
java.lang.Object |
getProperty(java.lang.String name)
|
java.lang.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(java.lang.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()
|
java.lang.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(java.lang.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 java.lang.String |
parseUntil(char c)
Method which parses and returns up to the next token |
protected java.lang.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,
java.lang.String namespace,
java.lang.String name)
|
void |
setFeature(java.lang.String name,
boolean state)
----- UNSUPPORTED METHODS ----- |
void |
setInput(java.io.InputStream inputStream,
java.lang.String inputEncoding)
|
void |
setInput(java.io.Reader in)
Set the input source for parser to the given reader and resets the parser. |
void |
setProperty(java.lang.String name,
java.lang.Object value)
|
protected void |
step()
Method which steps forward in the buffer |
protected java.lang.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 java.lang.String[][] ENTITIES
protected java.io.Reader reader
protected char[] buffer
protected int bufferPosition
protected int bufferLimit
protected StringCache cache
protected java.util.Stack tags
protected java.lang.String name
protected java.lang.String text
protected java.lang.String[] attributeKeys
protected java.lang.String[] attributeValues
protected int numAttributes
protected boolean inTag
protected int mark
protected XMLParser.CharArrayBuffer marked
Constructor Detail |
---|
public XMLParser()
Method Detail |
---|
public void setInput(java.io.Reader in) throws org.xmlpull.v1.XmlPullParserException
setInput
in interface org.xmlpull.v1.XmlPullParser
org.xmlpull.v1.XmlPullParserException
public java.lang.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.XmlPullParser
getEventType()
,
next()
,
nextToken()
public java.lang.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 java.lang.String getAttributeValue(java.lang.String namespace, java.lang.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.XmlPullParser
namespace
- 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.XmlPullParser
org.xmlpull.v1.XmlPullParserException
next()
,
nextToken()
public int next() throws org.xmlpull.v1.XmlPullParserException, java.io.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.XmlPullParser
org.xmlpull.v1.XmlPullParserException
java.io.IOException
isEmptyElementTag()
,
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.XmlPullParser
org.xmlpull.v1.XmlPullParserException
protected void fillBuffer() throws java.io.IOException
java.io.IOException
protected char current() throws java.io.IOException
java.io.IOException
protected void step()
protected void mark()
protected java.lang.String unmark()
protected void clearAttributes()
protected void addAttribute(java.lang.String key, java.lang.String value)
protected void expect(char c) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException
the
- expected char
org.xmlpull.v1.XmlPullParserException
java.io.IOException
public boolean isWhitespace(java.lang.String text)
chars
- The chars to check forchar
- The charprotected boolean contains(char[] chars, char c)
chars
- The chars to check forchar
- The charprotected java.lang.String parseUntil(char[] chars) throws java.io.IOException
java.io.IOException
protected java.lang.String parseUntil(char c) throws java.io.IOException
java.io.IOException
protected void parseUntilNot(char[] chars) throws java.io.IOException
java.io.IOException
protected int parseEndTag(java.lang.String tag) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException
The
- name of the parsed tag
org.xmlpull.v1.XmlPullParserException
java.io.IOException
protected int parseTag() throws org.xmlpull.v1.XmlPullParserException, java.io.IOException
org.xmlpull.v1.XmlPullParserException
java.io.IOException
protected int parseEndTag() throws org.xmlpull.v1.XmlPullParserException, java.io.IOException
The
- name of the parsed tag
org.xmlpull.v1.XmlPullParserException
java.io.IOException
protected int parseStartTag() throws org.xmlpull.v1.XmlPullParserException, java.io.IOException
org.xmlpull.v1.XmlPullParserException
java.io.IOException
protected int parseDocumentTag() throws org.xmlpull.v1.XmlPullParserException, java.io.IOException
org.xmlpull.v1.XmlPullParserException
java.io.IOException
protected void parseAttributes() throws org.xmlpull.v1.XmlPullParserException, java.io.IOException
org.xmlpull.v1.XmlPullParserException
java.io.IOException
protected int parseText() throws org.xmlpull.v1.XmlPullParserException, java.io.IOException
The
- name of the parsed tag
org.xmlpull.v1.XmlPullParserException
java.io.IOException
protected java.lang.String convert(java.lang.String string)
string
- The string to convert
public void setFeature(java.lang.String name, boolean state) throws org.xmlpull.v1.XmlPullParserException
setFeature
in interface org.xmlpull.v1.XmlPullParser
org.xmlpull.v1.XmlPullParserException
public boolean getFeature(java.lang.String name)
getFeature
in interface org.xmlpull.v1.XmlPullParser
public void setProperty(java.lang.String name, java.lang.Object value) throws org.xmlpull.v1.XmlPullParserException
setProperty
in interface org.xmlpull.v1.XmlPullParser
org.xmlpull.v1.XmlPullParserException
public java.lang.Object getProperty(java.lang.String name)
getProperty
in interface org.xmlpull.v1.XmlPullParser
public void setInput(java.io.InputStream inputStream, java.lang.String inputEncoding) throws org.xmlpull.v1.XmlPullParserException
setInput
in interface org.xmlpull.v1.XmlPullParser
org.xmlpull.v1.XmlPullParserException
public java.lang.String getInputEncoding()
getInputEncoding
in interface org.xmlpull.v1.XmlPullParser
public void defineEntityReplacementText(java.lang.String entityName, java.lang.String replacementText) throws org.xmlpull.v1.XmlPullParserException
defineEntityReplacementText
in interface org.xmlpull.v1.XmlPullParser
org.xmlpull.v1.XmlPullParserException
public int getNamespaceCount(int depth) throws org.xmlpull.v1.XmlPullParserException
getNamespaceCount
in interface org.xmlpull.v1.XmlPullParser
org.xmlpull.v1.XmlPullParserException
public java.lang.String getNamespacePrefix(int pos) throws org.xmlpull.v1.XmlPullParserException
getNamespacePrefix
in interface org.xmlpull.v1.XmlPullParser
org.xmlpull.v1.XmlPullParserException
public java.lang.String getNamespaceUri(int pos) throws org.xmlpull.v1.XmlPullParserException
getNamespaceUri
in interface org.xmlpull.v1.XmlPullParser
org.xmlpull.v1.XmlPullParserException
public java.lang.String getNamespace(java.lang.String prefix)
getNamespace
in interface org.xmlpull.v1.XmlPullParser
public int getDepth()
getDepth
in interface org.xmlpull.v1.XmlPullParser
public java.lang.String getPositionDescription()
getPositionDescription
in interface org.xmlpull.v1.XmlPullParser
public int getLineNumber()
getLineNumber
in interface org.xmlpull.v1.XmlPullParser
public int getColumnNumber()
getColumnNumber
in interface org.xmlpull.v1.XmlPullParser
public char[] getTextCharacters(int[] holderForStartAndLength)
getTextCharacters
in interface org.xmlpull.v1.XmlPullParser
public java.lang.String getNamespace()
getNamespace
in interface org.xmlpull.v1.XmlPullParser
public java.lang.String getPrefix()
getPrefix
in interface org.xmlpull.v1.XmlPullParser
public boolean isEmptyElementTag() throws org.xmlpull.v1.XmlPullParserException
isEmptyElementTag
in interface org.xmlpull.v1.XmlPullParser
org.xmlpull.v1.XmlPullParserException
public java.lang.String getAttributeNamespace(int index)
getAttributeNamespace
in interface org.xmlpull.v1.XmlPullParser
public java.lang.String getAttributePrefix(int index)
getAttributePrefix
in interface org.xmlpull.v1.XmlPullParser
public java.lang.String getAttributeType(int index)
getAttributeType
in interface org.xmlpull.v1.XmlPullParser
public boolean isAttributeDefault(int index)
isAttributeDefault
in interface org.xmlpull.v1.XmlPullParser
public int nextToken() throws org.xmlpull.v1.XmlPullParserException, java.io.IOException
nextToken
in interface org.xmlpull.v1.XmlPullParser
org.xmlpull.v1.XmlPullParserException
java.io.IOException
public void require(int type, java.lang.String namespace, java.lang.String name) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException
require
in interface org.xmlpull.v1.XmlPullParser
org.xmlpull.v1.XmlPullParserException
java.io.IOException
public java.lang.String nextText() throws org.xmlpull.v1.XmlPullParserException, java.io.IOException
nextText
in interface org.xmlpull.v1.XmlPullParser
org.xmlpull.v1.XmlPullParserException
java.io.IOException
public int nextTag() throws org.xmlpull.v1.XmlPullParserException, java.io.IOException
nextTag
in interface org.xmlpull.v1.XmlPullParser
org.xmlpull.v1.XmlPullParserException
java.io.IOException
public int getAttributeCount()
getAttributeCount
in interface org.xmlpull.v1.XmlPullParser
public java.lang.String getAttributeName(int index)
getAttributeName
in interface org.xmlpull.v1.XmlPullParser
public java.lang.String getAttributeValue(int index)
getAttributeValue
in interface org.xmlpull.v1.XmlPullParser
|
ePOST API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |