Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2455 - in development/laboratory/users/DPMLTesting: . bin src src/nanoxml src/net src/net/dpml src/net/dpml/refactorme testfiles

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: bseib AT purdue.edu
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r2455 - in development/laboratory/users/DPMLTesting: . bin src src/nanoxml src/net src/net/dpml src/net/dpml/refactorme testfiles
  • Date: Mon, 02 May 2005 21:57:49 -0400

Author: bseib AT purdue.edu
Date: Mon May 2 21:57:40 2005
New Revision: 2455

Added:
development/laboratory/users/DPMLTesting/.classpath
development/laboratory/users/DPMLTesting/.project
development/laboratory/users/DPMLTesting/bin/
development/laboratory/users/DPMLTesting/src/
development/laboratory/users/DPMLTesting/src/nanoxml/
development/laboratory/users/DPMLTesting/src/nanoxml/XMLElement.java
development/laboratory/users/DPMLTesting/src/nanoxml/XMLParseException.java
development/laboratory/users/DPMLTesting/src/net/
development/laboratory/users/DPMLTesting/src/net/dpml/
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/

development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/Dependency.java

development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/Importt.java

development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/Include.java
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/Info.java

development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/MagicIndexFile.java

development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/MagicIndexFileException.java

development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/Project.java

development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/ProjectAttribute.java

development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/Resource.java

development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/SABasedir.java

development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/SAFile.java

development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/StringAttribute.java
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/Test.java
development/laboratory/users/DPMLTesting/testfiles/
development/laboratory/users/DPMLTesting/testfiles/index1.xml
development/laboratory/users/DPMLTesting/testfiles/index2.xml
development/laboratory/users/DPMLTesting/testfiles/index3.xml
development/laboratory/users/DPMLTesting/testfiles/index4.xml
development/laboratory/users/DPMLTesting/testfiles/index5.xml
Log:
Working code to model and read magic index.xml files.

Very rough cut, but works. Need to verify with folks
what really shows up in index.xml files. Needs some
constructor consistancy. Needs javadocs. Needs to be
able to write files out. Needs package name refactored.

Added: development/laboratory/users/DPMLTesting/.classpath
==============================================================================
--- (empty file)
+++ development/laboratory/users/DPMLTesting/.classpath Mon May 2 21:57:40
2005
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>

Added: development/laboratory/users/DPMLTesting/.project
==============================================================================
--- (empty file)
+++ development/laboratory/users/DPMLTesting/.project Mon May 2 21:57:40
2005
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>DPMLTesting</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.ibm.sse.model.structuredbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>

Added: development/laboratory/users/DPMLTesting/src/nanoxml/XMLElement.java
==============================================================================
--- (empty file)
+++ development/laboratory/users/DPMLTesting/src/nanoxml/XMLElement.java
Mon May 2 21:57:40 2005
@@ -0,0 +1,2875 @@
+/* XMLElement.java
+ *
+ * $Revision: 1.1 $
+ * $Date: 2005/04/30 16:31:32 $
+ * $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 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.Enumeration;
+import java.util.Hashtable;
+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(java.lang.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>
+ * &nbsp;&nbsp;&nbsp;&nbsp;String key = (String) enum.nextElement();<BR>
+ * &nbsp;&nbsp;&nbsp;&nbsp;String value =
element.getStringAttribute(key);<BR>
+ * &nbsp;&nbsp;&nbsp;&nbsp;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>
+ * &lt;title&gt;The Title&lt;/title&gt;
+ * </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 nanoxml.XMLParseException
+ *
+ * @author Marc De Scheemaecker
+ * &lt;<A href="mailto:cyberelf AT mac.com";>cyberelf AT mac.com</A>&gt;
+ * @version $Name: $, $Revision: 1.1 $
+ */
+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 nanoxml.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 nanoxml.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 Hashtable 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 Vector 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 &amp;...; entities. The keys are the entity names
+ * without the &amp; 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"&nbsp;=&gt;&nbsp;"&lt;", "gt"&nbsp;=&gt;&nbsp;"&gt;",
+ * "quot"&nbsp;=&gt;&nbsp;"\"", "apos"&nbsp;=&gt;&nbsp;"'",
+ * "amp"&nbsp;=&gt;&nbsp;"&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 &gt= 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 &gt; 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 nanoxml.XMLElement#XMLElement(java.util.Hashtable)
+ * XMLElement(Hashtable)
+ * @see nanoxml.XMLElement#XMLElement(boolean)
+ * @see nanoxml.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 nanoxml.XMLElement#XMLElement()
+ * @see nanoxml.XMLElement#XMLElement(boolean)
+ * @see nanoxml.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 nanoxml.XMLElement#XMLElement()
+ * @see nanoxml.XMLElement#XMLElement(java.util.Hashtable)
+ * XMLElement(Hashtable)
+ * @see nanoxml.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 nanoxml.XMLElement#XMLElement()
+ * @see nanoxml.XMLElement#XMLElement(boolean)
+ * @see nanoxml.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 nanoxml.XMLElement#XMLElement()
+ * @see nanoxml.XMLElement#XMLElement(boolean)
+ * @see nanoxml.XMLElement#XMLElement(java.util.Hashtable)
+ * XMLElement(Hashtable)
+ * @see nanoxml.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 nanoxml.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 Hashtable();
+ this.children = new Vector();
+ this.entities = entities;
+ this.lineNr = 0;
+ Enumeration enum = this.entities.keys();
+ while (enum.hasMoreElements()) {
+ Object key = enum.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 nanoxml.XMLElement#countChildren()
+ * @see nanoxml.XMLElement#enumerateChildren()
+ * @see nanoxml.XMLElement#getChildren()
+ * @see nanoxml.XMLElement#removeChild(nanoxml.XMLElement)
+ * removeChild(XMLElement)
+ */
+ public void addChild(XMLElement child)
+ {
+ this.children.addElement(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 nanoxml.XMLElement#setDoubleAttribute(java.lang.String, double)
+ * setDoubleAttribute(String, double)
+ * @see nanoxml.XMLElement#setIntAttribute(java.lang.String, int)
+ * setIntAttribute(String, int)
+ * @see nanoxml.XMLElement#enumerateAttributeNames()
+ * @see nanoxml.XMLElement#getAttribute(java.lang.String)
+ * getAttribute(String)
+ * @see nanoxml.XMLElement#getAttribute(java.lang.String,
java.lang.Object)
+ * getAttribute(String, Object)
+ * @see nanoxml.XMLElement#getAttribute(java.lang.String,
+ * java.util.Hashtable,
+ * java.lang.String, boolean)
+ * getAttribute(String, Hashtable, String, boolean)
+ * @see nanoxml.XMLElement#getStringAttribute(java.lang.String)
+ * getStringAttribute(String)
+ * @see nanoxml.XMLElement#getStringAttribute(java.lang.String,
+ * java.lang.String)
+ * getStringAttribute(String, String)
+ * @see nanoxml.XMLElement#getStringAttribute(java.lang.String,
+ * java.util.Hashtable,
+ * java.lang.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(java.lang.String,
java.lang.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 nanoxml.XMLElement#setDoubleAttribute(java.lang.String, double)
+ * setDoubleAttribute(String, double)
+ * @see nanoxml.XMLElement#setAttribute(java.lang.String,
java.lang.Object)
+ * setAttribute(String, Object)
+ * @see nanoxml.XMLElement#removeAttribute(java.lang.String)
+ * removeAttribute(String)
+ * @see nanoxml.XMLElement#enumerateAttributeNames()
+ * @see nanoxml.XMLElement#getIntAttribute(java.lang.String)
+ * getIntAttribute(String)
+ * @see nanoxml.XMLElement#getIntAttribute(java.lang.String, int)
+ * getIntAttribute(String, int)
+ * @see nanoxml.XMLElement#getIntAttribute(java.lang.String,
+ * java.util.Hashtable,
+ * java.lang.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(java.lang.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 nanoxml.XMLElement#setIntAttribute(java.lang.String, int)
+ * setIntAttribute(String, int)
+ * @see nanoxml.XMLElement#setAttribute(java.lang.String,
java.lang.Object)
+ * setAttribute(String, Object)
+ * @see nanoxml.XMLElement#removeAttribute(java.lang.String)
+ * removeAttribute(String)
+ * @see nanoxml.XMLElement#enumerateAttributeNames()
+ * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String)
+ * getDoubleAttribute(String)
+ * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String, double)
+ * getDoubleAttribute(String, double)
+ * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String,
+ * java.util.Hashtable,
+ * java.lang.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(java.lang.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 nanoxml.XMLElement#addChild(nanoxml.XMLElement)
+ * addChild(XMLElement)
+ * @see nanoxml.XMLElement#enumerateChildren()
+ * @see nanoxml.XMLElement#getChildren()
+ * @see nanoxml.XMLElement#removeChild(nanoxml.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 nanoxml.XMLElement#setDoubleAttribute(java.lang.String, double)
+ * setDoubleAttribute(String, double)
+ * @see nanoxml.XMLElement#setIntAttribute(java.lang.String, int)
+ * setIntAttribute(String, int)
+ * @see nanoxml.XMLElement#setAttribute(java.lang.String,
java.lang.Object)
+ * setAttribute(String, Object)
+ * @see nanoxml.XMLElement#removeAttribute(java.lang.String)
+ * removeAttribute(String)
+ * @see nanoxml.XMLElement#getAttribute(java.lang.String)
+ * getAttribute(String)
+ * @see nanoxml.XMLElement#getAttribute(java.lang.String,
java.lang.Object)
+ * getAttribute(String, String)
+ * @see nanoxml.XMLElement#getAttribute(java.lang.String,
+ * java.util.Hashtable,
+ * java.lang.String, boolean)
+ * getAttribute(String, Hashtable, String, boolean)
+ * @see nanoxml.XMLElement#getStringAttribute(java.lang.String)
+ * getStringAttribute(String)
+ * @see nanoxml.XMLElement#getStringAttribute(java.lang.String,
+ * java.lang.String)
+ * getStringAttribute(String, String)
+ * @see nanoxml.XMLElement#getStringAttribute(java.lang.String,
+ * java.util.Hashtable,
+ * java.lang.String, boolean)
+ * getStringAttribute(String, Hashtable, String, boolean)
+ * @see nanoxml.XMLElement#getIntAttribute(java.lang.String)
+ * getIntAttribute(String)
+ * @see nanoxml.XMLElement#getIntAttribute(java.lang.String, int)
+ * getIntAttribute(String, int)
+ * @see nanoxml.XMLElement#getIntAttribute(java.lang.String,
+ * java.util.Hashtable,
+ * java.lang.String, boolean)
+ * getIntAttribute(String, Hashtable, String, boolean)
+ * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String)
+ * getDoubleAttribute(String)
+ * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String, double)
+ * getDoubleAttribute(String, double)
+ * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String,
+ * java.util.Hashtable,
+ * java.lang.String, boolean)
+ * getDoubleAttribute(String, Hashtable, String, boolean)
+ * @see nanoxml.XMLElement#getBooleanAttribute(java.lang.String,
+ * java.lang.String,
+ * java.lang.String, boolean)
+ * getBooleanAttribute(String, String, String, boolean)
+ */
+ public Enumeration enumerateAttributeNames()
+ {
+ return this.attributes.keys();
+ }
+
+
+ /**
+ * Enumerates the attribute names.
+ *
+ * @deprecated Use {@link #enumerateAttributeNames()
+ * enumerateAttributeNames} instead.
+ */
+ public Enumeration enumeratePropertyNames()
+ {
+ return this.enumerateAttributeNames();
+ }
+
+
+ /**
+ * Enumerates the child elements.
+ *
+ * <dl><dt><b>Postconditions:</b></dt><dd>
+ * <ul><li><code>result != null</code>
+ * </ul></dd></dl>
+ *
+ * @see nanoxml.XMLElement#addChild(nanoxml.XMLElement)
+ * addChild(XMLElement)
+ * @see nanoxml.XMLElement#countChildren()
+ * @see nanoxml.XMLElement#getChildren()
+ * @see nanoxml.XMLElement#removeChild(nanoxml.XMLElement)
+ * removeChild(XMLElement)
+ */
+ public Enumeration enumerateChildren()
+ {
+ return this.children.elements();
+ }
+
+
+ /**
+ * 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 nanoxml.XMLElement#addChild(nanoxml.XMLElement)
+ * addChild(XMLElement)
+ * @see nanoxml.XMLElement#countChildren()
+ * @see nanoxml.XMLElement#enumerateChildren()
+ * @see nanoxml.XMLElement#removeChild(nanoxml.XMLElement)
+ * removeChild(XMLElement)
+ */
+ public Vector getChildren()
+ {
+ try {
+ return (Vector) this.children.clone();
+ } catch (Exception e) {
+ // this never happens, however, some Java compilers are so
+ // braindead that they require this exception clause
+ return null;
+ }
+ }
+
+
+ /**
+ * 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 nanoxml.XMLElement#setContent(java.lang.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 nanoxml.XMLElement#setAttribute(java.lang.String,
java.lang.Object)
+ * setAttribute(String, Object)
+ * @see nanoxml.XMLElement#removeAttribute(java.lang.String)
+ * removeAttribute(String)
+ * @see nanoxml.XMLElement#enumerateAttributeNames()
+ * @see nanoxml.XMLElement#getAttribute(java.lang.String,
java.lang.Object)
+ * getAttribute(String, Object)
+ * @see nanoxml.XMLElement#getAttribute(java.lang.String,
+ * java.util.Hashtable,
+ * java.lang.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 nanoxml.XMLElement#setAttribute(java.lang.String,
java.lang.Object)
+ * setAttribute(String, Object)
+ * @see nanoxml.XMLElement#removeAttribute(java.lang.String)
+ * removeAttribute(String)
+ * @see nanoxml.XMLElement#enumerateAttributeNames()
+ * @see nanoxml.XMLElement#getAttribute(java.lang.String)
+ * getAttribute(String)
+ * @see nanoxml.XMLElement#getAttribute(java.lang.String,
+ * java.util.Hashtable,
+ * java.lang.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 nanoxml.XMLElement#setAttribute(java.lang.String,
java.lang.Object)
+ * setAttribute(String, Object)
+ * @see nanoxml.XMLElement#removeAttribute(java.lang.String)
+ * removeAttribute(String)
+ * @see nanoxml.XMLElement#enumerateAttributeNames()
+ * @see nanoxml.XMLElement#getAttribute(java.lang.String)
+ * getAttribute(String)
+ * @see nanoxml.XMLElement#getAttribute(java.lang.String,
java.lang.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 nanoxml.XMLElement#setAttribute(java.lang.String,
java.lang.Object)
+ * setAttribute(String, Object)
+ * @see nanoxml.XMLElement#removeAttribute(java.lang.String)
+ * removeAttribute(String)
+ * @see nanoxml.XMLElement#enumerateAttributeNames()
+ * @see nanoxml.XMLElement#getStringAttribute(java.lang.String,
+ * java.lang.String)
+ * getStringAttribute(String, String)
+ * @see nanoxml.XMLElement#getStringAttribute(java.lang.String,
+ * java.util.Hashtable,
+ * java.lang.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 nanoxml.XMLElement#setAttribute(java.lang.String,
java.lang.Object)
+ * setAttribute(String, Object)
+ * @see nanoxml.XMLElement#removeAttribute(java.lang.String)
+ * removeAttribute(String)
+ * @see nanoxml.XMLElement#enumerateAttributeNames()
+ * @see nanoxml.XMLElement#getStringAttribute(java.lang.String)
+ * getStringAttribute(String)
+ * @see nanoxml.XMLElement#getStringAttribute(java.lang.String,
+ * java.util.Hashtable,
+ * java.lang.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 nanoxml.XMLElement#setAttribute(java.lang.String,
java.lang.Object)
+ * setAttribute(String, Object)
+ * @see nanoxml.XMLElement#removeAttribute(java.lang.String)
+ * removeAttribute(String)
+ * @see nanoxml.XMLElement#enumerateAttributeNames()
+ * @see nanoxml.XMLElement#getStringAttribute(java.lang.String)
+ * getStringAttribute(String)
+ * @see nanoxml.XMLElement#getStringAttribute(java.lang.String,
+ * java.lang.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 nanoxml.XMLElement#setIntAttribute(java.lang.String, int)
+ * setIntAttribute(String, int)
+ * @see nanoxml.XMLElement#enumerateAttributeNames()
+ * @see nanoxml.XMLElement#getIntAttribute(java.lang.String, int)
+ * getIntAttribute(String, int)
+ * @see nanoxml.XMLElement#getIntAttribute(java.lang.String,
+ * java.util.Hashtable,
+ * java.lang.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 nanoxml.XMLElement#setIntAttribute(java.lang.String, int)
+ * setIntAttribute(String, int)
+ * @see nanoxml.XMLElement#enumerateAttributeNames()
+ * @see nanoxml.XMLElement#getIntAttribute(java.lang.String)
+ * getIntAttribute(String)
+ * @see nanoxml.XMLElement#getIntAttribute(java.lang.String,
+ * java.util.Hashtable,
+ * java.lang.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 nanoxml.XMLElement#setIntAttribute(java.lang.String, int)
+ * setIntAttribute(String, int)
+ * @see nanoxml.XMLElement#enumerateAttributeNames()
+ * @see nanoxml.XMLElement#getIntAttribute(java.lang.String)
+ * getIntAttribute(String)
+ * @see nanoxml.XMLElement#getIntAttribute(java.lang.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 nanoxml.XMLElement#setDoubleAttribute(java.lang.String, double)
+ * setDoubleAttribute(String, double)
+ * @see nanoxml.XMLElement#enumerateAttributeNames()
+ * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String, double)
+ * getDoubleAttribute(String, double)
+ * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String,
+ * java.util.Hashtable,
+ * java.lang.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 nanoxml.XMLElement#setDoubleAttribute(java.lang.String, double)
+ * setDoubleAttribute(String, double)
+ * @see nanoxml.XMLElement#enumerateAttributeNames()
+ * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String)
+ * getDoubleAttribute(String)
+ * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String,
+ * java.util.Hashtable,
+ * java.lang.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" =&gt;
+ * 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 nanoxml.XMLElement#setDoubleAttribute(java.lang.String, double)
+ * setDoubleAttribute(String, double)
+ * @see nanoxml.XMLElement#enumerateAttributeNames()
+ * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String)
+ * getDoubleAttribute(String)
+ * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.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 nanoxml.XMLElement#setAttribute(java.lang.String,
java.lang.Object)
+ * setAttribute(String, Object)
+ * @see nanoxml.XMLElement#removeAttribute(java.lang.String)
+ * removeAttribute(String)
+ * @see nanoxml.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(java.lang.String,
+ * java.util.Hashtable, java.lang.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(java.lang.String)
+ * getStringAttribute} instead.
+ */
+ public String getProperty(String name)
+ {
+ return this.getStringAttribute(name);
+ }
+
+
+ /**
+ * Returns an attribute.
+ *
+ * @deprecated Use {@link #getStringAttribute(java.lang.String,
+ * java.lang.String) getStringAttribute} instead.
+ */
+ public String getProperty(String name,
+ String defaultValue)
+ {
+ return this.getStringAttribute(name, defaultValue);
+ }
+
+
+ /**
+ * Returns an attribute.
+ *
+ * @deprecated Use {@link #getIntAttribute(java.lang.String, int)
+ * getIntAttribute} instead.
+ */
+ public int getProperty(String name,
+ int defaultValue)
+ {
+ return this.getIntAttribute(name, defaultValue);
+ }
+
+
+ /**
+ * Returns an attribute.
+ *
+ * @deprecated Use {@link #getDoubleAttribute(java.lang.String, double)
+ * getDoubleAttribute} instead.
+ */
+ public double getProperty(String name,
+ double defaultValue)
+ {
+ return this.getDoubleAttribute(name, defaultValue);
+ }
+
+
+ /**
+ * Returns an attribute.
+ *
+ * @deprecated Use {@link #getBooleanAttribute(java.lang.String,
+ * java.lang.String, java.lang.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(java.lang.String,
+ * java.util.Hashtable, java.lang.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(java.lang.String,
+ * java.util.Hashtable, java.lang.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(java.lang.String,
+ * java.util.Hashtable, java.lang.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(java.lang.String,
+ * java.util.Hashtable, java.lang.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 nanoxml.XMLElement#setName(java.lang.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
+ * '&gt;' character of the XML element
+ * </ul></dd></dl><dl>
+ *
+ * @throws java.io.IOException
+ * If an error occured while reading the input.
+ * @throws nanoxml.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
+ * '&gt;' character of the XML element
+ * </ul></dd></dl><dl>
+ *
+ * @throws java.io.IOException
+ * If an error occured while reading the input.
+ * @throws nanoxml.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
+ * The reader from which to retrieve the XML data.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>string != null</code>
+ * <li><code>string.length() &gt; 0</code>
+ * </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
+ * </ul></dd></dl><dl>
+ *
+ * @throws nanoxml.XMLParseException
+ * If an error occured while parsing the string.
+ */
+ public void parseString(String string)
+ throws XMLParseException
+ {
+ try {
+ this.parseFromReader(new StringReader(string),
+ /*startingLineNr*/ 1);
+ } catch (IOException e) {
+ // Java exception handling suxx
+ }
+ }
+
+
+ /**
+ * Reads one XML element from a String and parses it.
+ *
+ * @param reader
+ * The reader from which to retrieve the XML data.
+ * @param offset
+ * The first character in <code>string</code> to scan.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>string != null</code>
+ * <li><code>offset &lt; string.length()</code>
+ * <li><code>offset &gt;= 0</code>
+ * </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
+ * </ul></dd></dl><dl>
+ *
+ * @throws nanoxml.XMLParseException
+ * If an error occured while parsing the string.
+ */
+ public void parseString(String string,
+ int offset)
+ throws XMLParseException
+ {
+ this.parseString(string.substring(offset));
+ }
+
+
+ /**
+ * Reads one XML element from a String and parses it.
+ *
+ * @param reader
+ * The reader from which to retrieve the XML data.
+ * @param offset
+ * The first character in <code>string</code> to scan.
+ * @param end
+ * The character where to stop scanning.
+ * This character is not scanned.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>string != null</code>
+ * <li><code>end &lt;= string.length()</code>
+ * <li><code>offset &lt; end</code>
+ * <li><code>offset &gt;= 0</code>
+ * </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
+ * </ul></dd></dl><dl>
+ *
+ * @throws nanoxml.XMLParseException
+ * If an error occured while parsing the string.
+ */
+ public void parseString(String string,
+ int offset,
+ int end)
+ throws XMLParseException
+ {
+ this.parseString(string.substring(offset, end));
+ }
+
+
+ /**
+ * Reads one XML element from a String and parses it.
+ *
+ * @param reader
+ * The reader from which to retrieve the XML data.
+ * @param offset
+ * The first character in <code>string</code> to scan.
+ * @param end
+ * The character where to stop scanning.
+ * This character is not scanned.
+ * @param startingLineNr
+ * The line number of the first line in the data.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>string != null</code>
+ * <li><code>end &lt;= string.length()</code>
+ * <li><code>offset &lt; end</code>
+ * <li><code>offset &gt;= 0</code>
+ * </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
+ * </ul></dd></dl><dl>
+ *
+ * @throws nanoxml.XMLParseException
+ * If an error occured while parsing the string.
+ */
+ public void parseString(String string,
+ int offset,
+ int end,
+ int startingLineNr)
+ throws XMLParseException
+ {
+ string = string.substring(offset, end);
+ try {
+ this.parseFromReader(new StringReader(string), startingLineNr);
+ } catch (IOException e) {
+ // Java exception handling suxx
+ }
+ }
+
+
+ /**
+ * Reads one XML element from a char array and parses it.
+ *
+ * @param reader
+ * The reader from which to retrieve the XML data.
+ * @param offset
+ * The first character in <code>string</code> to scan.
+ * @param end
+ * The character where to stop scanning.
+ * This character is not scanned.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>input != null</code>
+ * <li><code>end &lt;= input.length</code>
+ * <li><code>offset &lt; end</code>
+ * <li><code>offset &gt;= 0</code>
+ * </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
+ * </ul></dd></dl><dl>
+ *
+ * @throws nanoxml.XMLParseException
+ * If an error occured while parsing the string.
+ */
+ public void parseCharArray(char[] input,
+ int offset,
+ int end)
+ throws XMLParseException
+ {
+ this.parseCharArray(input, offset, end, /*startingLineNr*/ 1);
+ }
+
+
+ /**
+ * Reads one XML element from a char array and parses it.
+ *
+ * @param reader
+ * The reader from which to retrieve the XML data.
+ * @param offset
+ * The first character in <code>string</code> to scan.
+ * @param end
+ * The character where to stop scanning.
+ * This character is not scanned.
+ * @param startingLineNr
+ * The line number of the first line in the data.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>input != null</code>
+ * <li><code>end &lt;= input.length</code>
+ * <li><code>offset &lt; end</code>
+ * <li><code>offset &gt;= 0</code>
+ * </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
+ * </ul></dd></dl><dl>
+ *
+ * @throws nanoxml.XMLParseException
+ * If an error occured while parsing the string.
+ */
+ public void parseCharArray(char[] input,
+ int offset,
+ int end,
+ int startingLineNr)
+ throws XMLParseException
+ {
+ try {
+ Reader reader = new CharArrayReader(input, offset, end);
+ this.parseFromReader(reader, startingLineNr);
+ } catch (IOException e) {
+ // This exception will never happen.
+ }
+ }
+
+
+ /**
+ * Removes a child element.
+ *
+ * @param child
+ * The child element to remove.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>child != null</code>
+ * <li><code>child</code> is a child element of the receiver
+ * </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 nanoxml.XMLElement#addChild(nanoxml.XMLElement)
+ * addChild(XMLElement)
+ * @see nanoxml.XMLElement#countChildren()
+ * @see nanoxml.XMLElement#enumerateChildren()
+ * @see nanoxml.XMLElement#getChildren()
+ */
+ public void removeChild(XMLElement child)
+ {
+ this.children.removeElement(child);
+ }
+
+
+ /**
+ * Removes an attribute.
+ *
+ * @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><dt><b>Postconditions:</b></dt><dd>
+ * <ul><li>enumerateAttributeNames()
+ * => old.enumerateAttributeNames() - name
+ * <li>getAttribute(name) => <code>null</code>
+ * </ul></dd></dl><dl>
+ *
+ * @see nanoxml.XMLElement#enumerateAttributeNames()
+ * @see nanoxml.XMLElement#setDoubleAttribute(java.lang.String, double)
+ * setDoubleAttribute(String, double)
+ * @see nanoxml.XMLElement#setIntAttribute(java.lang.String, int)
+ * setIntAttribute(String, int)
+ * @see nanoxml.XMLElement#setAttribute(java.lang.String,
java.lang.Object)
+ * setAttribute(String, Object)
+ * @see nanoxml.XMLElement#getAttribute(java.lang.String)
+ * getAttribute(String)
+ * @see nanoxml.XMLElement#getAttribute(java.lang.String,
java.lang.Object)
+ * getAttribute(String, Object)
+ * @see nanoxml.XMLElement#getAttribute(java.lang.String,
+ * java.util.Hashtable,
+ * java.lang.String, boolean)
+ * getAttribute(String, Hashtable, String, boolean)
+ * @see nanoxml.XMLElement#getStringAttribute(java.lang.String)
+ * getStringAttribute(String)
+ * @see nanoxml.XMLElement#getStringAttribute(java.lang.String,
+ * java.lang.String)
+ * getStringAttribute(String, String)
+ * @see nanoxml.XMLElement#getStringAttribute(java.lang.String,
+ * java.util.Hashtable,
+ * java.lang.String, boolean)
+ * getStringAttribute(String, Hashtable, String, boolean)
+ * @see nanoxml.XMLElement#getIntAttribute(java.lang.String)
+ * getIntAttribute(String)
+ * @see nanoxml.XMLElement#getIntAttribute(java.lang.String, int)
+ * getIntAttribute(String, int)
+ * @see nanoxml.XMLElement#getIntAttribute(java.lang.String,
+ * java.util.Hashtable,
+ * java.lang.String, boolean)
+ * getIntAttribute(String, Hashtable, String, boolean)
+ * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String)
+ * getDoubleAttribute(String)
+ * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String, double)
+ * getDoubleAttribute(String, double)
+ * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String,
+ * java.util.Hashtable,
+ * java.lang.String, boolean)
+ * getDoubleAttribute(String, Hashtable, String, boolean)
+ * @see nanoxml.XMLElement#getBooleanAttribute(java.lang.String,
+ * java.lang.String,
+ * java.lang.String, boolean)
+ * getBooleanAttribute(String, String, String, boolean)
+ */
+ public void removeAttribute(String name)
+ {
+ if (this.ignoreCase) {
+ name = name.toUpperCase();
+ }
+ this.attributes.remove(name);
+ }
+
+
+ /**
+ * Removes an attribute.
+ *
+ * @param name
+ * The name of the attribute.
+ *
+ * @deprecated Use {@link #removeAttribute(java.lang.String)
+ * removeAttribute} instead.
+ */
+ public void removeProperty(String name)
+ {
+ this.removeAttribute(name);
+ }
+
+
+ /**
+ * Removes an attribute.
+ *
+ * @param name
+ * The name of the attribute.
+ *
+ * @deprecated Use {@link #removeAttribute(java.lang.String)
+ * removeAttribute} instead.
+ */
+ public void removeChild(String name)
+ {
+ this.removeAttribute(name);
+ }
+
+
+ /**
+ * Creates a new similar XML element.
+ * <P>
+ * You should override this method when subclassing XMLElement.
+ */
+ protected XMLElement createAnotherElement()
+ {
+ return new XMLElement(this.entities,
+ this.ignoreWhitespace,
+ false,
+ this.ignoreCase);
+ }
+
+
+ /**
+ * Changes the content string.
+ *
+ * @param content
+ * The new content string.
+ */
+ public void setContent(String content)
+ {
+ this.contents = content;
+ }
+
+
+ /**
+ * Changes the name of the element.
+ *
+ * @param name
+ * The new name.
+ *
+ * @deprecated Use {@link #setName(java.lang.String) setName} instead.
+ */
+ public void setTagName(String name)
+ {
+ this.setName(name);
+ }
+
+
+ /**
+ * Changes the name of the element.
+ *
+ * @param name
+ * The new name.
+ *
+ * </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>
+ *
+ * @see nanoxml.XMLElement#getName()
+ */
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+
+ /**
+ * Writes the XML element to a string.
+ *
+ * @see nanoxml.XMLElement#write(java.io.Writer) write(Writer)
+ */
+ public String toString()
+ {
+ try {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ OutputStreamWriter writer = new OutputStreamWriter(out);
+ this.write(writer);
+ writer.flush();
+ return new String(out.toByteArray());
+ } catch (IOException e) {
+ // Java exception handling suxx
+ return super.toString();
+ }
+ }
+
+
+ /**
+ * Writes the XML element to a writer.
+ *
+ * @param writer
+ * The writer to write the XML data to.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>writer != null</code>
+ * <li><code>writer</code> is not closed
+ * </ul></dd></dl>
+ *
+ * @throws java.io.IOException
+ * If the data could not be written to the writer.
+ *
+ * @see nanoxml.XMLElement#toString()
+ */
+ public void write(Writer writer)
+ throws IOException
+ {
+ if (this.name == null) {
+ this.writeEncoded(writer, this.contents);
+ return;
+ }
+ writer.write('<');
+ writer.write(this.name);
+ if (! this.attributes.isEmpty()) {
+ Enumeration enum = this.attributes.keys();
+ while (enum.hasMoreElements()) {
+ writer.write(' ');
+ String key = (String) enum.nextElement();
+ String value = (String) this.attributes.get(key);
+ writer.write(key);
+ writer.write('='); writer.write('"');
+ this.writeEncoded(writer, value);
+ writer.write('"');
+ }
+ }
+ if ((this.contents != null) && (this.contents.length() > 0)) {
+ writer.write('>');
+ this.writeEncoded(writer, this.contents);
+ writer.write('<'); writer.write('/');
+ writer.write(this.name);
+ writer.write('>');
+ } else if (this.children.isEmpty()) {
+ writer.write('/'); writer.write('>');
+ } else {
+ writer.write('>');
+ Enumeration enum = this.enumerateChildren();
+ while (enum.hasMoreElements()) {
+ XMLElement child = (XMLElement) enum.nextElement();
+ child.write(writer);
+ }
+ writer.write('<'); writer.write('/');
+ writer.write(this.name);
+ writer.write('>');
+ }
+ }
+
+
+ /**
+ * Writes a string encoded to a writer.
+ *
+ * @param writer
+ * The writer to write the XML data to.
+ * @param str
+ * The string to write encoded.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>writer != null</code>
+ * <li><code>writer</code> is not closed
+ * <li><code>str != null</code>
+ * </ul></dd></dl>
+ */
+ protected void writeEncoded(Writer writer,
+ String str)
+ throws IOException
+ {
+ for (int i = 0; i < str.length(); i += 1) {
+ char ch = str.charAt(i);
+ switch (ch) {
+ case '<':
+ writer.write('&'); writer.write('l'); writer.write('t');
+ writer.write(';');
+ break;
+ case '>':
+ writer.write('&'); writer.write('g'); writer.write('t');
+ writer.write(';');
+ break;
+ case '&':
+ writer.write('&'); writer.write('a'); writer.write('m');
+ writer.write('p'); writer.write(';');
+ break;
+ case '"':
+ writer.write('&'); writer.write('q'); writer.write('u');
+ writer.write('o'); writer.write('t'); writer.write(';');
+ break;
+ case '\'':
+ writer.write('&'); writer.write('a'); writer.write('p');
+ writer.write('o'); writer.write('s'); writer.write(';');
+ break;
+ default:
+ int unicode = (int) ch;
+ if ((unicode < 32) || (unicode > 126)) {
+ writer.write('&'); writer.write('#');
+ writer.write('x');
+ writer.write(Integer.toString(unicode, 16));
+ writer.write(';');
+ } else {
+ writer.write(ch);
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Scans an identifier from the current reader.
+ * The scanned identifier is appended to <code>result</code>.
+ *
+ * @param result
+ * The buffer in which the scanned identifier will be put.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>result != null</code>
+ * <li>The next character read from the reader is a valid first
+ * character of an XML identifier.
+ * </ul></dd></dl>
+ *
+ * <dl><dt><b>Postconditions:</b></dt><dd>
+ * <ul><li>The next character read from the reader won't be an identifier
+ * character.
+ * </ul></dd></dl><dl>
+ */
+ protected void scanIdentifier(StringBuffer result)
+ throws IOException
+ {
+ for (;;) {
+ char ch = this.readChar();
+ if (((ch < 'A') || (ch > 'Z')) && ((ch < 'a') || (ch > 'z'))
+ && ((ch < '0') || (ch > '9')) && (ch != '_') && (ch != '.')
+ && (ch != ':') && (ch != '-') && (ch <= '\u007E')) {
+ this.unreadChar(ch);
+ return;
+ }
+ result.append(ch);
+ }
+ }
+
+
+ /**
+ * This method scans an identifier from the current reader.
+ *
+ * @return the next character following the whitespace.
+ */
+ protected char scanWhitespace()
+ throws IOException
+ {
+ for (;;) {
+ char ch = this.readChar();
+ switch (ch) {
+ case ' ':
+ case '\t':
+ case '\n':
+ case '\r':
+ break;
+ default:
+ return ch;
+ }
+ }
+ }
+
+
+ /**
+ * This method scans an identifier from the current reader.
+ * The scanned whitespace is appended to <code>result</code>.
+ *
+ * @return the next character following the whitespace.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>result != null</code>
+ * </ul></dd></dl>
+ */
+ protected char scanWhitespace(StringBuffer result)
+ throws IOException
+ {
+ for (;;) {
+ char ch = this.readChar();
+ switch (ch) {
+ case ' ':
+ case '\t':
+ case '\n':
+ result.append(ch);
+ case '\r':
+ break;
+ default:
+ return ch;
+ }
+ }
+ }
+
+
+ /**
+ * This method scans a delimited string from the current reader.
+ * The scanned string without delimiters is appended to
+ * <code>string</code>.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>string != null</code>
+ * <li>the next char read is the string delimiter
+ * </ul></dd></dl>
+ */
+ protected void scanString(StringBuffer string)
+ throws IOException
+ {
+ char delimiter = this.readChar();
+ if ((delimiter != '\'') && (delimiter != '"')) {
+ throw this.expectedInput("' or \"");
+ }
+ for (;;) {
+ char ch = this.readChar();
+ if (ch == delimiter) {
+ return;
+ } else if (ch == '&') {
+ this.resolveEntity(string);
+ } else {
+ string.append(ch);
+ }
+ }
+ }
+
+
+ /**
+ * Scans a #PCDATA element. CDATA sections and entities are resolved.
+ * The next &lt; char is skipped.
+ * The scanned data is appended to <code>data</code>.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>data != null</code>
+ * </ul></dd></dl>
+ */
+ protected void scanPCData(StringBuffer data)
+ throws IOException
+ {
+ for (;;) {
+ char ch = this.readChar();
+ if (ch == '<') {
+ ch = this.readChar();
+ if (ch == '!') {
+ this.checkCDATA(data);
+ } else {
+ this.unreadChar(ch);
+ return;
+ }
+ } else if (ch == '&') {
+ this.resolveEntity(data);
+ } else {
+ data.append(ch);
+ }
+ }
+ }
+
+
+ /**
+ * Scans a special tag and if the tag is a CDATA section, append its
+ * content to <code>buf</code>.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>buf != null</code>
+ * <li>The first &lt; has already been read.
+ * </ul></dd></dl>
+ */
+ protected boolean checkCDATA(StringBuffer buf)
+ throws IOException
+ {
+ char ch = this.readChar();
+ if (ch != '[') {
+ this.unreadChar(ch);
+ this.skipSpecialTag(0);
+ return false;
+ } else if (! this.checkLiteral("CDATA[")) {
+ this.skipSpecialTag(1); // one [ has already been read
+ return false;
+ } else {
+ int delimiterCharsSkipped = 0;
+ while (delimiterCharsSkipped < 3) {
+ ch = this.readChar();
+ switch (ch) {
+ case ']':
+ if (delimiterCharsSkipped < 2) {
+ delimiterCharsSkipped += 1;
+ } else {
+ buf.append(']');
+ buf.append(']');
+ delimiterCharsSkipped = 0;
+ }
+ break;
+ case '>':
+ if (delimiterCharsSkipped < 2) {
+ for (int i = 0; i < delimiterCharsSkipped; i++) {
+ buf.append(']');
+ }
+ delimiterCharsSkipped = 0;
+ buf.append('>');
+ } else {
+ delimiterCharsSkipped = 3;
+ }
+ break;
+ default:
+ for (int i = 0; i < delimiterCharsSkipped; i += 1) {
+ buf.append(']');
+ }
+ buf.append(ch);
+ delimiterCharsSkipped = 0;
+ }
+ }
+ return true;
+ }
+ }
+
+
+ /**
+ * Skips a comment.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li>The first &lt;!-- has already been read.
+ * </ul></dd></dl>
+ */
+ protected void skipComment()
+ throws IOException
+ {
+ int dashesToRead = 2;
+ while (dashesToRead > 0) {
+ char ch = this.readChar();
+ if (ch == '-') {
+ dashesToRead -= 1;
+ } else {
+ dashesToRead = 2;
+ }
+ }
+ if (this.readChar() != '>') {
+ throw this.expectedInput(">");
+ }
+ }
+
+
+ /**
+ * Skips a special tag or comment.
+ *
+ * @param bracketLevel The number of open square brackets ([) that have
+ * already been read.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li>The first &lt;! has already been read.
+ * <li><code>bracketLevel >= 0</code>
+ * </ul></dd></dl>
+ */
+ protected void skipSpecialTag(int bracketLevel)
+ throws IOException
+ {
+ int tagLevel = 1; // <
+ char stringDelimiter = '\0';
+ if (bracketLevel == 0) {
+ char ch = this.readChar();
+ if (ch == '[') {
+ bracketLevel += 1;
+ } else if (ch == '-') {
+ ch = this.readChar();
+ if (ch == '[') {
+ bracketLevel += 1;
+ } else if (ch == ']') {
+ bracketLevel -= 1;
+ } else if (ch == '-') {
+ this.skipComment();
+ return;
+ }
+ }
+ }
+ while (tagLevel > 0) {
+ char ch = this.readChar();
+ if (stringDelimiter == '\0') {
+ if ((ch == '"') || (ch == '\'')) {
+ stringDelimiter = ch;
+ } else if (bracketLevel <= 0) {
+ if (ch == '<') {
+ tagLevel += 1;
+ } else if (ch == '>') {
+ tagLevel -= 1;
+ }
+ }
+ if (ch == '[') {
+ bracketLevel += 1;
+ } else if (ch == ']') {
+ bracketLevel -= 1;
+ }
+ } else {
+ if (ch == stringDelimiter) {
+ stringDelimiter = '\0';
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Scans the data for literal text.
+ * Scanning stops when a character does not match or after the complete
+ * text has been checked, whichever comes first.
+ *
+ * @param literal the literal to check.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>literal != null</code>
+ * </ul></dd></dl>
+ */
+ protected boolean checkLiteral(String literal)
+ throws IOException
+ {
+ int length = literal.length();
+ for (int i = 0; i < length; i += 1) {
+ if (this.readChar() != literal.charAt(i)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+
+ /**
+ * Reads a character from a reader.
+ */
+ protected char readChar()
+ throws IOException
+ {
+ if (this.charReadTooMuch != '\0') {
+ char ch = this.charReadTooMuch;
+ this.charReadTooMuch = '\0';
+ return ch;
+ } else {
+ int i = this.reader.read();
+ if (i < 0) {
+ throw this.unexpectedEndOfData();
+ } else if (i == 10) {
+ this.parserLineNr += 1;
+ return '\n';
+ } else {
+ return (char) i;
+ }
+ }
+ }
+
+
+ /**
+ * Scans an XML element.
+ *
+ * @param elt The element that will contain the result.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li>The first &lt; has already been read.
+ * <li><code>elt != null</code>
+ * </ul></dd></dl>
+ */
+ protected void scanElement(XMLElement elt)
+ throws IOException
+ {
+ StringBuffer buf = new StringBuffer();
+ this.scanIdentifier(buf);
+ String name = buf.toString();
+ elt.setName(name);
+ char ch = this.scanWhitespace();
+ while ((ch != '>') && (ch != '/')) {
+ buf.setLength(0);
+ this.unreadChar(ch);
+ this.scanIdentifier(buf);
+ String key = buf.toString();
+ ch = this.scanWhitespace();
+ if (ch != '=') {
+ throw this.expectedInput("=");
+ }
+ this.unreadChar(this.scanWhitespace());
+ buf.setLength(0);
+ this.scanString(buf);
+ elt.setAttribute(key, buf);
+ ch = this.scanWhitespace();
+ }
+ if (ch == '/') {
+ ch = this.readChar();
+ if (ch != '>') {
+ throw this.expectedInput(">");
+ }
+ return;
+ }
+ buf.setLength(0);
+ ch = this.scanWhitespace(buf);
+ if (ch != '<') {
+ this.unreadChar(ch);
+ this.scanPCData(buf);
+ } else {
+ for (;;) {
+ ch = this.readChar();
+ if (ch == '!') {
+ if (this.checkCDATA(buf)) {
+ this.scanPCData(buf);
+ break;
+ } else {
+ ch = this.scanWhitespace(buf);
+ if (ch != '<') {
+ this.unreadChar(ch);
+ this.scanPCData(buf);
+ break;
+ }
+ }
+ } else {
+ if ((ch != '/') || this.ignoreWhitespace) {
+ buf.setLength(0);
+ }
+ if (ch == '/') {
+ this.unreadChar(ch);
+ }
+ break;
+ }
+ }
+ }
+ if (buf.length() == 0) {
+ while (ch != '/') {
+ if (ch == '!') {
+ ch = this.readChar();
+ if (ch != '-') {
+ throw this.expectedInput("Comment or Element");
+ }
+ ch = this.readChar();
+ if (ch != '-') {
+ throw this.expectedInput("Comment or Element");
+ }
+ this.skipComment();
+ } else {
+ this.unreadChar(ch);
+ XMLElement child = this.createAnotherElement();
+ this.scanElement(child);
+ elt.addChild(child);
+ }
+ ch = this.scanWhitespace();
+ if (ch != '<') {
+ throw this.expectedInput("<");
+ }
+ ch = this.readChar();
+ }
+ this.unreadChar(ch);
+ } else {
+ if (this.ignoreWhitespace) {
+ elt.setContent(buf.toString().trim());
+ } else {
+ elt.setContent(buf.toString());
+ }
+ }
+ ch = this.readChar();
+ if (ch != '/') {
+ throw this.expectedInput("/");
+ }
+ this.unreadChar(this.scanWhitespace());
+ if (! this.checkLiteral(name)) {
+ throw this.expectedInput(name);
+ }
+ if (this.scanWhitespace() != '>') {
+ throw this.expectedInput(">");
+ }
+ }
+
+
+ /**
+ * Resolves an entity. The name of the entity is read from the reader.
+ * The value of the entity is appended to <code>buf</code>.
+ *
+ * @param buf Where to put the entity value.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li>The first &amp; has already been read.
+ * <li><code>buf != null</code>
+ * </ul></dd></dl>
+ */
+ protected void resolveEntity(StringBuffer buf)
+ throws IOException
+ {
+ char ch = '\0';
+ StringBuffer keyBuf = new StringBuffer();
+ for (;;) {
+ ch = this.readChar();
+ if (ch == ';') {
+ break;
+ }
+ keyBuf.append(ch);
+ }
+ String key = keyBuf.toString();
+ if (key.charAt(0) == '#') {
+ try {
+ if (key.charAt(1) == 'x') {
+ ch = (char) Integer.parseInt(key.substring(2), 16);
+ } else {
+ ch = (char) Integer.parseInt(key.substring(1), 10);
+ }
+ } catch (NumberFormatException e) {
+ throw this.unknownEntity(key);
+ }
+ buf.append(ch);
+ } else {
+ char[] value = (char[]) this.entities.get(key);
+ if (value == null) {
+ throw this.unknownEntity(key);
+ }
+ buf.append(value);
+ }
+ }
+
+
+ /**
+ * Pushes a character back to the read-back buffer.
+ *
+ * @param ch The character to push back.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li>The read-back buffer is empty.
+ * <li><code>ch != '\0'</code>
+ * </ul></dd></dl>
+ */
+ protected void unreadChar(char ch)
+ {
+ this.charReadTooMuch = ch;
+ }
+
+
+ /**
+ * Creates a parse exception for when an invalid valueset is given to
+ * a method.
+ *
+ * @param name The name of the entity.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>name != null</code>
+ * </ul></dd></dl>
+ */
+ protected XMLParseException invalidValueSet(String name)
+ {
+ String msg = "Invalid value set (entity name = \"" + name + "\")";
+ return new XMLParseException(this.getName(), this.parserLineNr, msg);
+ }
+
+
+ /**
+ * Creates a parse exception for when an invalid value is given to a
+ * method.
+ *
+ * @param name The name of the entity.
+ * @param value The value of the entity.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>name != null</code>
+ * <li><code>value != null</code>
+ * </ul></dd></dl>
+ */
+ protected XMLParseException invalidValue(String name,
+ String value)
+ {
+ String msg = "Attribute \"" + name + "\" does not contain a valid "
+ + "value (\"" + value + "\")";
+ return new XMLParseException(this.getName(), this.parserLineNr, msg);
+ }
+
+
+ /**
+ * Creates a parse exception for when the end of the data input has been
+ * reached.
+ */
+ protected XMLParseException unexpectedEndOfData()
+ {
+ String msg = "Unexpected end of data reached";
+ return new XMLParseException(this.getName(), this.parserLineNr, msg);
+ }
+
+
+ /**
+ * Creates a parse exception for when a syntax error occured.
+ *
+ * @param context The context in which the error occured.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>context != null</code>
+ * <li><code>context.length() &gt; 0</code>
+ * </ul></dd></dl>
+ */
+ protected XMLParseException syntaxError(String context)
+ {
+ String msg = "Syntax error while parsing " + context;
+ return new XMLParseException(this.getName(), this.parserLineNr, msg);
+ }
+
+
+ /**
+ * Creates a parse exception for when the next character read is not
+ * the character that was expected.
+ *
+ * @param charSet The set of characters (in human readable form) that was
+ * expected.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>charSet != null</code>
+ * <li><code>charSet.length() &gt; 0</code>
+ * </ul></dd></dl>
+ */
+ protected XMLParseException expectedInput(String charSet)
+ {
+ String msg = "Expected: " + charSet;
+ return new XMLParseException(this.getName(), this.parserLineNr, msg);
+ }
+
+
+ /**
+ * Creates a parse exception for when an entity could not be resolved.
+ *
+ * @param name The name of the entity.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>name != null</code>
+ * <li><code>name.length() &gt; 0</code>
+ * </ul></dd></dl>
+ */
+ protected XMLParseException unknownEntity(String name)
+ {
+ String msg = "Unknown or invalid entity: &" + name + ";";
+ return new XMLParseException(this.getName(), this.parserLineNr, msg);
+ }
+
+}

Added:
development/laboratory/users/DPMLTesting/src/nanoxml/XMLParseException.java
==============================================================================
--- (empty file)
+++
development/laboratory/users/DPMLTesting/src/nanoxml/XMLParseException.java
Mon May 2 21:57:40 2005
@@ -0,0 +1,130 @@
+/* XMLParseException.java
+ *
+ * $Revision: 1.1 $
+ * $Date: 2005/04/30 16:31:32 $
+ * $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 nanoxml;
+
+
+/**
+ * An XMLParseException is thrown when an error occures while parsing an XML
+ * string.
+ * <P>
+ * $Revision: 1.1 $<BR>
+ * $Date: 2005/04/30 16:31:32 $<P>
+ *
+ * @see nanoxml.XMLElement
+ *
+ * @author Marc De Scheemaecker
+ * @version $Name: $, $Revision: 1.1 $
+ */
+public class XMLParseException
+ extends RuntimeException
+{
+
+ /**
+ * Indicates that no line number has been associated with this exception.
+ */
+ public static final int NO_LINE = -1;
+
+
+ /**
+ * The line number in the source code where the error occurred, or
+ * <code>NO_LINE</code> if the line number is unknown.
+ *
+ * <dl><dt><b>Invariants:</b></dt><dd>
+ * <ul><li><code>lineNr &gt 0 || lineNr == NO_LINE</code>
+ * </ul></dd></dl>
+ */
+ private int lineNr;
+
+
+ /**
+ * Creates an exception.
+ *
+ * @param name The name of the element where the error is located.
+ * @param message A message describing what went wrong.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>message != null</code>
+ * </ul></dd></dl>
+ *
+ * <dl><dt><b>Postconditions:</b></dt><dd>
+ * <ul><li>getLineNr() => NO_LINE
+ * </ul></dd></dl><dl>
+ */
+ public XMLParseException(String name,
+ String message)
+ {
+ super("XML Parse Exception during parsing of "
+ + ((name == null) ? "the XML definition"
+ : ("a " + name + " element"))
+ + ": " + message);
+ this.lineNr = XMLParseException.NO_LINE;
+ }
+
+
+ /**
+ * Creates an exception.
+ *
+ * @param name The name of the element where the error is located.
+ * @param lineNr The number of the line in the input.
+ * @param message A message describing what went wrong.
+ *
+ * </dl><dl><dt><b>Preconditions:</b></dt><dd>
+ * <ul><li><code>message != null</code>
+ * <li><code>lineNr &gt; 0</code>
+ * </ul></dd></dl>
+ *
+ * <dl><dt><b>Postconditions:</b></dt><dd>
+ * <ul><li>getLineNr() => lineNr
+ * </ul></dd></dl><dl>
+ */
+ public XMLParseException(String name,
+ int lineNr,
+ String message)
+ {
+ super("XML Parse Exception during parsing of "
+ + ((name == null) ? "the XML definition"
+ : ("a " + name + " element"))
+ + " at line " + lineNr + ": " + message);
+ this.lineNr = lineNr;
+ }
+
+
+ /**
+ * Where the error occurred, or <code>NO_LINE</code> if the line number
is
+ * unknown.
+ *
+ * @see nanoxml.XMLParseException#NO_LINE
+ */
+ public int getLineNr()
+ {
+ return this.lineNr;
+ }
+
+}

Added:
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/Dependency.java
==============================================================================
--- (empty file)
+++
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/Dependency.java
Mon May 2 21:57:40 2005
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2005 The Digital Product Meta Library
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.refactorme;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Vector;
+
+import nanoxml.XMLElement;
+
+/**
+ * Represents the "dependencies" part of the "project" of a Magic index.xml
file.
+ *
+ * @author <a href="http://www.dpml.net/";>The Digital Product Meta
Library</a>
+ * @version $Id:$
+ */
+public class Dependency
+{
+ private Include[] includes;
+
+ public static Dependency create(XMLElement xml)
+ {
+ ArrayList list = new ArrayList(10);
+
+ Vector v = xml.getChildren();
+ Iterator it = v.iterator();
+ while ( it.hasNext() ) {
+ XMLElement child = (XMLElement) it.next();
+ String tagName = child.getName();
+ if ( tagName.equals("include") ) {
+ list.add(Include.create(child));
+ }
+ }
+
+ return new Dependency((Include[])list.toArray(new Include[0]));
+ }
+
+ public Dependency(Include[] includes)
+ {
+ this.includes = includes;
+ }
+
+ public Include[] getIncludes()
+ {
+ return includes;
+ }
+
+
+
+}

Added:
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/Importt.java
==============================================================================
--- (empty file)
+++
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/Importt.java
Mon May 2 21:57:40 2005
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2005 The Digital Product Meta Library
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.refactorme;
+
+import nanoxml.XMLElement;
+
+/**
+ * Represents an import element within a magic index.xml file.
+ *
+ * @author <a href="http://www.dpml.net/";>The Digital Product Meta
Library</a>
+ * @version $Id:$
+ */
+public class Importt
+{
+ String href;
+ String uri;
+ String index;
+
+
+ static public Importt create(XMLElement xml)
+ {
+ Importt importt = new Importt();
+ importt.setUri(xml.getStringAttribute("uri"));
+ importt.setHref(xml.getStringAttribute("href"));
+ importt.setIndex(xml.getStringAttribute("index"));
+ return importt;
+ }
+
+
+ /**
+ * @return Returns the href.
+ */
+ public String getHref()
+ {
+ return href;
+ }
+ /**
+ * @param href The href to set.
+ */
+ public void setHref(String href)
+ {
+ this.href = href;
+ }
+ /**
+ * @return Returns the index.
+ */
+ public String getIndex()
+ {
+ return index;
+ }
+ /**
+ * @param index The index to set.
+ */
+ public void setIndex(String index)
+ {
+ this.index = index;
+ }
+ /**
+ * @return Returns the uri.
+ */
+ public String getUri()
+ {
+ return uri;
+ }
+ /**
+ * @param uri The uri to set.
+ */
+ public void setUri(String uri)
+ {
+ this.uri = uri;
+ }
+}

Added:
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/Include.java
==============================================================================
--- (empty file)
+++
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/Include.java
Mon May 2 21:57:40 2005
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2005 The Digital Product Meta Library
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.refactorme;
+
+import nanoxml.XMLElement;
+
+/**
+ * TODO - description of this class
+ *
+ * @author <a href="http://www.dpml.net/";>The Digital Product Meta
Library</a>
+ * @version $Id:$
+ */
+public class Include
+{
+ private String key;
+ private boolean build;
+ private boolean runtime;
+
+ static public Include create(XMLElement xml)
+ {
+ String key = xml.getStringAttribute("key");
+ Include include = new Include(key);
+
include.setBuild(xml.getBooleanAttribute("build","true","false",false));
+
include.setRuntime(xml.getBooleanAttribute("runtime","true","false",false));
+ return include;
+ }
+
+ /**
+ *
+ */
+ public Include(String key)
+ {
+ this.key = key;
+ this.build = false;
+ this.runtime = false;
+ }
+
+ /**
+ * @return Returns the build.
+ */
+ public boolean isBuild()
+ {
+ return build;
+ }
+ /**
+ * @param build The build to set.
+ */
+ public void setBuild(boolean build)
+ {
+ this.build = build;
+ }
+ /**
+ * @return Returns the key.
+ */
+ public String getKey()
+ {
+ return key;
+ }
+ /**
+ * @param key The key to set.
+ */
+ public void setKey(String key)
+ {
+ this.key = key;
+ }
+ /**
+ * @return Returns the runtime.
+ */
+ public boolean isRuntime()
+ {
+ return runtime;
+ }
+ /**
+ * @param runtime The runtime to set.
+ */
+ public void setRuntime(boolean runtime)
+ {
+ this.runtime = runtime;
+ }
+}

Added:
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/Info.java
==============================================================================
--- (empty file)
+++
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/Info.java
Mon May 2 21:57:40 2005
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2005 The Digital Product Meta Library
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.refactorme;
+
+import java.util.Iterator;
+import java.util.Vector;
+
+import nanoxml.XMLElement;
+
+/**
+ * TODO - description of this class
+ *
+ * @author <a href="http://www.dpml.net/";>The Digital Product Meta
Library</a>
+ * @version $Id:$
+ */
+public class Info
+{
+ private String group;
+ private String name;
+ private String version;
+ private String type;
+ private String status;
+
+
+ static public Info create(XMLElement xml)
+ {
+ String group = null;
+ String name = null;
+ String version = null;
+ String status = null;
+ String type = null;
+
+ Vector v = xml.getChildren();
+ Iterator it = v.iterator();
+ while ( it.hasNext() ) {
+ XMLElement child = (XMLElement) it.next();
+ String tagName = child.getName();
+ if ( tagName.equals("group") ) {
+ group = child.getContent();
+ } else if ( tagName.equals("name") ) {
+ name = child.getContent();
+ } else if ( tagName.equals("version") ) {
+ version = child.getContent();
+ } else if ( tagName.equals("status") ) {
+ status = child.getContent();
+ } else if ( tagName.equals("type") ) {
+ type = child.getContent();
+ }
+ }
+ return new Info(group,name,version,type,status);
+ }
+
+
+ public Info(String group, String name, String version, String type)
+ {
+ this(group,name,version,type,null);
+ }
+
+ public Info(String group, String name, String version, String type,
String status)
+ {
+ this.group = group;
+ this.name = name;
+ this.version = version;
+ this.type = type;
+ this.status = status;
+ }
+
+ /**
+ * @return Returns the group.
+ */
+ public String getGroup()
+ {
+ return group;
+ }
+ /**
+ * @return Returns the name.
+ */
+ public String getName()
+ {
+ return name;
+ }
+ /**
+ * @return Returns the status.
+ */
+ public String getStatus()
+ {
+ return status;
+ }
+ /**
+ * @return Returns the type.
+ */
+ public String getType()
+ {
+ return type;
+ }
+ /**
+ * @return Returns the version.
+ */
+ public String getVersion()
+ {
+ return version;
+ }
+}

Added:
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/MagicIndexFile.java
==============================================================================
--- (empty file)
+++
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/MagicIndexFile.java
Mon May 2 21:57:40 2005
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2005 The Digital Product Meta Library
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.refactorme;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Vector;
+
+import nanoxml.XMLElement;
+
+/**
+ * This class represents the Magic index.xml file. It uses a super-simple
+ * lightweight xml parser to read and write the file.
+ *
+ * @author <a href="http://www.dpml.net/";>The Digital Product Meta
Library</a>
+ * @version $Id: $
+ */
+public class MagicIndexFile
+{
+ private String key;
+ private ArrayList imports;
+ private ArrayList projects;
+ private ArrayList resources;
+
+ /**
+ * @throws IOException
+ * @throws MagicIndexFileException
+ *
+ */
+ public MagicIndexFile(File descriptorFile) throws IOException,
MagicIndexFileException
+ {
+ this.imports = new ArrayList(10);
+ this.projects = new ArrayList(10);
+ this.resources = new ArrayList(10);
+
+ FileReader reader = new FileReader(descriptorFile);
+ XMLElement xml = new XMLElement();
+ xml.parseFromReader(reader);
+
+ this.key = (String) xml.getAttribute("key");
+
+ Vector v = xml.getChildren();
+ Iterator it = v.iterator();
+ while ( it.hasNext() ) {
+ XMLElement child = (XMLElement) it.next();
+ String tagName = child.getName();
+ if ( tagName.equals("import") ) {
+ imports.add(Importt.create(child));
+ } else if ( tagName.equals("project") ) {
+ projects.add(Project.create(child));
+ } else if ( tagName.equals("resource") ) {
+ resources.add(Resource.create(child));
+ }
+ }
+ }
+
+ /**
+ * @return Returns the imports.
+ */
+ public Importt[] getImports()
+ {
+ return (Importt[]) imports.toArray(new Importt[0]);
+ }
+ /**
+ * @return Returns the projects.
+ */
+ public Project[] getProjects()
+ {
+ return (Project[]) projects.toArray(new Project[0]);
+ }
+ /**
+ * @return Returns the resources.
+ */
+ public Resource[] getResources()
+ {
+ return (Resource[]) resources.toArray(new Resource[0]);
+ }
+ /**
+ * @return Returns the key.
+ */
+ public String getKey()
+ {
+ return key;
+ }
+}

Added:
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/MagicIndexFileException.java
==============================================================================
--- (empty file)
+++
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/MagicIndexFileException.java
Mon May 2 21:57:40 2005
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2005 The Digital Product Meta Library
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.refactorme;
+
+/**
+ * Exception class for dealing with magic index.xml files.
+ *
+ * @author <a href="http://www.dpml.net/";>The Digital Product Meta
Library</a>
+ * @version $Id:$
+ */
+public class MagicIndexFileException extends Exception
+{
+
+ /**
+ *
+ */
+ public MagicIndexFileException()
+ {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param arg0
+ */
+ public MagicIndexFileException(String arg0)
+ {
+ super(arg0);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param arg0
+ */
+ public MagicIndexFileException(Throwable arg0)
+ {
+ super(arg0);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param arg0
+ * @param arg1
+ */
+ public MagicIndexFileException(String arg0, Throwable arg1)
+ {
+ super(arg0, arg1);
+ // TODO Auto-generated constructor stub
+ }
+
+}

Added:
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/Project.java
==============================================================================
--- (empty file)
+++
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/Project.java
Mon May 2 21:57:40 2005
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2005 The Digital Product Meta Library
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.refactorme;
+
+import java.util.Iterator;
+import java.util.Vector;
+
+import nanoxml.XMLElement;
+
+/**
+ * This class represents a project within a magic index.xml file.
+ *
+ * @author <a href="http://www.dpml.net/";>The Digital Product Meta
Library</a>
+ * @version $Id:$
+ */
+public class Project
+{
+ private Info info;
+ private Dependency dependency;
+ private ProjectAttribute projectAttribute;
+
+
+ static public Project create(XMLElement xml) throws
MagicIndexFileException
+ {
+ Info info = null;
+ Dependency dependency = null;
+
+ Vector v = xml.getChildren();
+ Iterator it = v.iterator();
+ while ( it.hasNext() ) {
+ XMLElement child = (XMLElement) it.next();
+ String tagName = child.getName();
+ if ( tagName.equals("info") ) {
+ info = Info.create(child);
+ } else if ( tagName.equals("dependencies") ) {
+ dependency = Dependency.create(child);
+ }
+ }
+
+ ProjectAttribute pa = null;
+ String basedir = xml.getStringAttribute("basedir");
+ if ( basedir != null ) {
+ pa = new SABasedir(basedir);
+ } else {
+ String file = xml.getStringAttribute("file");
+ if ( file != null ) {
+ pa = new SAFile(file);
+ }
+ }
+
+ if ( pa == null ) {
+ throw new MagicIndexFileException("Attribute (basedir|file)
required in element \"project\" at line " + xml.getLineNr());
+ }
+ if ( info == null ) {
+ throw new MagicIndexFileException("<info> block required in
element \"project\" at line " + xml.getLineNr());
+ }
+
+ return new Project(pa,info,dependency);
+ }
+
+
+ public Project(ProjectAttribute pa, Info info)
+ {
+ this(pa,info,null);
+ }
+
+ public Project(ProjectAttribute pa, Info info, Dependency dependency)
+ {
+ this.projectAttribute = pa;
+ this.info = info;
+ this.dependency = dependency;
+ }
+
+ /**
+ * @return Returns the dependency.
+ */
+ public Dependency getDependency()
+ {
+ return dependency;
+ }
+ /**
+ * @return Returns the info.
+ */
+ public Info getInfo()
+ {
+ return info;
+ }
+ /**
+ * @return Returns the projectAttribute.
+ */
+ public ProjectAttribute getProjectAttribute()
+ {
+ return projectAttribute;
+ }
+}

Added:
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/ProjectAttribute.java
==============================================================================
--- (empty file)
+++
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/ProjectAttribute.java
Mon May 2 21:57:40 2005
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2005 The Digital Product Meta Library
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.refactorme;
+
+/**
+ * Represents either of the two kinds of string attributes a project must
have,
+ * file, or basedir.
+ *
+ * @author <a href="http://www.dpml.net/";>The Digital Product Meta
Library</a>
+ * @version $Id:$
+ */
+public class ProjectAttribute extends StringAttribute
+{
+ public ProjectAttribute(String str)
+ {
+ super(str);
+ }
+
+}

Added:
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/Resource.java
==============================================================================
--- (empty file)
+++
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/Resource.java
Mon May 2 21:57:40 2005
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2005 The Digital Product Meta Library
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.refactorme;
+
+import java.util.Iterator;
+import java.util.Vector;
+
+import nanoxml.XMLElement;
+
+/**
+ * Represents a resource in the index file.
+ *
+ * @author <a href="http://www.dpml.net/";>The Digital Product Meta
Library</a>
+ * @version $Id:$
+ */
+public class Resource
+{
+ private Info info;
+
+
+ static public Resource create(XMLElement xml) throws
MagicIndexFileException
+ {
+ Info info = null;
+
+ Vector v = xml.getChildren();
+ Iterator it = v.iterator();
+ while ( it.hasNext() ) {
+ XMLElement child = (XMLElement) it.next();
+ String tagName = child.getName();
+ if ( tagName.equals("info") ) {
+ info = Info.create(child);
+ }
+ }
+
+ if ( info == null )
+ {
+ throw new MagicIndexFileException("A resource must have an
\"info\" element.");
+ }
+
+ return new Resource(info);
+ }
+
+ public Resource(Info info)
+ {
+ this.info = info;
+ }
+
+}

Added:
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/SABasedir.java
==============================================================================
--- (empty file)
+++
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/SABasedir.java
Mon May 2 21:57:40 2005
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2005 The Digital Product Meta Library
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.refactorme;
+
+/**
+ * A "basedir=" xml element string attribute.
+ *
+ * @author <a href="http://www.dpml.net/";>The Digital Product Meta
Library</a>
+ * @version $Id:$
+ */
+public class SABasedir extends ProjectAttribute
+{
+ public SABasedir(String str)
+ {
+ super(str);
+ }
+}

Added:
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/SAFile.java
==============================================================================
--- (empty file)
+++
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/SAFile.java
Mon May 2 21:57:40 2005
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2005 The Digital Product Meta Library
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.refactorme;
+
+/**
+ * A "file=" xml element string attribute.
+ *
+ * @author <a href="http://www.dpml.net/";>The Digital Product Meta
Library</a>
+ * @version $Id:$
+ */
+public class SAFile extends ProjectAttribute
+{
+ public SAFile(String str)
+ {
+ super(str);
+ }
+}

Added:
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/StringAttribute.java
==============================================================================
--- (empty file)
+++
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/StringAttribute.java
Mon May 2 21:57:40 2005
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2005 The Digital Product Meta Library
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.refactorme;
+
+/**
+ * This represents a simple string attribute belonging to an xml element.
+ * It is simply a String.
+ * This class is meant to be subclassed for the purpose of creating
+ * type-specific constructor signatures.
+ *
+ * @author <a href="http://www.dpml.net/";>The Digital Product Meta
Library</a>
+ * @version $Id:$
+ */
+public class StringAttribute
+{
+ private String str;
+
+ public StringAttribute(String str)
+ {
+ this.str = str;
+ }
+
+ /**
+ * @return Returns the string value.
+ */
+ public String getStr()
+ {
+ return str;
+ }
+}

Added:
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/Test.java
==============================================================================
--- (empty file)
+++
development/laboratory/users/DPMLTesting/src/net/dpml/refactorme/Test.java
Mon May 2 21:57:40 2005
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2005 The Digital Product Meta Library
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.refactorme;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * @author <a href="http://www.dpml.net/";>The Digital Product Meta
Library</a>
+ * @version $Id:$
+ */
+public class Test
+{
+
+ /**
+ *
+ */
+ public Test()
+ {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+ public static void main(String[] args) throws IOException,
MagicIndexFileException
+ {
+ File testfile = new File("C:/parsetest/testfiles/index1.xml");
+ MagicIndexFile mif = new MagicIndexFile(testfile);
+ Importt[] imports = mif.getImports();
+ Project[] projects = mif.getProjects();
+ Resource[] resources = mif.getResources();
+ }
+}

Added: development/laboratory/users/DPMLTesting/testfiles/index1.xml
==============================================================================
--- (empty file)
+++ development/laboratory/users/DPMLTesting/testfiles/index1.xml Mon
May 2 21:57:40 2005
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<index key="dpml-ide-common">
+
+ <import uri="artifact:module:dpml/transit/dpml-transit#SNAPSHOT"/>
+ <import uri="artifact:module:dpml/magic/dpml-magic#SNAPSHOT"/>
+
+ <project file="module.xml">
+ <info>
+ <group>dpml/ide</group>
+ <name>dpml-ide-common</name>
+ <version>1.0.0</version>
+ <status>SNAPSHOT</status>
+ <type>module</type>
+ </info>
+ </project>
+
+ <project basedir="magic">
+ <info>
+ <group>dpml/ide</group>
+ <name>dpml-ide-common-magic</name>
+ <version>1.0.0</version>
+ <status>SNAPSHOT</status>
+ <type>jar</type>
+ </info>
+ <dependencies>
+ <include key="commons-lang"/>
+ <include key="dpml-transit-main"/>
+ <include key="ant"/>
+ <include key="dpml-magic-core"/>
+ </dependencies>
+ </project>
+
+ <resource>
+ <info>
+ <group>commons-lang</group>
+ <name>commons-lang</name>
+ <version>2.0</version>
+ <type>jar</type>
+ </info>
+ </resource>
+
+</index>
\ No newline at end of file

Added: development/laboratory/users/DPMLTesting/testfiles/index2.xml
==============================================================================
--- (empty file)
+++ development/laboratory/users/DPMLTesting/testfiles/index2.xml Mon
May 2 21:57:40 2005
@@ -0,0 +1,135 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<index key="dpml-idea-plugin">
+
+ <import uri="artifact:module:dpml/ide/dpml-ide-common#SNAPSHOT"/>
+
+ <project basedir="magic">
+ <info>
+ <group>dpml/idea-plugin</group>
+ <name>dpml-idea-magic</name>
+ <version>1.0.0</version>
+ <status>SNAPSHOT</status>
+ <type>jar</type>
+ </info>
+ <dependencies>
+ <include key="openapi" runtime="false"/>
+ <include key="forms_rt"/>
+ <include key="jdom" runtime="false"/>
+ <include key="dpml-ide-common-magic"/>
+ <include key="commons-lang"/>
+ <include key="commons-digester"/>
+ <include key="dpml-transit-main"/>
+ <include key="ant"/>
+ <include key="dpml-magic-core"/>
+ </dependencies>
+ </project>
+
+ <resource>
+ <info>
+ <group>LOCAL/idea</group>
+ <name>openapi</name>
+ <version>LOCAL</version>
+ <type>jar</type>
+ </info>
+ </resource>
+
+ <resource>
+ <info>
+ <group>LOCAL/idea</group>
+ <name>forms_rt</name>
+ <version>LOCAL</version>
+ <type>jar</type>
+ </info>
+ </resource>
+
+ <resource>
+ <info>
+ <group>jdom</group>
+ <name>jdom</name>
+ <version>1.0</version>
+ <type>jar</type>
+ </info>
+ </resource>
+
+ <resource>
+ <info>
+ <group>commons-lang</group>
+ <name>commons-lang</name>
+ <version>2.0</version>
+ <type>jar</type>
+ </info>
+ </resource>
+
+ <resource>
+ <info>
+ <group>commons-digester</group>
+ <name>commons-digester</name>
+ <version>1.6</version>
+ <type>jar</type>
+ </info>
+ <dependencies>
+ <include key="commons-beanutils"/>
+ <include key="commons-collections"/>
+ <include key="commons-logging"/>
+ </dependencies>
+ </resource>
+
+ <resource>
+ <info>
+ <group>commons-beanutils</group>
+ <name>commons-beanutils</name>
+ <version>1.6</version>
+ <type>jar</type>
+ </info>
+ <dependencies>
+ <include key="commons-logging"/>
+ </dependencies>
+ </resource>
+ <resource>
+ <info>
+ <group>commons-collections</group>
+ <name>commons-collections</name>
+ <version>2.1</version>
+ <type>jar</type>
+ </info>
+ </resource>
+
+ <resource>
+ <info>
+ <group>commons-logging</group>
+ <name>commons-logging</name>
+ <version>1.0.3</version>
+ <type>jar</type>
+ </info>
+ </resource>
+
+ <resource>
+ <info>
+ <group>dpml/transit</group>
+ <name>dpml-transit-main</name>
+ <version>SNAPSHOT</version>
+ <type>jar</type>
+ </info>
+ </resource>
+
+ <resource>
+ <info>
+ <group>ant</group>
+ <name>ant</name>
+ <version>1.6.2</version>
+ <type>jar</type>
+ </info>
+ </resource>
+
+ <resource>
+ <info>
+ <group>dpml/magic</group>
+ <name>dpml-magic-core</name>
+ <version>SNAPSHOT</version>
+ <type>jar</type>
+ </info>
+ </resource>
+
+</index>
+
\ No newline at end of file

Added: development/laboratory/users/DPMLTesting/testfiles/index3.xml
==============================================================================
--- (empty file)
+++ development/laboratory/users/DPMLTesting/testfiles/index3.xml Mon
May 2 21:57:40 2005
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<index>
+ <import index="../../../../main/magic/index.xml"/>
+ <resource>
+ <info>
+ <group>emma</group>
+ <name>emma</name>
+ <version>2.0.4217</version>
+ <type>jar</type>
+ </info>
+ </resource>
+ <resource>
+ <info>
+ <group>emma</group>
+ <name>emma_ant</name>
+ <version>2.0.4217</version>
+ <type>jar</type>
+ </info>
+ </resource>
+ <resource>
+ <info>
+ <group>junit</group>
+ <name>junit</name>
+ <version>3.8.1</version>
+ <type>jar</type>
+ </info>
+ <gump>
+ <classpath/>
+ </gump>
+ </resource>
+
+
+
+ <project basedir=".">
+ <info>
+ <group>dpml/magic</group>
+ <name>dpml-magic-emma</name>
+ <version>1.0.0</version>
+ <status>SNAPSHOT</status>
+ <type>jar</type>
+ </info>
+ <dependencies>
+ <include key="dpml-magic-core"/>
+ <include key="emma"/>
+ <include key="emma_ant"/>
+ </dependencies>
+ </project>
+ <resource>
+ <info>
+ <group>dpml/magic</group>
+ <name>dpml-magic-core</name>
+ <type>jar</type>
+ </info>
+ </resource>
+
+</index>
\ No newline at end of file

Added: development/laboratory/users/DPMLTesting/testfiles/index4.xml
==============================================================================
--- (empty file)
+++ development/laboratory/users/DPMLTesting/testfiles/index4.xml Mon
May 2 21:57:40 2005
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<index>
+
+ <import href="http://paris.dpml.net/svn/development/main/index.xml"/>
+
+ <project basedir=".">
+ <info>
+ <group>dpml/cocoon</group>
+ <name>dpml-cocoon-task</name>
+ <version>SNAPSHOT</version>
+ </info>
+ <dependencies>
+ <include key="dpml-magic-core"/>
+ <include key="dpml-transit-task"/>
+ </dependencies>
+ </project>
+
+</index>
\ No newline at end of file

Added: development/laboratory/users/DPMLTesting/testfiles/index5.xml
==============================================================================
--- (empty file)
+++ development/laboratory/users/DPMLTesting/testfiles/index5.xml Mon
May 2 21:57:40 2005
@@ -0,0 +1,52 @@
+<index>
+
+ <import index="../../../../main/magic/index.xml"/>
+
+ <project basedir="task">
+ <info>
+ <group>dpml/magic/spells/eclipse</group>
+ <name>dpml-magic-eclipse</name>
+ <version>1.0</version>
+ <status>SNAPSHOT</status>
+ </info>
+ <dependencies>
+ <include key="dpml-magic-core"/>
+ </dependencies>
+ </project>
+
+ <project basedir="test">
+ <info>
+ <group>dpml/magic/spells/eclipse</group>
+ <name>dpml-magic-eclipse-test</name>
+ <version>1.0</version>
+ <status>SNAPSHOT</status>
+ </info>
+ <plugins>
+ <include key="dpml-magic-eclipse"/>
+ </plugins>
+ </project>
+
+ <project basedir="elements">
+ <info>
+ <name>dpml-iso8583-elements</name>
+ <group>dpml/planet/iso8583/elements</group>
+ </info>
+ <dependencies>
+ <include key="jpos"/>
+ <include key="dpml-iso8583-api"/>
+ <include key="dpml-activity-api"/>
+ <include key="dpml-logging-api"/>
+ <include key="dpml-classic-api"/>
+ <include key="dpml-context-api"/>
+ <include key="dpml-context-impl" build="false" runtime="false"
test="true"/>
+ <include key="dpml-parameters-api"/>
+ <include key="dpml-parameters-impl" build="false"
runtime="false" test="true"/>
+ <include key="dpml-service-api"/>
+ <include key="dpml-transit-main"/>
+ </dependencies>
+ <plugins>
+ <include key="dpml-meta-tools"/>
+ </plugins>
+ </project>
+
+</index>
\ No newline at end of file



  • svn commit: r2455 - in development/laboratory/users/DPMLTesting: . bin src src/nanoxml src/net src/net/dpml src/net/dpml/refactorme testfiles, bseib, 05/02/2005

Archive powered by MHonArc 2.6.24.

Top of Page