ePOST API

rice.p2p.util
Class XMLReader

java.lang.Object
  extended by rice.p2p.util.XMLReader

public class XMLReader
extends java.lang.Object

XMLReader is a utility class used by XMLObjectInputStreamm to perform the actual XML parsing. This reader is based on the XML Pull-Parsing API, available online at http://www.xmlpull.org. Any of the provided parser implementations will work with this reader.

Version:
$Id: XMLReader.java 3141 2006-03-15 16:07:02Z jstewart $
Author:
Alan Mislove

Field Summary
protected  int eventType
          The cached type of the last event the parser saw
protected  java.io.Reader in
          The actual reader which the parser uses
protected  org.xmlpull.v1.XmlPullParser xpp
          The actual XML parser which we use
 
Constructor Summary
XMLReader(java.io.Reader in)
          Constructor which takes the provided reader and builds a new XML parser to read XML from the reader.
 
Method Summary
 void assertAttribute(java.lang.String name, java.lang.String value)
          Asserts that the given attribute exists and is equal to the given value.
 void assertEndTag()
          Asserts that a end tag was just read
 void assertEndTag(java.lang.String name)
          Asserts that the provided end tag was just read
protected  void assertEvent(int type)
          Asserts that the given event type just happened.
 void assertStartTag()
          Asserts that a start tag was just read
 void assertStartTag(java.lang.String name)
          Asserts that the provided start tag was just read
 void close()
          Method which closes the underlying reader, which will cause future step attempts to throw an IOException.
 java.lang.String getAttribute(java.lang.String name)
          Returns the value of the given attribute, or null if the attribute cannot be found.
 java.lang.String getEndTag()
          Returns the value of the current end tag
 java.lang.String getStartTag()
          Returns the value of the current start tag
 boolean isEndDocument()
          Returns whether or not a end document just happened
 boolean isEndTag()
          Returns whether or not a end tag just happened
 boolean isStartDocument()
          Returns whether or not a start document just happened
 boolean isStartTag()
          Returns whether or not a start tag just happened
 boolean isText()
          Returns whether or not a end tag just happened
 byte[] readBase64()
          Method which writes a sequence of base64 encoded bytes to the output stream
 void readEndTag()
          Asserts that a end tag will be read next.
 void readEndTag(java.lang.String name)
          Asserts that the provided end tag will be read next.
 void readHeader()
          Method which reads the header from the reader.
 void readStartTag()
          Asserts that a start tag will be read next.
 void readStartTag(java.lang.String name)
          Asserts that the provided start tag will be read next.
 void step()
          Advances the parser one step, skipping whitespace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

in

protected java.io.Reader in
The actual reader which the parser uses


xpp

protected org.xmlpull.v1.XmlPullParser xpp
The actual XML parser which we use


eventType

protected int eventType
The cached type of the last event the parser saw

Constructor Detail

XMLReader

public XMLReader(java.io.Reader in)
          throws java.io.IOException
Constructor which takes the provided reader and builds a new XML parser to read XML from the reader.

Parameters:
in - The reader to base this XML reader off of
Throws:
java.io.IOException - If an error occurs
Method Detail

close

public void close()
           throws java.io.IOException
Method which closes the underlying reader, which will cause future step attempts to throw an IOException.

Throws:
java.io.IOException - If an error occurs

readBase64

public byte[] readBase64()
                  throws java.io.IOException
Method which writes a sequence of base64 encoded bytes to the output stream

Parameters:
bytes - The bytes to write
Throws:
java.io.IOException

readHeader

public void readHeader()
                throws java.io.IOException
Method which reads the header from the reader. If an invalid header is found, and IOException is thrown.

Throws:
java.io.IOException - If an error occurs

assertEvent

protected void assertEvent(int type)
                    throws java.io.IOException
Asserts that the given event type just happened.

Throws:
java.io.IOException - If a the assertion failed

assertStartTag

public void assertStartTag()
                    throws java.io.IOException
Asserts that a start tag was just read

Throws:
java.io.IOException - If a the assertion failed

assertEndTag

public void assertEndTag()
                  throws java.io.IOException
Asserts that a end tag was just read

Throws:
java.io.IOException - If a the assertion failed

assertStartTag

public void assertStartTag(java.lang.String name)
                    throws java.io.IOException
Asserts that the provided start tag was just read

Parameters:
name - The name of the start tag
Throws:
java.io.IOException - If a the assertion failed

assertEndTag

public void assertEndTag(java.lang.String name)
                  throws java.io.IOException
Asserts that the provided end tag was just read

Parameters:
name - The name of the end tag
Throws:
java.io.IOException - If a the assertion failed

readStartTag

public void readStartTag()
                  throws java.io.IOException
Asserts that a start tag will be read next. Causes a step() to be called.

Throws:
java.io.IOException - If a the assertion failed

readEndTag

public void readEndTag()
                throws java.io.IOException
Asserts that a end tag will be read next. Causes a step() to be called.

Throws:
java.io.IOException - If a the assertion failed

readStartTag

public void readStartTag(java.lang.String name)
                  throws java.io.IOException
Asserts that the provided start tag will be read next. Causes a step() to be called.

Throws:
java.io.IOException - If a the assertion failed

readEndTag

public void readEndTag(java.lang.String name)
                throws java.io.IOException
Asserts that the provided end tag will be read next. Causes a step() to be called.

Throws:
java.io.IOException - If a the assertion failed

assertAttribute

public void assertAttribute(java.lang.String name,
                            java.lang.String value)
                     throws java.io.IOException
Asserts that the given attribute exists and is equal to the given value.

Throws:
java.io.IOException - If a the assertion failed

step

public void step()
          throws java.io.IOException
Advances the parser one step, skipping whitespace

Throws:
java.io.IOException - If an error occurs

isStartDocument

public boolean isStartDocument()
Returns whether or not a start document just happened

Returns:
Whether or not a start doucment just happened

isEndDocument

public boolean isEndDocument()
Returns whether or not a end document just happened

Returns:
Whether or not a end doucment just happened

isStartTag

public boolean isStartTag()
Returns whether or not a start tag just happened

Returns:
Whether or not a start tag just happened

isEndTag

public boolean isEndTag()
Returns whether or not a end tag just happened

Returns:
Whether or not a end tag just happened

isText

public boolean isText()
Returns whether or not a end tag just happened

Returns:
Whether or not a end tag just happened

getAttribute

public java.lang.String getAttribute(java.lang.String name)
                              throws java.io.IOException
Returns the value of the given attribute, or null if the attribute cannot be found.

Returns:
The corresponding value, or null
Throws:
java.io.IOException - If the current event is not a start tag

getStartTag

public java.lang.String getStartTag()
                             throws java.io.IOException
Returns the value of the current start tag

Returns:
The start tag value
Throws:
java.io.IOException - If the current event is not a start tag

getEndTag

public java.lang.String getEndTag()
                           throws java.io.IOException
Returns the value of the current end tag

Returns:
The end tag value
Throws:
java.io.IOException - If the current event is not a end tag

ePOST API

Copyright © 2001-2005 - Rice Pastry.