|
From: <ls...@us...> - 2008-05-31 12:36:24
|
Revision: 4163
http://jnode.svn.sourceforge.net/jnode/?rev=4163&view=rev
Author: lsantha
Date: 2008-05-31 05:36:22 -0700 (Sat, 31 May 2008)
Log Message:
-----------
Moved nanoxml to endrosed sources.
Added Paths:
-----------
trunk/core/src/endorsed/
trunk/core/src/endorsed/nanoxml/
trunk/core/src/endorsed/nanoxml/org/
trunk/core/src/endorsed/nanoxml/org/jnode/
trunk/core/src/endorsed/nanoxml/org/jnode/nanoxml/
trunk/core/src/endorsed/nanoxml/org/jnode/nanoxml/XMLElement.java
trunk/core/src/endorsed/nanoxml/org/jnode/nanoxml/XMLParseException.java
Added: trunk/core/src/endorsed/nanoxml/org/jnode/nanoxml/XMLElement.java
===================================================================
--- trunk/core/src/endorsed/nanoxml/org/jnode/nanoxml/XMLElement.java (rev 0)
+++ trunk/core/src/endorsed/nanoxml/org/jnode/nanoxml/XMLElement.java 2008-05-31 12:36:22 UTC (rev 4163)
@@ -0,0 +1,2861 @@
+/* XMLElement.java
+ *
+ * $Revision: 1950 $
+ * $Date: 2005-07-28 12:29:12 +0300 (Thu, 28 Jul 2005) $
+ * $Name$
+ *
+ * This file is part of NanoXML 2 Lite.
+ * Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved.
+ *
+ * This software is provided 'as-is', without any express or implied warranty.
+ * In no event will the authors be held liable for any damages arising from the
+ * use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software in
+ * a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ *
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ *
+ * 3. This notice may not be removed or altered from any source distribution.
+ *****************************************************************************/
+
+
+package org.jnode.nanoxml;
+
+
+import java.io.ByteArrayOutputStream;
+import java.io.CharArrayReader;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Vector;
+
+
+/**
+ * XMLElement is a representation of an XML object. The object is able to parse
+ * XML code.
+ * <P><DL>
+ * <DT><B>Parsing XML Data</B></DT>
+ * <DD>
+ * You can parse XML data using the following code:
+ * <UL><CODE>
+ * XMLElement xml = new XMLElement();<BR>
+ * FileReader reader = new FileReader("filename.xml");<BR>
+ * xml.parseFromReader(reader);
+ * </CODE></UL></DD></DL>
+ * <DL><DT><B>Retrieving Attributes</B></DT>
+ * <DD>
+ * You can enumerate the attributes of an element using the method
+ * {@link #enumerateAttributeNames() enumerateAttributeNames}.
+ * The attribute values can be retrieved using the method
+ * {@link #getStringAttribute(String) getStringAttribute}.
+ * The following example shows how to list the attributes of an element:
+ * <UL><CODE>
+ * XMLElement element = ...;<BR>
+ * Enumeration enum = element.getAttributeNames();<BR>
+ * while (enum.hasMoreElements()) {<BR>
+ * String key = (String) enum.nextElement();<BR>
+ * String value = element.getStringAttribute(key);<BR>
+ * System.out.println(key + " = " + value);<BR>
+ * }
+ * </CODE></UL></DD></DL>
+ * <DL><DT><B>Retrieving Child Elements</B></DT>
+ * <DD>
+ * You can enumerate the children of an element using
+ * {@link #enumerateChildren() enumerateChildren}.
+ * The number of child elements can be retrieved using
+ * {@link #countChildren() countChildren}.
+ * </DD></DL>
+ * <DL><DT><B>Elements Containing Character Data</B></DT>
+ * <DD>
+ * If an elements contains character data, like in the following example:
+ * <UL><CODE>
+ * <title>The Title</title>
+ * </CODE></UL>
+ * you can retrieve that data using the method
+ * {@link #getContent() getContent}.
+ * </DD></DL>
+ * <DL><DT><B>Subclassing XMLElement</B></DT>
+ * <DD>
+ * When subclassing XMLElement, you need to override the method
+ * {@link #createAnotherElement() createAnotherElement}
+ * which has to return a new copy of the receiver.
+ * </DD></DL>
+ * <P>
+ *
+ * @see XMLParseException
+ *
+ * @author Marc De Scheemaecker
+ * <<A href="mailto:cyb...@ma...">cyb...@ma...</A>>
+ * @version $Name$, $Revision: 1950 $
+ */
+public class XMLElement
+{
+
+ /**
+ * Serialization serial version ID.
+ */
+ static final long serialVersionUID = 6685035139346394777L;
+
+
+ /**
+ * Major version of NanoXML. Classes with the same major and minor
+ * version are binary compatible. Classes with the same major version
+ * are source compatible. If the major version is different, you may
+ * need to modify the client source code.
+ *
+ * @see XMLElement#NANOXML_MINOR_VERSION
+ */
+ public static final int NANOXML_MAJOR_VERSION = 2;
+
+
+ /**
+ * Minor version of NanoXML. Classes with the same major and minor
+ * version are binary compatible. Classes with the same major version
+ * are source compatible. If the major version is different, you may
+ * need to modify the client source code.
+ *
+ * @see XMLElement#NANOXML_MAJOR_VERSION
+ */
+ public static final int NANOXML_MINOR_VERSION = 2;
+
+
+ /**
+ * The attributes given to the element.
+ *
+ * <dl><dt><b>Invariants:</b></dt><dd>
+ * <ul><li>The field can be empty.
+ * <li>The field is never <code>null</code>.
+ * <li>The keys and the values are strings.
+ * </ul></dd></dl>
+ */
+ private Map<String, String> attributes;
+
+
+ /**
+ * Child elements of the element.
+ *
+ * <dl><dt><b>Invariants:</b></dt><dd>
+ * <ul><li>The field can be empty.
+ * <li>The field is never <code>null</code>.
+ * <li>The elements are instances of <code>XMLElement</code>
+ * or a subclass of <code>XMLElement</code>.
+ * </ul></dd></dl>
+ */
+ private List<XMLElement> children;
+
+
+ /**
+ * The name of the element.
+ *
+ * <dl><dt><b>Invariants:</b></dt><dd>
+ * <ul><li>The field is <code>null</code> iff the element is not
+ * initialized by either parse or setName.
+ * <li>If the field is not <code>null</code>, it's not empty.
+ * <li>If the field is not <code>null</code>, it contains a valid
+ * XML identifier.
+ * </ul></dd></dl>
+ */
+ private String name;
+
+
+ /**
+ * The #PCDATA content of the object.
+ *
+ * <dl><dt><b>Invariants:</b></dt><dd>
+ * <ul><li>The field is <code>null</code> iff the element is not a
+ * #PCDATA element.
+ * <li>The field can be any string, including the empty string.
+ * </ul></dd></dl>
+ */
+ private String contents;
+
+
+ /**
+ * Conversion table for &...; entities. The keys are the entity names
+ * without the & and ; delimiters.
+ *
+ * <dl><dt><b>Invariants:</b></dt><dd>
+ * <ul><li>The field is never <code>null</code>.
+ * <li>The field always contains the following associations:
+ * "lt" => "<", "gt" => ">",
+ * "quot" => "\"", "apos" => "'",
+ * "amp" => "&"
+ * <li>The keys are strings
+ * <li>The values are char arrays
+ * </ul></dd></dl>
+ */
+ private Hashtable entities;
+
+
+ /**
+ * The line number where the element starts.
+ *
+ * <dl><dt><b>Invariants:</b></dt><dd>
+ * <ul><li><code>lineNr >= 0</code>
+ * </ul></dd></dl>
+ */
+ private int lineNr;
+
+
+ /**
+ * <code>true</code> if the case of the element and attribute names
+ * are case insensitive.
+ */
+ private boolean ignoreCase;
+
+
+ /**
+ * <code>true</code> if the leading and trailing whitespace of #PCDATA
+ * sections have to be ignored.
+ */
+ private boolean ignoreWhitespace;
+
+
+ /**
+ * Character read too much.
+ * This character provides push-back functionality to the input reader
+ * without having to use a PushbackReader.
+ * If there is no such character, this field is '\0'.
+ */
+ private char charReadTooMuch;
+
+
+ /**
+ * The reader provided by the caller of the parse method.
+ *
+ * <dl><dt><b>Invariants:</b></dt><dd>
+ * <ul><li>The field is not <code>null</code> while the parse method
+ * is running.
+ * </ul></dd></dl>
+ */
+ private Reader reader;
+
+
+ /**
+ * The current line number in the source content.
+ *
+ * <dl><dt><b>Invariants:</b></dt><dd>
+ * <ul><li>parserLineNr > 0 while the parse method is running.
+ * </ul></dd></dl>
+ */
+ private int parserLineNr;
+
+
+ /**
+ * Creates and initializes a new XML element.
+ * Calling the construction is equivalent to:
+ * <ul><code>new XMLElement(new Hashtable(), false, true)
+ * </code></ul>
+ *
+ * <dl><dt><b>Postconditions:</b></dt><dd>
+ * <ul><li>countChildren() => 0
+ * <li>enumerateChildren() => empty enumeration
+ * <li>enumeratePropertyNames() => empty enumeration
+ * <li>getChildren() => empty vector
+ * <li>getContent() => ""
+ * <li>getLineNr() => 0
+ * <li>getName() => null
+ * </ul></dd></dl>
+ *
+ * @see XMLElement#XMLElement(java.util.Hashtable)
+ * XMLElement(Hashtable)
+ * @see XMLElement#XMLElement(boolean)
+ * @see XMLElement#XMLElement(java.util.Hashtable,boolean)
+ * XMLElement(Hashtable, boolean)
+ */
+ public XMLElement()
+ {
+ this(new Hashtable(), false, true, true);
+ }
+
+
+ /**
+ * Creates and initializes a new XML element.
+ * Calling the construction is equivalent to:
+ * <ul><code>new XMLElement(entities, false, true)
+ * </code></ul>
+ *
+ * @param entities
+ * The entity conversion table.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>entities != null</code>
+ * </ul></dd></dl>
+ *
+ * <dl><dt><b>Postconditions:</b></dt><dd>
+ * <ul><li>countChildren() => 0
+ * <li>enumerateChildren() => empty enumeration
+ * <li>enumeratePropertyNames() => empty enumeration
+ * <li>getChildren() => empty vector
+ * <li>getContent() => ""
+ * <li>getLineNr() => 0
+ * <li>getName() => null
+ * </ul></dd></dl><dl>
+ *
+ * @see XMLElement#XMLElement()
+ * @see XMLElement#XMLElement(boolean)
+ * @see XMLElement#XMLElement(java.util.Hashtable,boolean)
+ * XMLElement(Hashtable, boolean)
+ */
+ public XMLElement(Hashtable entities)
+ {
+ this(entities, false, true, true);
+ }
+
+
+ /**
+ * Creates and initializes a new XML element.
+ * Calling the construction is equivalent to:
+ * <ul><code>new XMLElement(new Hashtable(), skipLeadingWhitespace, true)
+ * </code></ul>
+ *
+ * @param skipLeadingWhitespace
+ * <code>true</code> if leading and trailing whitespace in PCDATA
+ * content has to be removed.
+ *
+ * </dl><dl><dt><b>Postconditions:</b></dt><dd>
+ * <ul><li>countChildren() => 0
+ * <li>enumerateChildren() => empty enumeration
+ * <li>enumeratePropertyNames() => empty enumeration
+ * <li>getChildren() => empty vector
+ * <li>getContent() => ""
+ * <li>getLineNr() => 0
+ * <li>getName() => null
+ * </ul></dd></dl><dl>
+ *
+ * @see XMLElement#XMLElement()
+ * @see XMLElement#XMLElement(java.util.Hashtable)
+ * XMLElement(Hashtable)
+ * @see XMLElement#XMLElement(java.util.Hashtable,boolean)
+ * XMLElement(Hashtable, boolean)
+ */
+ public XMLElement(boolean skipLeadingWhitespace)
+ {
+ this(new Hashtable(), skipLeadingWhitespace, true, true);
+ }
+
+
+ /**
+ * Creates and initializes a new XML element.
+ * Calling the construction is equivalent to:
+ * <ul><code>new XMLElement(entities, skipLeadingWhitespace, true)
+ * </code></ul>
+ *
+ * @param entities
+ * The entity conversion table.
+ * @param skipLeadingWhitespace
+ * <code>true</code> if leading and trailing whitespace in PCDATA
+ * content has to be removed.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>entities != null</code>
+ * </ul></dd></dl>
+ *
+ * <dl><dt><b>Postconditions:</b></dt><dd>
+ * <ul><li>countChildren() => 0
+ * <li>enumerateChildren() => empty enumeration
+ * <li>enumeratePropertyNames() => empty enumeration
+ * <li>getChildren() => empty vector
+ * <li>getContent() => ""
+ * <li>getLineNr() => 0
+ * <li>getName() => null
+ * </ul></dd></dl><dl>
+ *
+ * @see XMLElement#XMLElement()
+ * @see XMLElement#XMLElement(boolean)
+ * @see XMLElement#XMLElement(java.util.Hashtable)
+ * XMLElement(Hashtable)
+ */
+ public XMLElement(Hashtable entities,
+ boolean skipLeadingWhitespace)
+ {
+ this(entities, skipLeadingWhitespace, true, true);
+ }
+
+
+ /**
+ * Creates and initializes a new XML element.
+ *
+ * @param entities
+ * The entity conversion table.
+ * @param skipLeadingWhitespace
+ * <code>true</code> if leading and trailing whitespace in PCDATA
+ * content has to be removed.
+ * @param ignoreCase
+ * <code>true</code> if the case of element and attribute names have
+ * to be ignored.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>entities != null</code>
+ * </ul></dd></dl>
+ *
+ * <dl><dt><b>Postconditions:</b></dt><dd>
+ * <ul><li>countChildren() => 0
+ * <li>enumerateChildren() => empty enumeration
+ * <li>enumeratePropertyNames() => empty enumeration
+ * <li>getChildren() => empty vector
+ * <li>getContent() => ""
+ * <li>getLineNr() => 0
+ * <li>getName() => null
+ * </ul></dd></dl><dl>
+ *
+ * @see XMLElement#XMLElement()
+ * @see XMLElement#XMLElement(boolean)
+ * @see XMLElement#XMLElement(java.util.Hashtable)
+ * XMLElement(Hashtable)
+ * @see XMLElement#XMLElement(java.util.Hashtable,boolean)
+ * XMLElement(Hashtable, boolean)
+ */
+ public XMLElement(Hashtable entities,
+ boolean skipLeadingWhitespace,
+ boolean ignoreCase)
+ {
+ this(entities, skipLeadingWhitespace, true, ignoreCase);
+ }
+
+
+ /**
+ * Creates and initializes a new XML element.
+ * <P>
+ * This constructor should <I>only</I> be called from
+ * {@link #createAnotherElement() createAnotherElement}
+ * to create child elements.
+ *
+ * @param entities
+ * The entity conversion table.
+ * @param skipLeadingWhitespace
+ * <code>true</code> if leading and trailing whitespace in PCDATA
+ * content has to be removed.
+ * @param fillBasicConversionTable
+ * <code>true</code> if the basic entities need to be added to
+ * the entity list.
+ * @param ignoreCase
+ * <code>true</code> if the case of element and attribute names have
+ * to be ignored.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>entities != null</code>
+ * <li>if <code>fillBasicConversionTable == false</code>
+ * then <code>entities</code> contains at least the following
+ * entries: <code>amp</code>, <code>lt</code>, <code>gt</code>,
+ * <code>apos</code> and <code>quot</code>
+ * </ul></dd></dl>
+ *
+ * <dl><dt><b>Postconditions:</b></dt><dd>
+ * <ul><li>countChildren() => 0
+ * <li>enumerateChildren() => empty enumeration
+ * <li>enumeratePropertyNames() => empty enumeration
+ * <li>getChildren() => empty vector
+ * <li>getContent() => ""
+ * <li>getLineNr() => 0
+ * <li>getName() => null
+ * </ul></dd></dl><dl>
+ *
+ * @see XMLElement#createAnotherElement()
+ */
+ protected XMLElement(Hashtable entities,
+ boolean skipLeadingWhitespace,
+ boolean fillBasicConversionTable,
+ boolean ignoreCase)
+ {
+ this.ignoreWhitespace = skipLeadingWhitespace;
+ this.ignoreCase = ignoreCase;
+ this.name = null;
+ this.contents = "";
+ this.attributes = new HashMap<String, String>();
+ this.children = new ArrayList<XMLElement>();
+ this.entities = entities;
+ this.lineNr = 0;
+ Enumeration e = this.entities.keys();
+ while (e.hasMoreElements()) {
+ Object key = e.nextElement();
+ Object value = this.entities.get(key);
+ if (value instanceof String) {
+ value = ((String) value).toCharArray();
+ this.entities.put(key, value);
+ }
+ }
+ if (fillBasicConversionTable) {
+ this.entities.put("amp", new char[] { '&' });
+ this.entities.put("quot", new char[] { '"' });
+ this.entities.put("apos", new char[] { '\'' });
+ this.entities.put("lt", new char[] { '<' });
+ this.entities.put("gt", new char[] { '>' });
+ }
+ }
+
+
+ /**
+ * Adds a child element.
+ *
+ * @param child
+ * The child element to add.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>child != null</code>
+ * <li><code>child.getName() != null</code>
+ * <li><code>child</code> does not have a parent element
+ * </ul></dd></dl>
+ *
+ * <dl><dt><b>Postconditions:</b></dt><dd>
+ * <ul><li>countChildren() => old.countChildren() + 1
+ * <li>enumerateChildren() => old.enumerateChildren() + child
+ * <li>getChildren() => old.enumerateChildren() + child
+ * </ul></dd></dl><dl>
+ *
+ * @see XMLElement#countChildren()
+ * @see XMLElement#enumerateChildren()
+ * @see XMLElement#getChildren()
+ * @see XMLElement#removeChild(XMLElement)
+ * removeChild(XMLElement)
+ */
+ public void addChild(XMLElement child)
+ {
+ this.children.add(child);
+ }
+
+
+ /**
+ * Adds or modifies an attribute.
+ *
+ * @param name
+ * The name of the attribute.
+ * @param value
+ * The value of the attribute.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>name != null</code>
+ * <li><code>name</code> is a valid XML identifier
+ * <li><code>value != null</code>
+ * </ul></dd></dl>
+ *
+ * <dl><dt><b>Postconditions:</b></dt><dd>
+ * <ul><li>enumerateAttributeNames()
+ * => old.enumerateAttributeNames() + name
+ * <li>getAttribute(name) => value
+ * </ul></dd></dl><dl>
+ *
+ * @see XMLElement#setDoubleAttribute(String, double)
+ * setDoubleAttribute(String, double)
+ * @see XMLElement#setIntAttribute(String, int)
+ * setIntAttribute(String, int)
+ * @see XMLElement#enumerateAttributeNames()
+ * @see XMLElement#getAttribute(String)
+ * getAttribute(String)
+ * @see XMLElement#getAttribute(String, Object)
+ * getAttribute(String, Object)
+ * @see XMLElement#getAttribute(String,
+ * java.util.Hashtable,
+ * String, boolean)
+ * getAttribute(String, Hashtable, String, boolean)
+ * @see XMLElement#getStringAttribute(String)
+ * getStringAttribute(String)
+ * @see XMLElement#getStringAttribute(String,
+ * String)
+ * getStringAttribute(String, String)
+ * @see XMLElement#getStringAttribute(String,
+ * java.util.Hashtable,
+ * String, boolean)
+ * getStringAttribute(String, Hashtable, String, boolean)
+ */
+ public void setAttribute(String name,
+ Object value)
+ {
+ if (this.ignoreCase) {
+ name = name.toUpperCase();
+ }
+ this.attributes.put(name, value.toString());
+ }
+
+
+ /**
+ * Adds or modifies an attribute.
+ *
+ * @param name
+ * The name of the attribute.
+ * @param value
+ * The value of the attribute.
+ *
+ * @deprecated Use {@link #setAttribute(String, Object)
+ * setAttribute} instead.
+ */
+ public void addProperty(String name,
+ Object value)
+ {
+ this.setAttribute(name, value);
+ }
+
+
+ /**
+ * Adds or modifies an attribute.
+ *
+ * @param name
+ * The name of the attribute.
+ * @param value
+ * The value of the attribute.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>name != null</code>
+ * <li><code>name</code> is a valid XML identifier
+ * </ul></dd></dl>
+ *
+ * <dl><dt><b>Postconditions:</b></dt><dd>
+ * <ul><li>enumerateAttributeNames()
+ * => old.enumerateAttributeNames() + name
+ * <li>getIntAttribute(name) => value
+ * </ul></dd></dl><dl>
+ *
+ * @see XMLElement#setDoubleAttribute(String, double)
+ * setDoubleAttribute(String, double)
+ * @see XMLElement#setAttribute(String, Object)
+ * setAttribute(String, Object)
+ * @see XMLElement#removeAttribute(String)
+ * removeAttribute(String)
+ * @see XMLElement#enumerateAttributeNames()
+ * @see XMLElement#getIntAttribute(String)
+ * getIntAttribute(String)
+ * @see XMLElement#getIntAttribute(String, int)
+ * getIntAttribute(String, int)
+ * @see XMLElement#getIntAttribute(String,
+ * java.util.Hashtable,
+ * String, boolean)
+ * getIntAttribute(String, Hashtable, String, boolean)
+ */
+ public void setIntAttribute(String name,
+ int value)
+ {
+ if (this.ignoreCase) {
+ name = name.toUpperCase();
+ }
+ this.attributes.put(name, Integer.toString(value));
+ }
+
+
+ /**
+ * Adds or modifies an attribute.
+ *
+ * @param name
+ * The name of the attribute.
+ * @param value
+ * The value of the attribute.
+ *
+ * @deprecated Use {@link #setIntAttribute(String, int)
+ * setIntAttribute} instead.
+ */
+ public void addProperty(String key,
+ int value)
+ {
+ this.setIntAttribute(key, value);
+ }
+
+
+ /**
+ * Adds or modifies an attribute.
+ *
+ * @param name
+ * The name of the attribute.
+ * @param value
+ * The value of the attribute.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>name != null</code>
+ * <li><code>name</code> is a valid XML identifier
+ * </ul></dd></dl>
+ *
+ * <dl><dt><b>Postconditions:</b></dt><dd>
+ * <ul><li>enumerateAttributeNames()
+ * => old.enumerateAttributeNames() + name
+ * <li>getDoubleAttribute(name) => value
+ * </ul></dd></dl><dl>
+ *
+ * @see XMLElement#setIntAttribute(String, int)
+ * setIntAttribute(String, int)
+ * @see XMLElement#setAttribute(String, Object)
+ * setAttribute(String, Object)
+ * @see XMLElement#removeAttribute(String)
+ * removeAttribute(String)
+ * @see XMLElement#enumerateAttributeNames()
+ * @see XMLElement#getDoubleAttribute(String)
+ * getDoubleAttribute(String)
+ * @see XMLElement#getDoubleAttribute(String, double)
+ * getDoubleAttribute(String, double)
+ * @see XMLElement#getDoubleAttribute(String,
+ * java.util.Hashtable,
+ * String, boolean)
+ * getDoubleAttribute(String, Hashtable, String, boolean)
+ */
+ public void setDoubleAttribute(String name,
+ double value)
+ {
+ if (this.ignoreCase) {
+ name = name.toUpperCase();
+ }
+ this.attributes.put(name, Double.toString(value));
+ }
+
+
+ /**
+ * Adds or modifies an attribute.
+ *
+ * @param name
+ * The name of the attribute.
+ * @param value
+ * The value of the attribute.
+ *
+ * @deprecated Use {@link #setDoubleAttribute(String, double)
+ * setDoubleAttribute} instead.
+ */
+ public void addProperty(String name,
+ double value)
+ {
+ this.setDoubleAttribute(name, value);
+ }
+
+
+ /**
+ * Returns the number of child elements of the element.
+ *
+ * <dl><dt><b>Postconditions:</b></dt><dd>
+ * <ul><li><code>result >= 0</code>
+ * </ul></dd></dl>
+ *
+ * @see XMLElement#addChild(XMLElement)
+ * addChild(XMLElement)
+ * @see XMLElement#enumerateChildren()
+ * @see XMLElement#getChildren()
+ * @see XMLElement#removeChild(XMLElement)
+ * removeChild(XMLElement)
+ */
+ public int countChildren()
+ {
+ return this.children.size();
+ }
+
+
+ /**
+ * Enumerates the attribute names.
+ *
+ * <dl><dt><b>Postconditions:</b></dt><dd>
+ * <ul><li><code>result != null</code>
+ * </ul></dd></dl>
+ *
+ * @see XMLElement#setDoubleAttribute(String, double)
+ * setDoubleAttribute(String, double)
+ * @see XMLElement#setIntAttribute(String, int)
+ * setIntAttribute(String, int)
+ * @see XMLElement#setAttribute(String, Object)
+ * setAttribute(String, Object)
+ * @see XMLElement#removeAttribute(String)
+ * removeAttribute(String)
+ * @see XMLElement#getAttribute(String)
+ * getAttribute(String)
+ * @see XMLElement#getAttribute(String, Object)
+ * getAttribute(String, String)
+ * @see XMLElement#getAttribute(String,
+ * java.util.Hashtable,
+ * String, boolean)
+ * getAttribute(String, Hashtable, String, boolean)
+ * @see XMLElement#getStringAttribute(String)
+ * getStringAttribute(String)
+ * @see XMLElement#getStringAttribute(String,
+ * String)
+ * getStringAttribute(String, String)
+ * @see XMLElement#getStringAttribute(String,
+ * java.util.Hashtable,
+ * String, boolean)
+ * getStringAttribute(String, Hashtable, String, boolean)
+ * @see XMLElement#getIntAttribute(String)
+ * getIntAttribute(String)
+ * @see XMLElement#getIntAttribute(String, int)
+ * getIntAttribute(String, int)
+ * @see XMLElement#getIntAttribute(String,
+ * java.util.Hashtable,
+ * String, boolean)
+ * getIntAttribute(String, Hashtable, String, boolean)
+ * @see XMLElement#getDoubleAttribute(String)
+ * getDoubleAttribute(String)
+ * @see XMLElement#getDoubleAttribute(String, double)
+ * getDoubleAttribute(String, double)
+ * @see XMLElement#getDoubleAttribute(String,
+ * java.util.Hashtable,
+ * String, boolean)
+ * getDoubleAttribute(String, Hashtable, String, boolean)
+ * @see XMLElement#getBooleanAttribute(String,
+ * String,
+ * String, boolean)
+ * getBooleanAttribute(String, String, String, boolean)
+ */
+ public Set<String> attributeNames()
+ {
+ return Collections.unmodifiableSet(this.attributes.keySet());
+ }
+
+
+ /**
+ * Enumerates the child elements.
+ *
+ * <dl><dt><b>Postconditions:</b></dt><dd>
+ * <ul><li><code>result != null</code>
+ * </ul></dd></dl>
+ *
+ * @see XMLElement#addChild(XMLElement)
+ * addChild(XMLElement)
+ * @see XMLElement#countChildren()
+ * @see XMLElement#getChildren()
+ * @see XMLElement#removeChild(XMLElement)
+ * removeChild(XMLElement)
+ */
+ public Iterator<XMLElement> iteratorChildren()
+ {
+ return this.children.iterator();
+ }
+
+
+ /**
+ * Returns the child elements as a Vector. It is safe to modify this
+ * Vector.
+ *
+ * <dl><dt><b>Postconditions:</b></dt><dd>
+ * <ul><li><code>result != null</code>
+ * </ul></dd></dl>
+ *
+ * @see XMLElement#addChild(XMLElement)
+ * addChild(XMLElement)
+ * @see XMLElement#countChildren()
+ * @see XMLElement#enumerateChildren()
+ * @see XMLElement#removeChild(XMLElement)
+ * removeChild(XMLElement)
+ */
+ public List<XMLElement> getChildren()
+ {
+ return new ArrayList<XMLElement>(this.children);
+ }
+
+
+ /**
+ * Returns the PCDATA content of the object. If there is no such content,
+ * <CODE>null</CODE> is returned.
+ *
+ * @deprecated Use {@link #getContent() getContent} instead.
+ */
+ public String getContents()
+ {
+ return this.getContent();
+ }
+
+
+ /**
+ * Returns the PCDATA content of the object. If there is no such content,
+ * <CODE>null</CODE> is returned.
+ *
+ * @see XMLElement#setContent(String)
+ * setContent(String)
+ */
+ public String getContent()
+ {
+ return this.contents;
+ }
+
+
+ /**
+ * Returns the line nr in the source data on which the element is found.
+ * This method returns <code>0</code> there is no associated source data.
+ *
+ * <dl><dt><b>Postconditions:</b></dt><dd>
+ * <ul><li><code>result >= 0</code>
+ * </ul></dd></dl>
+ */
+ public int getLineNr()
+ {
+ return this.lineNr;
+ }
+
+
+ /**
+ * Returns an attribute of the element.
+ * If the attribute doesn't exist, <code>null</code> is returned.
+ *
+ * @param name The name of the attribute.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>name != null</code>
+ * <li><code>name</code> is a valid XML identifier
+ * </ul></dd></dl><dl>
+ *
+ * @see XMLElement#setAttribute(String, Object)
+ * setAttribute(String, Object)
+ * @see XMLElement#removeAttribute(String)
+ * removeAttribute(String)
+ * @see XMLElement#enumerateAttributeNames()
+ * @see XMLElement#getAttribute(String, Object)
+ * getAttribute(String, Object)
+ * @see XMLElement#getAttribute(String,
+ * java.util.Hashtable,
+ * String, boolean)
+ * getAttribute(String, Hashtable, String, boolean)
+ */
+ public Object getAttribute(String name)
+ {
+ return this.getAttribute(name, null);
+ }
+
+
+ /**
+ * Returns an attribute of the element.
+ * If the attribute doesn't exist, <code>defaultValue</code> is returned.
+ *
+ * @param name The name of the attribute.
+ * @param defaultValue Key to use if the attribute is missing.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>name != null</code>
+ * <li><code>name</code> is a valid XML identifier
+ * </ul></dd></dl><dl>
+ *
+ * @see XMLElement#setAttribute(String, Object)
+ * setAttribute(String, Object)
+ * @see XMLElement#removeAttribute(String)
+ * removeAttribute(String)
+ * @see XMLElement#enumerateAttributeNames()
+ * @see XMLElement#getAttribute(String)
+ * getAttribute(String)
+ * @see XMLElement#getAttribute(String,
+ * java.util.Hashtable,
+ * String, boolean)
+ * getAttribute(String, Hashtable, String, boolean)
+ */
+ public Object getAttribute(String name,
+ Object defaultValue)
+ {
+ if (this.ignoreCase) {
+ name = name.toUpperCase();
+ }
+ Object value = this.attributes.get(name);
+ if (value == null) {
+ value = defaultValue;
+ }
+ return value;
+ }
+
+
+ /**
+ * Returns an attribute by looking up a key in a hashtable.
+ * If the attribute doesn't exist, the value corresponding to defaultKey
+ * is returned.
+ * <P>
+ * As an example, if valueSet contains the mapping <code>"one" =>
+ * "1"</code>
+ * and the element contains the attribute <code>attr="one"</code>, then
+ * <code>getAttribute("attr", mapping, defaultKey, false)</code> returns
+ * <code>"1"</code>.
+ *
+ * @param name
+ * The name of the attribute.
+ * @param valueSet
+ * Hashtable mapping keys to values.
+ * @param defaultKey
+ * Key to use if the attribute is missing.
+ * @param allowLiterals
+ * <code>true</code> if literals are valid.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>name != null</code>
+ * <li><code>name</code> is a valid XML identifier
+ * <li><code>valueSet</code> != null
+ * <li>the keys of <code>valueSet</code> are strings
+ * </ul></dd></dl><dl>
+ *
+ * @see XMLElement#setAttribute(String, Object)
+ * setAttribute(String, Object)
+ * @see XMLElement#removeAttribute(String)
+ * removeAttribute(String)
+ * @see XMLElement#enumerateAttributeNames()
+ * @see XMLElement#getAttribute(String)
+ * getAttribute(String)
+ * @see XMLElement#getAttribute(String, Object)
+ * getAttribute(String, Object)
+ */
+ public Object getAttribute(String name,
+ Hashtable valueSet,
+ String defaultKey,
+ boolean allowLiterals)
+ {
+ if (this.ignoreCase) {
+ name = name.toUpperCase();
+ }
+ Object key = this.attributes.get(name);
+ Object result;
+ if (key == null) {
+ key = defaultKey;
+ }
+ result = valueSet.get(key);
+ if (result == null) {
+ if (allowLiterals) {
+ result = key;
+ } else {
+ throw this.invalidValue(name, (String) key);
+ }
+ }
+ return result;
+ }
+
+
+ /**
+ * Returns an attribute of the element.
+ * If the attribute doesn't exist, <code>null</code> is returned.
+ *
+ * @param name The name of the attribute.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>name != null</code>
+ * <li><code>name</code> is a valid XML identifier
+ * </ul></dd></dl><dl>
+ *
+ * @see XMLElement#setAttribute(String, Object)
+ * setAttribute(String, Object)
+ * @see XMLElement#removeAttribute(String)
+ * removeAttribute(String)
+ * @see XMLElement#enumerateAttributeNames()
+ * @see XMLElement#getStringAttribute(String,
+ * String)
+ * getStringAttribute(String, String)
+ * @see XMLElement#getStringAttribute(String,
+ * java.util.Hashtable,
+ * String, boolean)
+ * getStringAttribute(String, Hashtable, String, boolean)
+ */
+ public String getStringAttribute(String name)
+ {
+ return this.getStringAttribute(name, null);
+ }
+
+
+ /**
+ * Returns an attribute of the element.
+ * If the attribute doesn't exist, <code>defaultValue</code> is returned.
+ *
+ * @param name The name of the attribute.
+ * @param defaultValue Key to use if the attribute is missing.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>name != null</code>
+ * <li><code>name</code> is a valid XML identifier
+ * </ul></dd></dl><dl>
+ *
+ * @see XMLElement#setAttribute(String, Object)
+ * setAttribute(String, Object)
+ * @see XMLElement#removeAttribute(String)
+ * removeAttribute(String)
+ * @see XMLElement#enumerateAttributeNames()
+ * @see XMLElement#getStringAttribute(String)
+ * getStringAttribute(String)
+ * @see XMLElement#getStringAttribute(String,
+ * java.util.Hashtable,
+ * String, boolean)
+ * getStringAttribute(String, Hashtable, String, boolean)
+ */
+ public String getStringAttribute(String name,
+ String defaultValue)
+ {
+ return (String) this.getAttribute(name, defaultValue);
+ }
+
+
+ /**
+ * Returns an attribute by looking up a key in a hashtable.
+ * If the attribute doesn't exist, the value corresponding to defaultKey
+ * is returned.
+ * <P>
+ * As an example, if valueSet contains the mapping <code>"one" =>
+ * "1"</code>
+ * and the element contains the attribute <code>attr="one"</code>, then
+ * <code>getAttribute("attr", mapping, defaultKey, false)</code> returns
+ * <code>"1"</code>.
+ *
+ * @param name
+ * The name of the attribute.
+ * @param valueSet
+ * Hashtable mapping keys to values.
+ * @param defaultKey
+ * Key to use if the attribute is missing.
+ * @param allowLiterals
+ * <code>true</code> if literals are valid.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>name != null</code>
+ * <li><code>name</code> is a valid XML identifier
+ * <li><code>valueSet</code> != null
+ * <li>the keys of <code>valueSet</code> are strings
+ * <li>the values of <code>valueSet</code> are strings
+ * </ul></dd></dl><dl>
+ *
+ * @see XMLElement#setAttribute(String, Object)
+ * setAttribute(String, Object)
+ * @see XMLElement#removeAttribute(String)
+ * removeAttribute(String)
+ * @see XMLElement#enumerateAttributeNames()
+ * @see XMLElement#getStringAttribute(String)
+ * getStringAttribute(String)
+ * @see XMLElement#getStringAttribute(String,
+ * String)
+ * getStringAttribute(String, String)
+ */
+ public String getStringAttribute(String name,
+ Hashtable valueSet,
+ String defaultKey,
+ boolean allowLiterals)
+ {
+ return (String) this.getAttribute(name, valueSet, defaultKey,
+ allowLiterals);
+ }
+
+
+ /**
+ * Returns an attribute of the element.
+ * If the attribute doesn't exist, <code>0</code> is returned.
+ *
+ * @param name The name of the attribute.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>name != null</code>
+ * <li><code>name</code> is a valid XML identifier
+ * </ul></dd></dl><dl>
+ *
+ * @see XMLElement#setIntAttribute(String, int)
+ * setIntAttribute(String, int)
+ * @see XMLElement#enumerateAttributeNames()
+ * @see XMLElement#getIntAttribute(String, int)
+ * getIntAttribute(String, int)
+ * @see XMLElement#getIntAttribute(String,
+ * java.util.Hashtable,
+ * String, boolean)
+ * getIntAttribute(String, Hashtable, String, boolean)
+ */
+ public int getIntAttribute(String name)
+ {
+ return this.getIntAttribute(name, 0);
+ }
+
+
+ /**
+ * Returns an attribute of the element.
+ * If the attribute doesn't exist, <code>defaultValue</code> is returned.
+ *
+ * @param name The name of the attribute.
+ * @param defaultValue Key to use if the attribute is missing.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>name != null</code>
+ * <li><code>name</code> is a valid XML identifier
+ * </ul></dd></dl><dl>
+ *
+ * @see XMLElement#setIntAttribute(String, int)
+ * setIntAttribute(String, int)
+ * @see XMLElement#enumerateAttributeNames()
+ * @see XMLElement#getIntAttribute(String)
+ * getIntAttribute(String)
+ * @see XMLElement#getIntAttribute(String,
+ * java.util.Hashtable,
+ * String, boolean)
+ * getIntAttribute(String, Hashtable, String, boolean)
+ */
+ public int getIntAttribute(String name,
+ int defaultValue)
+ {
+ if (this.ignoreCase) {
+ name = name.toUpperCase();
+ }
+ String value = (String) this.attributes.get(name);
+ if (value == null) {
+ return defaultValue;
+ } else {
+ try {
+ return Integer.parseInt(value);
+ } catch (NumberFormatException e) {
+ throw this.invalidValue(name, value);
+ }
+ }
+ }
+
+
+ /**
+ * Returns an attribute by looking up a key in a hashtable.
+ * If the attribute doesn't exist, the value corresponding to defaultKey
+ * is returned.
+ * <P>
+ * As an example, if valueSet contains the mapping <code>"one" => 1</code>
+ * and the element contains the attribute <code>attr="one"</code>, then
+ * <code>getIntAttribute("attr", mapping, defaultKey, false)</code> returns
+ * <code>1</code>.
+ *
+ * @param name
+ * The name of the attribute.
+ * @param valueSet
+ * Hashtable mapping keys to values.
+ * @param defaultKey
+ * Key to use if the attribute is missing.
+ * @param allowLiteralNumbers
+ * <code>true</code> if literal numbers are valid.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>name != null</code>
+ * <li><code>name</code> is a valid XML identifier
+ * <li><code>valueSet</code> != null
+ * <li>the keys of <code>valueSet</code> are strings
+ * <li>the values of <code>valueSet</code> are Integer objects
+ * <li><code>defaultKey</code> is either <code>null</code>, a
+ * key in <code>valueSet</code> or an integer.
+ * </ul></dd></dl><dl>
+ *
+ * @see XMLElement#setIntAttribute(String, int)
+ * setIntAttribute(String, int)
+ * @see XMLElement#enumerateAttributeNames()
+ * @see XMLElement#getIntAttribute(String)
+ * getIntAttribute(String)
+ * @see XMLElement#getIntAttribute(String, int)
+ * getIntAttribute(String, int)
+ */
+ public int getIntAttribute(String name,
+ Hashtable valueSet,
+ String defaultKey,
+ boolean allowLiteralNumbers)
+ {
+ if (this.ignoreCase) {
+ name = name.toUpperCase();
+ }
+ Object key = this.attributes.get(name);
+ Integer result;
+ if (key == null) {
+ key = defaultKey;
+ }
+ try {
+ result = (Integer) valueSet.get(key);
+ } catch (ClassCastException e) {
+ throw this.invalidValueSet(name);
+ }
+ if (result == null) {
+ if (! allowLiteralNumbers) {
+ throw this.invalidValue(name, (String) key);
+ }
+ try {
+ result = Integer.valueOf((String) key);
+ } catch (NumberFormatException e) {
+ throw this.invalidValue(name, (String) key);
+ }
+ }
+ return result.intValue();
+ }
+
+
+ /**
+ * Returns an attribute of the element.
+ * If the attribute doesn't exist, <code>0.0</code> is returned.
+ *
+ * @param name The name of the attribute.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>name != null</code>
+ * <li><code>name</code> is a valid XML identifier
+ * </ul></dd></dl><dl>
+ *
+ * @see XMLElement#setDoubleAttribute(String, double)
+ * setDoubleAttribute(String, double)
+ * @see XMLElement#enumerateAttributeNames()
+ * @see XMLElement#getDoubleAttribute(String, double)
+ * getDoubleAttribute(String, double)
+ * @see XMLElement#getDoubleAttribute(String,
+ * java.util.Hashtable,
+ * String, boolean)
+ * getDoubleAttribute(String, Hashtable, String, boolean)
+ */
+ public double getDoubleAttribute(String name)
+ {
+ return this.getDoubleAttribute(name, 0.);
+ }
+
+
+ /**
+ * Returns an attribute of the element.
+ * If the attribute doesn't exist, <code>defaultValue</code> is returned.
+ *
+ * @param name The name of the attribute.
+ * @param defaultValue Key to use if the attribute is missing.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>name != null</code>
+ * <li><code>name</code> is a valid XML identifier
+ * </ul></dd></dl><dl>
+ *
+ * @see XMLElement#setDoubleAttribute(String, double)
+ * setDoubleAttribute(String, double)
+ * @see XMLElement#enumerateAttributeNames()
+ * @see XMLElement#getDoubleAttribute(String)
+ * getDoubleAttribute(String)
+ * @see XMLElement#getDoubleAttribute(String,
+ * java.util.Hashtable,
+ * String, boolean)
+ * getDoubleAttribute(String, Hashtable, String, boolean)
+ */
+ public double getDoubleAttribute(String name,
+ double defaultValue)
+ {
+ if (this.ignoreCase) {
+ name = name.toUpperCase();
+ }
+ String value = (String) this.attributes.get(name);
+ if (value == null) {
+ return defaultValue;
+ } else {
+ try {
+ return Double.valueOf(value).doubleValue();
+ } catch (NumberFormatException e) {
+ throw this.invalidValue(name, value);
+ }
+ }
+ }
+
+
+ /**
+ * Returns an attribute by looking up a key in a hashtable.
+ * If the attribute doesn't exist, the value corresponding to defaultKey
+ * is returned.
+ * <P>
+ * As an example, if valueSet contains the mapping <code>"one" =>
+ * 1.0</code>
+ * and the element contains the attribute <code>attr="one"</code>, then
+ * <code>getDoubleAttribute("attr", mapping, defaultKey, false)</code>
+ * returns <code>1.0</code>.
+ *
+ * @param name
+ * The name of the attribute.
+ * @param valueSet
+ * Hashtable mapping keys to values.
+ * @param defaultKey
+ * Key to use if the attribute is missing.
+ * @param allowLiteralNumbers
+ * <code>true</code> if literal numbers are valid.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>name != null</code>
+ * <li><code>name</code> is a valid XML identifier
+ * <li><code>valueSet != null</code>
+ * <li>the keys of <code>valueSet</code> are strings
+ * <li>the values of <code>valueSet</code> are Double objects
+ * <li><code>defaultKey</code> is either <code>null</code>, a
+ * key in <code>valueSet</code> or a double.
+ * </ul></dd></dl><dl>
+ *
+ * @see XMLElement#setDoubleAttribute(String, double)
+ * setDoubleAttribute(String, double)
+ * @see XMLElement#enumerateAttributeNames()
+ * @see XMLElement#getDoubleAttribute(String)
+ * getDoubleAttribute(String)
+ * @see XMLElement#getDoubleAttribute(String, double)
+ * getDoubleAttribute(String, double)
+ */
+ public double getDoubleAttribute(String name,
+ Hashtable valueSet,
+ String defaultKey,
+ boolean allowLiteralNumbers)
+ {
+ if (this.ignoreCase) {
+ name = name.toUpperCase();
+ }
+ Object key = this.attributes.get(name);
+ Double result;
+ if (key == null) {
+ key = defaultKey;
+ }
+ try {
+ result = (Double) valueSet.get(key);
+ } catch (ClassCastException e) {
+ throw this.invalidValueSet(name);
+ }
+ if (result == null) {
+ if (! allowLiteralNumbers) {
+ throw this.invalidValue(name, (String) key);
+ }
+ try {
+ result = Double.valueOf((String) key);
+ } catch (NumberFormatException e) {
+ throw this.invalidValue(name, (String) key);
+ }
+ }
+ return result.doubleValue();
+ }
+
+
+ /**
+ * Returns an attribute of the element.
+ * If the attribute doesn't exist, <code>defaultValue</code> is returned.
+ * If the value of the attribute is equal to <code>trueValue</code>,
+ * <code>true</code> is returned.
+ * If the value of the attribute is equal to <code>falseValue</code>,
+ * <code>false</code> is returned.
+ * If the value doesn't match <code>trueValue</code> or
+ * <code>falseValue</code>, an exception is thrown.
+ *
+ * @param name The name of the attribute.
+ * @param trueValue The value associated with <code>true</code>.
+ * @param falseValue The value associated with <code>true</code>.
+ * @param defaultValue Value to use if the attribute is missing.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>name != null</code>
+ * <li><code>name</code> is a valid XML identifier
+ * <li><code>trueValue</code> and <code>falseValue</code>
+ * are different strings.
+ * </ul></dd></dl><dl>
+ *
+ * @see XMLElement#setAttribute(String, Object)
+ * setAttribute(String, Object)
+ * @see XMLElement#removeAttribute(String)
+ * removeAttribute(String)
+ * @see XMLElement#enumerateAttributeNames()
+ */
+ public boolean getBooleanAttribute(String name,
+ String trueValue,
+ String falseValue,
+ boolean defaultValue)
+ {
+ if (this.ignoreCase) {
+ name = name.toUpperCase();
+ }
+ Object value = this.attributes.get(name);
+ if (value == null) {
+ return defaultValue;
+ } else if (value.equals(trueValue)) {
+ return true;
+ } else if (value.equals(falseValue)) {
+ return false;
+ } else {
+ throw this.invalidValue(name, (String) value);
+ }
+ }
+
+
+ /**
+ * Returns an attribute by looking up a key in a hashtable.
+ *
+ * @deprecated Use {@link #getIntAttribute(String,
+ * java.util.Hashtable, String, boolean)
+ * getIntAttribute} instead.
+ */
+ public int getIntProperty(String name,
+ Hashtable valueSet,
+ String defaultKey)
+ {
+ return this.getIntAttribute(name, valueSet, defaultKey, false);
+ }
+
+
+ /**
+ * Returns an attribute.
+ *
+ * @deprecated Use {@link #getStringAttribute(String)
+ * getStringAttribute} instead.
+ */
+ public String getProperty(String name)
+ {
+ return this.getStringAttribute(name);
+ }
+
+
+ /**
+ * Returns an attribute.
+ *
+ * @deprecated Use {@link #getStringAttribute(String,
+ * String) getStringAttribute} instead.
+ */
+ public String getProperty(String name,
+ String defaultValue)
+ {
+ return this.getStringAttribute(name, defaultValue);
+ }
+
+
+ /**
+ * Returns an attribute.
+ *
+ * @deprecated Use {@link #getIntAttribute(String, int)
+ * getIntAttribute} instead.
+ */
+ public int getProperty(String name,
+ int defaultValue)
+ {
+ return this.getIntAttribute(name, defaultValue);
+ }
+
+
+ /**
+ * Returns an attribute.
+ *
+ * @deprecated Use {@link #getDoubleAttribute(String, double)
+ * getDoubleAttribute} instead.
+ */
+ public double getProperty(String name,
+ double defaultValue)
+ {
+ return this.getDoubleAttribute(name, defaultValue);
+ }
+
+
+ /**
+ * Returns an attribute.
+ *
+ * @deprecated Use {@link #getBooleanAttribute(String,
+ * String, String, boolean)
+ * getBooleanAttribute} instead.
+ */
+ public boolean getProperty(String key,
+ String trueValue,
+ String falseValue,
+ boolean defaultValue)
+ {
+ return this.getBooleanAttribute(key, trueValue, falseValue,
+ defaultValue);
+ }
+
+
+ /**
+ * Returns an attribute by looking up a key in a hashtable.
+ *
+ * @deprecated Use {@link #getAttribute(String,
+ * java.util.Hashtable, String, boolean)
+ * getAttribute} instead.
+ */
+ public Object getProperty(String name,
+ Hashtable valueSet,
+ String defaultKey)
+ {
+ return this.getAttribute(name, valueSet, defaultKey, false);
+ }
+
+
+ /**
+ * Returns an attribute by looking up a key in a hashtable.
+ *
+ * @deprecated Use {@link #getStringAttribute(String,
+ * java.util.Hashtable, String, boolean)
+ * getStringAttribute} instead.
+ */
+ public String getStringProperty(String name,
+ Hashtable valueSet,
+ String defaultKey)
+ {
+ return this.getStringAttribute(name, valueSet, defaultKey, false);
+ }
+
+
+ /**
+ * Returns an attribute by looking up a key in a hashtable.
+ *
+ * @deprecated Use {@link #getIntAttribute(String,
+ * java.util.Hashtable, String, boolean)
+ * getIntAttribute} instead.
+ */
+ public int getSpecialIntProperty(String name,
+ Hashtable valueSet,
+ String defaultKey)
+ {
+ return this.getIntAttribute(name, valueSet, defaultKey, true);
+ }
+
+
+ /**
+ * Returns an attribute by looking up a key in a hashtable.
+ *
+ * @deprecated Use {@link #getDoubleAttribute(String,
+ * java.util.Hashtable, String, boolean)
+ * getDoubleAttribute} instead.
+ */
+ public double getSpecialDoubleProperty(String name,
+ Hashtable valueSet,
+ String defaultKey)
+ {
+ return this.getDoubleAttribute(name, valueSet, defaultKey, true);
+ }
+
+
+ /**
+ * Returns the name of the element.
+ *
+ * @see XMLElement#setName(String) setName(String)
+ */
+ public String getName()
+ {
+ return this.name;
+ }
+
+
+ /**
+ * Returns the name of the element.
+ *
+ * @deprecated Use {@link #getName() getName} instead.
+ */
+ public String getTagName()
+ {
+ return this.getName();
+ }
+
+
+ /**
+ * Reads one XML element from a java.io.Reader and parses it.
+ *
+ * @param reader
+ * The reader from which to retrieve the XML data.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>reader != null</code>
+ * <li><code>reader</code> is not closed
+ * </ul></dd></dl>
+ *
+ * <dl><dt><b>Postconditions:</b></dt><dd>
+ * <ul><li>the state of the receiver is updated to reflect the XML element
+ * parsed from the reader
+ * <li>the reader points to the first character following the last
+ * '>' character of the XML element
+ * </ul></dd></dl><dl>
+ *
+ * @throws java.io.IOException
+ * If an error occured while reading the input.
+ * @throws XMLParseException
+ * If an error occured while parsing the read data.
+ */
+ public void parseFromReader(Reader reader)
+ throws IOException, XMLParseException
+ {
+ this.parseFromReader(reader, /*startingLineNr*/ 1);
+ }
+
+
+ /**
+ * Reads one XML element from a java.io.Reader and parses it.
+ *
+ * @param reader
+ * The reader from which to retrieve the XML data.
+ * @param startingLineNr
+ * The line number of the first line in the data.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>reader != null</code>
+ * <li><code>reader</code> is not closed
+ * </ul></dd></dl>
+ *
+ * <dl><dt><b>Postconditions:</b></dt><dd>
+ * <ul><li>the state of the receiver is updated to reflect the XML element
+ * parsed from the reader
+ * <li>the reader points to the first character following the last
+ * '>' character of the XML element
+ * </ul></dd></dl><dl>
+ *
+ * @throws java.io.IOException
+ * If an error occured while reading the input.
+ * @throws XMLParseException
+ * If an error occured while parsing the read data.
+ */
+ public void parseFromReader(Reader reader,
+ int startingLineNr)
+ throws IOException, XMLParseException
+ {
+ this.name = null;
+ this.contents = "";
+ this.attributes = new Hashtable();
+ this.children = new Vector();
+ this.charReadTooMuch = '\0';
+ this.reader = reader;
+ this.parserLineNr = startingLineNr;
+
+ for (;;) {
+ char ch = this.scanWhitespace();
+
+ if (ch != '<') {
+ throw this.expectedInput("<");
+ }
+
+ ch = this.readChar();
+
+ if ((ch == '!') || (ch == '?')) {
+ this.skipSpecialTag(0);
+ } else {
+ this.unreadChar(ch);
+ this.scanElement(this);
+ return;
+ }
+ }
+ }
+
+
+ /**
+ * Reads one XML element from a String and parses it.
+ *
+ * @param reader
+ * ...
[truncated message content] |