edu.udo.cs.wvtool.external
Class XmlReader

java.lang.Object
  extended by edu.udo.cs.wvtool.external.XmlReader

public class XmlReader
extends java.lang.Object

A minimalistic XML pull parser, similar to kXML, but not supporting namespaces or legacy events. If you need support for namespaces, or access to XML comments or processing instructions, please use kXML(2) instead.

Author:
Stefan Haustein

Field Summary
private  int attributeCount
           
private  java.lang.String[] attributes
           
static int CDSECT
           
private  int column
           
private  boolean degenerated
           
private  int depth
           
private  java.lang.String[] elementStack
           
static int END_DOCUMENT
          Signal logical end of xml document
static int END_TAG
          End tag was just read
(package private) static int ENTITY_REF
           
private  java.util.Hashtable entityMap
           
private  boolean eof
           
private  boolean isWhitespace
           
private static int LEGACY
           
private  int line
           
private  java.lang.String name
           
private  int peek0
           
private  int peek1
           
private  java.io.Reader reader
           
 boolean relaxed
           
private  char[] srcBuf
           
private  int srcCount
           
private  int srcPos
           
static int START_DOCUMENT
          Return value of getType before first call to next()
static int START_TAG
          Start tag was just read
private  java.lang.String text
           
static int TEXT
          Text was just read
private  char[] txtBuf
           
private  int txtPos
           
private  int type
           
private  java.lang.String[] TYPES
           
private static java.lang.String UNEXPECTED_EOF
           
 
Constructor Summary
XmlReader(java.io.Reader reader)
           
 
Method Summary
 void defineCharacterEntity(java.lang.String entity, java.lang.String value)
           
private static java.lang.String[] ensureCapacity(java.lang.String[] arr, int required)
           
private  void exception(java.lang.String desc)
           
 int getAttributeCount()
           
 java.lang.String getAttributeName(int index)
           
 java.lang.String getAttributeValue(int index)
           
 java.lang.String getAttributeValue(java.lang.String name)
           
 int getColumnNumber()
           
 int getDepth()
           
 int getLineNumber()
           
 java.lang.String getName()
           
 java.lang.String getPositionDescription()
           
 java.lang.String getText()
           
 int getType()
           
 boolean isEmptyElementTag()
           
 boolean isWhitespace()
           
 int next()
           
private  void parseDoctype()
          precondition:
private  void parseEndTag()
           
private  void parseLegacy(boolean push)
           
private  void parseStartTag()
          Sets name and attributes
private  int peekType()
           
private  java.lang.String pop(int pos)
           
private  void push(int c)
           
 boolean pushEntity()
          result: isWhitespace; if the setName parameter is set, the name of the entity is stored in "name"
private  boolean pushText(int delimiter)
          types: '< parse="parse" to="to" any="any" token="token" (for="(for" nextToken="nextToken" (="(" )=")" '="'" "='"' ="':" quote="quote" whitespace="whitespace" or="or">'
private  int read()
           
private  void read(char c)
           
private  java.lang.String readName()
           
 java.lang.String readText()
          If the current event is text, the value of getText is returned and next() is called.
 void require(int type, java.lang.String name)
          test if the current event is of the given type and if the name do match.
private  void skip()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

START_DOCUMENT

public static final int START_DOCUMENT
Return value of getType before first call to next()

See Also:
Constant Field Values


END_DOCUMENT

public static final int END_DOCUMENT
Signal logical end of xml document

See Also:
Constant Field Values


START_TAG

public static final int START_TAG
Start tag was just read

See Also:
Constant Field Values


END_TAG

public static final int END_TAG
End tag was just read

See Also:
Constant Field Values


TEXT

public static final int TEXT
Text was just read

See Also:
Constant Field Values


CDSECT

public static final int CDSECT
See Also:
Constant Field Values

ENTITY_REF

static final int ENTITY_REF
See Also:
Constant Field Values

UNEXPECTED_EOF

private static final java.lang.String UNEXPECTED_EOF
See Also:
Constant Field Values

LEGACY

private static final int LEGACY
See Also:
Constant Field Values

relaxed

public boolean relaxed

entityMap

private java.util.Hashtable entityMap

depth

private int depth

elementStack

private java.lang.String[] elementStack

reader

private java.io.Reader reader

srcBuf

private char[] srcBuf

srcPos

private int srcPos

srcCount

private int srcCount

eof

private boolean eof

line

private int line

column

private int column

peek0

private int peek0

peek1

private int peek1

txtBuf

private char[] txtBuf

txtPos

private int txtPos

type

private int type

text

private java.lang.String text

isWhitespace

private boolean isWhitespace

name

private java.lang.String name

degenerated

private boolean degenerated

attributeCount

private int attributeCount

attributes

private java.lang.String[] attributes

TYPES

private java.lang.String[] TYPES
Constructor Detail

XmlReader

public XmlReader(java.io.Reader reader)
          throws java.io.IOException
Throws:
java.io.IOException
Method Detail

read

private final int read()
                throws java.io.IOException
Throws:
java.io.IOException

exception

private final void exception(java.lang.String desc)
                      throws java.io.IOException
Throws:
java.io.IOException

push

private final void push(int c)

read

private final void read(char c)
                 throws java.io.IOException
Throws:
java.io.IOException

skip

private final void skip()
                 throws java.io.IOException
Throws:
java.io.IOException

pop

private final java.lang.String pop(int pos)

readName

private final java.lang.String readName()
                                 throws java.io.IOException
Throws:
java.io.IOException

parseLegacy

private final void parseLegacy(boolean push)
                        throws java.io.IOException
Throws:
java.io.IOException

parseDoctype

private final void parseDoctype()
                         throws java.io.IOException
precondition: consumed

Throws:
java.io.IOException


parseEndTag

private final void parseEndTag()
                        throws java.io.IOException
Throws:
java.io.IOException

peekType

private final int peekType()

ensureCapacity

private static final java.lang.String[] ensureCapacity(java.lang.String[] arr,
                                                       int required)

parseStartTag

private final void parseStartTag()
                          throws java.io.IOException
Sets name and attributes

Throws:
java.io.IOException


pushEntity

public final boolean pushEntity()
                         throws java.io.IOException
result: isWhitespace; if the setName parameter is set, the name of the entity is stored in "name"

Throws:
java.io.IOException


pushText

private final boolean pushText(int delimiter)
                        throws java.io.IOException
types: '< parse="parse" to="to" any="any" token="token" (for="(for" nextToken="nextToken" (="(" )=")" '="'" "='"' ="':" quote="quote" whitespace="whitespace" or="or">'

Throws:
java.io.IOException


defineCharacterEntity

public void defineCharacterEntity(java.lang.String entity,
                                  java.lang.String value)

getDepth

public int getDepth()

getPositionDescription

public java.lang.String getPositionDescription()

getLineNumber

public int getLineNumber()

getColumnNumber

public int getColumnNumber()

isWhitespace

public boolean isWhitespace()

getText

public java.lang.String getText()

getName

public java.lang.String getName()

isEmptyElementTag

public boolean isEmptyElementTag()

getAttributeCount

public int getAttributeCount()

getAttributeName

public java.lang.String getAttributeName(int index)

getAttributeValue

public java.lang.String getAttributeValue(int index)

getAttributeValue

public java.lang.String getAttributeValue(java.lang.String name)

getType

public int getType()

next

public int next()
         throws java.io.IOException
Throws:
java.io.IOException

require

public void require(int type,
                    java.lang.String name)
             throws java.io.IOException
test if the current event is of the given type and if the name do match. null will match any namespace and any name. If the current event is TEXT with isWhitespace()= true, and the required type is not TEXT, next () is called prior to the test. If the test is not passed, an exception is thrown. The exception text indicates the parser position, the expected event and the current event (not meeting the requirement.

essentially it does this

     if (getType() == TEXT && type != TEXT && isWhitespace ())
       next ();
   
     if (type != getType
     || (name != null && !name.equals (getName ())
        throw new XmlPullParserException ( "....");
 

Throws:
java.io.IOException


readText

public java.lang.String readText()
                          throws java.io.IOException
If the current event is text, the value of getText is returned and next() is called. Otherwise, an empty String ("") is returned. Useful for reading element content without needing to performing an additional check if the element is empty.

essentially it does this

      if (getType != TEXT) return ""
       String result = getText ();
       next ();
       return result;
 

Throws:
java.io.IOException