org.japano.util
Class XMLElement

java.lang.Object
  extended by org.japano.util.XMLElement

public class XMLElement
extends java.lang.Object

XMLElement is a representation of an XML object. The object is able to parse XML code.

Version:
$Name: $, $Revision: 1.1.1.1 $
Author:
Marc De Scheemaecker
See Also:
XMLParseException

Field Summary
static int NANOXML_MAJOR_VERSION
          Major version of NanoXML.
static int NANOXML_MINOR_VERSION
          Minor version of NanoXML.
 
Constructor Summary
  XMLElement()
          Creates a new XML element.
  XMLElement(boolean skipLeadingWhitespace)
          Creates a new XML element.
  XMLElement(java.util.Hashtable entities)
          Creates a new XML element.
  XMLElement(java.util.Hashtable entities, boolean skipLeadingWhitespace)
          Creates a new XML element.
  XMLElement(java.util.Hashtable entities, boolean skipLeadingWhitespace, boolean ignoreCase)
          Creates a new XML element.
protected XMLElement(java.util.Hashtable entities, boolean skipLeadingWhitespace, boolean fillBasicConversionTable, boolean ignoreCase)
          Creates a new XML element.
  XMLElement(java.lang.String name, java.lang.String content)
          Creates a new, simple XML element.
 
Method Summary
 void addChild(XMLElement child)
          Adds a subobject.
 void addNode(XMLNode node)
           
 void addProperty(java.lang.String key, double value)
          Adds a property.
 void addProperty(java.lang.String key, int value)
          Adds a property.
 void addProperty(java.lang.String key, java.lang.Object value)
          Adds a property.
protected  boolean checkCDATA(java.lang.StringBuffer buf)
          Scans a special tag and if the tag is a CDATA section, append its content to buf.
protected  boolean checkLiteral(java.lang.String literal)
          Scans the data for literal text.
 int countChildren()
          Returns the number of subobjects of the object.
protected  XMLElement createAnotherElement()
          Creates a new XML element.
 java.util.Enumeration enumerationerateChildren()
          Enumerates the subobjects of the object.
 java.util.Enumeration enumerationeratePropertyNames()
          Enumerates the attribute names.
protected  XMLParseException expectedInput(java.lang.String charSet)
          A character has been expected.
protected  void finalize()
          Cleans up the object when it's destroyed.
 java.util.Vector getChildren()
          Returns the subobjects of the object.
 java.lang.String getContent()
          Returns the #PCDATA content of the object.
 XMLElement getFirstElementWithName(java.lang.String name)
           
 int getLineNr()
          Returns the line nr on which the element is found.
 java.lang.String getName()
          Returns the class (i.e. the name indicated in the element) of the object.
 java.lang.String getProperty(java.lang.String key)
          Returns a property of the object.
 double getProperty(java.lang.String key, double defaultValue)
          Returns a floating point property of the object.
 int getProperty(java.lang.String key, int defaultValue)
          Returns an integer property of the object.
 java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue)
          Returns a property of the object.
protected  XMLParseException invalidValue(java.lang.String key, java.lang.String value)
          Creates a parse exception for when an invalid value is given to a method.
protected  XMLParseException invalidValueSet(java.lang.String key)
          Creates a parse exception for when an invalid valueset is given to a method.
 void parseCharArray(char[] input, int offset, int end)
          Parses an XML definition starting at offset.
 void parseCharArray(char[] input, int offset, int end, int startingLineNr)
          Parses an XML definition starting at offset.
 void parseFromReader(java.io.Reader reader)
          Reads an XML definition from a java.io.Reader and parses it.
 void parseFromReader(java.io.Reader reader, int startingLineNr)
          Reads an XML definition from a java.io.Reader and parses it.
 void parseString(java.lang.String string)
          Parses an XML definition.
 void parseString(java.lang.String string, int offset)
          Parses an XML definition starting at offset.
 void parseString(java.lang.String string, int offset, int end)
          Parses an XML definition starting at offset.
 void parseString(java.lang.String string, int offset, int end, int startingLineNr)
          Parses an XML definition starting at offset.
protected  char readChar()
          Reads a character from a reader.
 void removeChild(XMLElement child)
          Removes a child object.
 void removeProperty(java.lang.String name)
          Removes an attribute.
protected  void resolveEntity(java.lang.StringBuffer buf)
          Resolves an entity.
protected  void scanElement(XMLElement elt)
          Scans an XML element.
protected  void scanIdentifier(java.lang.StringBuffer identifier)
          Scans an identifier.
protected  void scanPCData(java.lang.StringBuffer data)
          Scans a #PCDATA element.
protected  void scanString(java.lang.StringBuffer string)
          Scans a string.
protected  char scanWhitespace()
          Scans whitespace.
protected  char scanWhitespace(java.lang.StringBuffer buf)
          Scans whitespace.
 void setContent(java.lang.String content)
          Changes the content string.
 void setName(java.lang.String name)
          Changes the element name.
protected  void skipComment()
          Skips a comment.
protected  void skipSpecialTag(int bracketLevel)
          Skips a special tag or comment.
protected  XMLParseException syntaxError(java.lang.String context)
          A syntax error occured.
 java.lang.String toString()
          Writes the XML element to a string.
 java.lang.String toStringFormatted()
          Dito, nur formatiert
protected  XMLParseException unexpectedEndOfData()
          The end of the data input has been reached.
protected  XMLParseException unknownEntity(java.lang.String key)
          Invalid entity.
protected  void unreadChar(char ch)
          Adds a character to the read-back buffer.
protected  XMLParseException valueMissingForAttribute(java.lang.String key)
          A value is missing for an attribute.
 void write(java.io.Writer writer, java.lang.String indent, java.lang.String eol, int nestingLevel)
          Writes the XML element to a writer.
protected  void writeEncoded(java.io.Writer writer, java.lang.String str)
          Writes a string encoded to a writer.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NANOXML_MAJOR_VERSION

public static final int NANOXML_MAJOR_VERSION
Major version of NanoXML.

See Also:
Constant Field Values

NANOXML_MINOR_VERSION

public static final int NANOXML_MINOR_VERSION
Minor version of NanoXML.

See Also:
Constant Field Values
Constructor Detail

XMLElement

public XMLElement()
Creates a new XML element. The following settings are used:
Conversion table
Minimal XML conversions: & < > ' "
Skip whitespace in contents
false
Ignore Case
false

See Also:
XMLElement(java.util.Hashtable), XMLElement(boolean), XMLElement(java.util.Hashtable,boolean)

XMLElement

public XMLElement(java.util.Hashtable entities)
Creates a new XML element. The following settings are used:
Conversion table
entities combined with the minimal XML conversions: & < > ' "
Skip whitespace in contents
false
Ignore Case
false

See Also:
XMLElement(), XMLElement(boolean), XMLElement(java.util.Hashtable,boolean)

XMLElement

public XMLElement(boolean skipLeadingWhitespace)
Creates a new XML element. The following settings are used:
Conversion table
Minimal XML conversions: & < > ' "
Skip whitespace in contents
skipLeadingWhitespace
Ignore Case
false

See Also:
XMLElement(), XMLElement(java.util.Hashtable), XMLElement(java.util.Hashtable,boolean)

XMLElement

public XMLElement(java.util.Hashtable entities,
                  boolean skipLeadingWhitespace)
Creates a new XML element. The following settings are used:
Conversion table
entities combined with the minimal XML conversions: & < > ' "
Skip whitespace in contents
skipLeadingWhitespace
Ignore Case
false

See Also:
XMLElement(), XMLElement(boolean), XMLElement(java.util.Hashtable)

XMLElement

public XMLElement(java.util.Hashtable entities,
                  boolean skipLeadingWhitespace,
                  boolean ignoreCase)
Creates a new XML element. The following settings are used:
Conversion table
entities, eventually combined with the minimal XML conversions: & < > ' " (depending on fillBasicConversionTable)
Skip whitespace in contents
skipLeadingWhitespace
Ignore Case
ignoreCase

This constructor should only be called from XMLElement itself to create child elements.

See Also:
XMLElement(), XMLElement(boolean), XMLElement(java.util.Hashtable), XMLElement(java.util.Hashtable,boolean)

XMLElement

public XMLElement(java.lang.String name,
                  java.lang.String content)
Creates a new, simple XML element.

Parameters:
name - The name of the new XML Element
content - The content of the new XML Element
See Also:
XMLElement(), XMLElement(boolean), XMLElement(java.util.Hashtable), XMLElement(java.util.Hashtable,boolean)

XMLElement

protected XMLElement(java.util.Hashtable entities,
                     boolean skipLeadingWhitespace,
                     boolean fillBasicConversionTable,
                     boolean ignoreCase)
Creates a new XML element. The following settings are used:
Conversion table
entities, eventually combined with the minimal XML conversions: & < > ' " (depending on fillBasicConversionTable)
Skip whitespace in contents
skipLeadingWhitespace
Ignore Case
ignoreCase

This constructor should only be called from XMLElement itself to create child elements.

See Also:
XMLElement(), XMLElement(boolean), XMLElement(java.util.Hashtable), XMLElement(java.util.Hashtable,boolean)
Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
Cleans up the object when it's destroyed.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

addChild

public void addChild(XMLElement child)
Adds a subobject.


addProperty

public void addProperty(java.lang.String key,
                        java.lang.Object value)
Adds a property.


addProperty

public void addProperty(java.lang.String key,
                        int value)
Adds a property.


addProperty

public void addProperty(java.lang.String key,
                        double value)
Adds a property.


countChildren

public int countChildren()
Returns the number of subobjects of the object.


enumerationeratePropertyNames

public java.util.Enumeration enumerationeratePropertyNames()
Enumerates the attribute names.


enumerationerateChildren

public java.util.Enumeration enumerationerateChildren()
Enumerates the subobjects of the object.


getChildren

public java.util.Vector getChildren()
Returns the subobjects of the object.


getContent

public java.lang.String getContent()
Returns the #PCDATA content of the object. If there is no such content, null is returned.


getLineNr

public int getLineNr()
Returns the line nr on which the element is found.


getProperty

public java.lang.String getProperty(java.lang.String key)
Returns a property of the object. If there is no such property, this method returns null.


getProperty

public java.lang.String getProperty(java.lang.String key,
                                    java.lang.String defaultValue)
Returns a property of the object. If the property doesn't exist, defaultValue is returned.


getProperty

public int getProperty(java.lang.String key,
                       int defaultValue)
Returns an integer property of the object. If the property doesn't exist, defaultValue is returned.


getProperty

public double getProperty(java.lang.String key,
                          double defaultValue)
Returns a floating point property of the object. If the property doesn't exist, defaultValue is returned.


getName

public java.lang.String getName()
Returns the class (i.e. the name indicated in the element) of the object.


parseFromReader

public void parseFromReader(java.io.Reader reader)
                     throws java.io.IOException,
                            XMLParseException
Reads an XML definition from a java.io.Reader and parses it.

Throws:
java.io.IOException - if an error occured while reading the input
XMLParseException - if an error occured while parsing the read data

parseFromReader

public void parseFromReader(java.io.Reader reader,
                            int startingLineNr)
                     throws java.io.IOException,
                            XMLParseException
Reads an XML definition from a java.io.Reader and parses it.

Throws:
java.io.IOException - if an error occured while reading the input
XMLParseException - if an error occured while parsing the read data

parseString

public void parseString(java.lang.String string)
                 throws XMLParseException
Parses an XML definition.

Throws:
XMLParseException - if an error occured while parsing the string

parseString

public void parseString(java.lang.String string,
                        int offset)
                 throws XMLParseException
Parses an XML definition starting at offset.

Throws:
XMLParseException - if an error occured while parsing the string

parseString

public void parseString(java.lang.String string,
                        int offset,
                        int end)
                 throws XMLParseException
Parses an XML definition starting at offset.

Throws:
XMLParseException - if an error occured while parsing the string

parseString

public void parseString(java.lang.String string,
                        int offset,
                        int end,
                        int startingLineNr)
                 throws XMLParseException
Parses an XML definition starting at offset.

Throws:
XMLParseException - if an error occured while parsing the string

parseCharArray

public void parseCharArray(char[] input,
                           int offset,
                           int end)
                    throws XMLParseException
Parses an XML definition starting at offset.

Throws:
XMLParseException - if an error occured while parsing the array

parseCharArray

public void parseCharArray(char[] input,
                           int offset,
                           int end,
                           int startingLineNr)
                    throws XMLParseException
Parses an XML definition starting at offset.

Throws:
XMLParseException - if an error occured while parsing the array

removeChild

public void removeChild(XMLElement child)
Removes a child object. If the object is not a child, nothing happens.


removeProperty

public void removeProperty(java.lang.String name)
Removes an attribute.


createAnotherElement

protected XMLElement createAnotherElement()
Creates a new XML element.


setContent

public void setContent(java.lang.String content)
Changes the content string.

Parameters:
content - The new content string.

setName

public void setName(java.lang.String name)
Changes the element name.

Parameters:
name - The new name.

toString

public java.lang.String toString()
Writes the XML element to a string.

Overrides:
toString in class java.lang.Object

toStringFormatted

public java.lang.String toStringFormatted()
Dito, nur formatiert


write

public void write(java.io.Writer writer,
                  java.lang.String indent,
                  java.lang.String eol,
                  int nestingLevel)
           throws java.io.IOException
Writes the XML element to a writer.

Throws:
java.io.IOException

writeEncoded

protected void writeEncoded(java.io.Writer writer,
                            java.lang.String str)
                     throws java.io.IOException
Writes a string encoded to a writer.

Throws:
java.io.IOException

scanIdentifier

protected void scanIdentifier(java.lang.StringBuffer identifier)
                       throws java.io.IOException
Scans an identifier.

Throws:
java.io.IOException

scanWhitespace

protected char scanWhitespace()
                       throws java.io.IOException
Scans whitespace.

Throws:
java.io.IOException

scanWhitespace

protected char scanWhitespace(java.lang.StringBuffer buf)
                       throws java.io.IOException
Scans whitespace.

Throws:
java.io.IOException

scanString

protected void scanString(java.lang.StringBuffer string)
                   throws java.io.IOException
Scans a string.

Throws:
java.io.IOException

scanPCData

protected void scanPCData(java.lang.StringBuffer data)
                   throws java.io.IOException
Scans a #PCDATA element. CDATA sections and entities are resolved. The next < char is skipped.

Throws:
java.io.IOException

checkCDATA

protected boolean checkCDATA(java.lang.StringBuffer buf)
                      throws java.io.IOException
Scans a special tag and if the tag is a CDATA section, append its content to buf.

Throws:
java.io.IOException

skipComment

protected void skipComment()
                    throws java.io.IOException
Skips a comment.

Throws:
java.io.IOException

skipSpecialTag

protected void skipSpecialTag(int bracketLevel)
                       throws java.io.IOException
Skips a special tag or comment.

Throws:
java.io.IOException

checkLiteral

protected boolean checkLiteral(java.lang.String literal)
                        throws java.io.IOException
Scans the data for literal text.

Throws:
java.io.IOException

readChar

protected char readChar()
                 throws java.io.IOException
Reads a character from a reader.

Throws:
java.io.IOException

scanElement

protected void scanElement(XMLElement elt)
                    throws java.io.IOException
Scans an XML element.

Throws:
java.io.IOException

resolveEntity

protected void resolveEntity(java.lang.StringBuffer buf)
                      throws java.io.IOException
Resolves an entity.

Throws:
java.io.IOException

unreadChar

protected void unreadChar(char ch)
Adds a character to the read-back buffer.


invalidValueSet

protected XMLParseException invalidValueSet(java.lang.String key)
Creates a parse exception for when an invalid valueset is given to a method.


invalidValue

protected XMLParseException invalidValue(java.lang.String key,
                                         java.lang.String value)
Creates a parse exception for when an invalid value is given to a method.


unexpectedEndOfData

protected XMLParseException unexpectedEndOfData()
The end of the data input has been reached.


syntaxError

protected XMLParseException syntaxError(java.lang.String context)
A syntax error occured.


expectedInput

protected XMLParseException expectedInput(java.lang.String charSet)
A character has been expected.


valueMissingForAttribute

protected XMLParseException valueMissingForAttribute(java.lang.String key)
A value is missing for an attribute.


unknownEntity

protected XMLParseException unknownEntity(java.lang.String key)
Invalid entity.


getFirstElementWithName

public XMLElement getFirstElementWithName(java.lang.String name)

addNode

public void addNode(XMLNode node)