KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > agent > client > util > XMLElement


1 /* XMLElement.java
2  *
3  *
4  * This file is part of NanoXML 2 Lite.
5  * Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved.
6  *
7  * This software is provided 'as-is', without any express or implied warranty.
8  * In no event will the authors be held liable for any damages arising from the
9  * use of this software.
10  *
11  * Permission is granted to anyone to use this software for any purpose,
12  * including commercial applications, and to alter it and redistribute it
13  * freely, subject to the following restrictions:
14  *
15  * 1. The origin of this software must not be misrepresented; you must not
16  * claim that you wrote the original software. If you use this software in
17  * a product, an acknowledgment in the product documentation would be
18  * appreciated but is not required.
19  *
20  * 2. Altered source versions must be plainly marked as such, and must not be
21  * misrepresented as being the original software.
22  *
23  * 3. This notice may not be removed or altered from any source distribution.
24  *****************************************************************************/

25
26
27 package com.sslexplorer.agent.client.util;
28
29 import java.io.ByteArrayOutputStream JavaDoc;
30 import java.io.CharArrayReader JavaDoc;
31 import java.io.IOException JavaDoc;
32 import java.io.OutputStreamWriter JavaDoc;
33 import java.io.Reader JavaDoc;
34 import java.io.StringReader JavaDoc;
35 import java.io.Writer JavaDoc;
36 import java.text.MessageFormat JavaDoc;
37 import java.util.Enumeration JavaDoc;
38 import java.util.Hashtable JavaDoc;
39 import java.util.Vector JavaDoc;
40
41
42 /**
43  * XMLElement is a representation of an XML object. The object is able to parse
44  * XML code.
45  * <P><DL>
46  * <DT><B>Parsing XML Data</B></DT>
47  * <DD>
48  * You can parse XML data using the following code:
49  * <UL><CODE>
50  * XMLElement xml = new XMLElement();<BR>
51  * FileReader reader = new FileReader("filename.xml");<BR>
52  * xml.parseFromReader(reader);
53  * </CODE></UL></DD></DL>
54  * <DL><DT><B>Retrieving Attributes</B></DT>
55  * <DD>
56  * You can enumerate the attributes of an element using the method
57  * {@link #enumerateAttributeNames() enumerateAttributeNames}.
58  * The attribute values can be retrieved using the method
59  * {@link #getStringAttribute(java.lang.String) getStringAttribute}.
60  * The following example shows how to list the attributes of an element:
61  * <UL><CODE>
62  * XMLElement element = ...;<BR>
63  * Enumeration enum = element.getAttributeNames();<BR>
64  * while (enum.hasMoreElements()) {<BR>
65  * &nbsp;&nbsp;&nbsp;&nbsp;String key = (String) enum.nextElement();<BR>
66  * &nbsp;&nbsp;&nbsp;&nbsp;String value = element.getStringAttribute(key);<BR>
67  * &nbsp;&nbsp;&nbsp;&nbsp;System.out.println(key + " = " + value);<BR>
68  * }
69  * </CODE></UL></DD></DL>
70  * <DL><DT><B>Retrieving Child Elements</B></DT>
71  * <DD>
72  * You can enumerate the children of an element using
73  * {@link #enumerateChildren() enumerateChildren}.
74  * The number of child elements can be retrieved using
75  * {@link #countChildren() countChildren}.
76  * </DD></DL>
77  * <DL><DT><B>Elements Containing Character Data</B></DT>
78  * <DD>
79  * If an elements contains character data, like in the following example:
80  * <UL><CODE>
81  * &lt;title&gt;The Title&lt;/title&gt;
82  * </CODE></UL>
83  * you can retrieve that data using the method
84  * {@link #getContent() getContent}.
85  * </DD></DL>
86  * <DL><DT><B>Subclassing XMLElement</B></DT>
87  * <DD>
88  * When subclassing XMLElement, you need to override the method
89  * {@link #createAnotherElement() createAnotherElement}
90  * which has to return a new copy of the receiver.
91  * </DD></DL>
92  * <P>
93  *
94  * @see XMLParseException
95  *
96  * @author Marc De Scheemaecker
97  * &lt;<A HREF="mailto:cyberelf@mac.com">cyberelf@mac.com</A>&gt;
98  */

99 public class XMLElement
100 {
101
102     /**
103      * Serialization serial version ID.
104      */

105     static final long serialVersionUID = 6685035139346394777L;
106
107
108     /**
109      * Major version of NanoXML. Classes with the same major and minor
110      * version are binary compatible. Classes with the same major version
111      * are source compatible. If the major version is different, you may
112      * need to modify the client source code.
113      *
114      * @see XMLElement#NANOXML_MINOR_VERSION
115      */

116     public static final int NANOXML_MAJOR_VERSION = 2;
117
118
119     /**
120      * Minor version of NanoXML. Classes with the same major and minor
121      * version are binary compatible. Classes with the same major version
122      * are source compatible. If the major version is different, you may
123      * need to modify the client source code.
124      *
125      * @see XMLElement#NANOXML_MAJOR_VERSION
126      */

127     public static final int NANOXML_MINOR_VERSION = 2;
128
129
130     /**
131      * The attributes given to the element.
132      *
133      * <dl><dt><b>Invariants:</b></dt><dd>
134      * <ul><li>The field can be empty.
135      * <li>The field is never <code>null</code>.
136      * <li>The keys and the values are strings.
137      * </ul></dd></dl>
138      */

139     private Hashtable JavaDoc attributes;
140
141
142     /**
143      * Child elements of the element.
144      *
145      * <dl><dt><b>Invariants:</b></dt><dd>
146      * <ul><li>The field can be empty.
147      * <li>The field is never <code>null</code>.
148      * <li>The elements are instances of <code>XMLElement</code>
149      * or a subclass of <code>XMLElement</code>.
150      * </ul></dd></dl>
151      */

152     private Vector JavaDoc children;
153
154
155     /**
156      * The name of the element.
157      *
158      * <dl><dt><b>Invariants:</b></dt><dd>
159      * <ul><li>The field is <code>null</code> iff the element is not
160      * initialized by either parse or setName.
161      * <li>If the field is not <code>null</code>, it's not empty.
162      * <li>If the field is not <code>null</code>, it contains a valid
163      * XML identifier.
164      * </ul></dd></dl>
165      */

166     private String JavaDoc name;
167
168
169     /**
170      * The #PCDATA content of the object.
171      *
172      * <dl><dt><b>Invariants:</b></dt><dd>
173      * <ul><li>The field is <code>null</code> iff the element is not a
174      * #PCDATA element.
175      * <li>The field can be any string, including the empty string.
176      * </ul></dd></dl>
177      */

178     private String JavaDoc contents;
179
180
181     /**
182      * Conversion table for &amp;...; entities. The keys are the entity names
183      * without the &amp; and ; delimiters.
184      *
185      * <dl><dt><b>Invariants:</b></dt><dd>
186      * <ul><li>The field is never <code>null</code>.
187      * <li>The field always contains the following associations:
188      * "lt"&nbsp;=&gt;&nbsp;"&lt;", "gt"&nbsp;=&gt;&nbsp;"&gt;",
189      * "quot"&nbsp;=&gt;&nbsp;"\"", "apos"&nbsp;=&gt;&nbsp;"'",
190      * "amp"&nbsp;=&gt;&nbsp;"&amp;"
191      * <li>The keys are strings
192      * <li>The values are char arrays
193      * </ul></dd></dl>
194      */

195     private Hashtable JavaDoc entities;
196
197
198     /**
199      * The line number where the element starts.
200      *
201      * <dl><dt><b>Invariants:</b></dt><dd>
202      * <ul><li><code>lineNr &gt= 0</code>
203      * </ul></dd></dl>
204      */

205     private int lineNr;
206
207
208     /**
209      * <code>true</code> if the case of the element and attribute names
210      * are case insensitive.
211      */

212     private boolean ignoreCase;
213
214
215     /**
216      * <code>true</code> if the leading and trailing whitespace of #PCDATA
217      * sections have to be ignored.
218      */

219     private boolean ignoreWhitespace;
220
221
222     /**
223      * Character read too much.
224      * This character provides push-back functionality to the input reader
225      * without having to use a PushbackReader.
226      * If there is no such character, this field is '\0'.
227      */

228     private char charReadTooMuch;
229
230
231     /**
232      * The reader provided by the caller of the parse method.
233      *
234      * <dl><dt><b>Invariants:</b></dt><dd>
235      * <ul><li>The field is not <code>null</code> while the parse method
236      * is running.
237      * </ul></dd></dl>
238      */

239     private Reader JavaDoc reader;
240
241
242     /**
243      * The current line number in the source content.
244      *
245      * <dl><dt><b>Invariants:</b></dt><dd>
246      * <ul><li>parserLineNr &gt; 0 while the parse method is running.
247      * </ul></dd></dl>
248      */

249     private int parserLineNr;
250
251
252     /**
253      * Creates and initializes a new XML element.
254      * Calling the construction is equivalent to:
255      * <ul><code>new XMLElement(new Hashtable(), false, true)
256      * </code></ul>
257      *
258      * <dl><dt><b>Postconditions:</b></dt><dd>
259      * <ul><li>countChildren() => 0
260      * <li>enumerateChildren() => empty enumeration
261      * <li>enumeratePropertyNames() => empty enumeration
262      * <li>getChildren() => empty vector
263      * <li>getContent() => ""
264      * <li>getLineNr() => 0
265      * <li>getName() => null
266      * </ul></dd></dl>
267      *
268      * @see XMLElement#XMLElement(java.util.Hashtable)
269      * XMLElement(Hashtable)
270      * @see XMLElement#XMLElement(boolean)
271      * @see XMLElement#XMLElement(java.util.Hashtable,boolean)
272      * XMLElement(Hashtable, boolean)
273      */

274     public XMLElement()
275     {
276         this(new Hashtable JavaDoc(), false, true, true);
277     }
278
279
280     /**
281      * Creates and initializes a new XML element.
282      * Calling the construction is equivalent to:
283      * <ul><code>new XMLElement(entities, false, true)
284      * </code></ul>
285      *
286      * @param entities
287      * The entity conversion table.
288      *
289      * </dl><dl><dt><b>Preconditions:</b></dt><dd>
290      * <ul><li><code>entities != null</code>
291      * </ul></dd></dl>
292      *
293      * <dl><dt><b>Postconditions:</b></dt><dd>
294      * <ul><li>countChildren() => 0
295      * <li>enumerateChildren() => empty enumeration
296      * <li>enumeratePropertyNames() => empty enumeration
297      * <li>getChildren() => empty vector
298      * <li>getContent() => ""
299      * <li>getLineNr() => 0
300      * <li>getName() => null
301      * </ul></dd></dl><dl>
302      *
303      * @see XMLElement#XMLElement()
304      * @see XMLElement#XMLElement(boolean)
305      * @see XMLElement#XMLElement(java.util.Hashtable,boolean)
306      * XMLElement(Hashtable, boolean)
307      */

308     public XMLElement(Hashtable JavaDoc entities)
309     {
310         this(entities, false, true, true);
311     }
312
313
314     /**
315      * Creates and initializes a new XML element.
316      * Calling the construction is equivalent to:
317      * <ul><code>new XMLElement(new Hashtable(), skipLeadingWhitespace, true)
318      * </code></ul>
319      *
320      * @param skipLeadingWhitespace
321      * <code>true</code> if leading and trailing whitespace in PCDATA
322      * content has to be removed.
323      *
324      * </dl><dl><dt><b>Postconditions:</b></dt><dd>
325      * <ul><li>countChildren() => 0
326      * <li>enumerateChildren() => empty enumeration
327      * <li>enumeratePropertyNames() => empty enumeration
328      * <li>getChildren() => empty vector
329      * <li>getContent() => ""
330      * <li>getLineNr() => 0
331      * <li>getName() => null
332      * </ul></dd></dl><dl>
333      *
334      * @see XMLElement#XMLElement()
335      * @see XMLElement#XMLElement(java.util.Hashtable)
336      * XMLElement(Hashtable)
337      * @see XMLElement#XMLElement(java.util.Hashtable,boolean)
338      * XMLElement(Hashtable, boolean)
339      */

340     public XMLElement(boolean skipLeadingWhitespace)
341     {
342         this(new Hashtable JavaDoc(), skipLeadingWhitespace, true, true);
343     }
344
345
346     /**
347      * Creates and initializes a new XML element.
348      * Calling the construction is equivalent to:
349      * <ul><code>new XMLElement(entities, skipLeadingWhitespace, true)
350      * </code></ul>
351      *
352      * @param entities
353      * The entity conversion table.
354      * @param skipLeadingWhitespace
355      * <code>true</code> if leading and trailing whitespace in PCDATA
356      * content has to be removed.
357      *
358      * </dl><dl><dt><b>Preconditions:</b></dt><dd>
359      * <ul><li><code>entities != null</code>
360      * </ul></dd></dl>
361      *
362      * <dl><dt><b>Postconditions:</b></dt><dd>
363      * <ul><li>countChildren() => 0
364      * <li>enumerateChildren() => empty enumeration
365      * <li>enumeratePropertyNames() => empty enumeration
366      * <li>getChildren() => empty vector
367      * <li>getContent() => ""
368      * <li>getLineNr() => 0
369      * <li>getName() => null
370      * </ul></dd></dl><dl>
371      *
372      * @see XMLElement#XMLElement()
373      * @see XMLElement#XMLElement(boolean)
374      * @see XMLElement#XMLElement(java.util.Hashtable)
375      * XMLElement(Hashtable)
376      */

377     public XMLElement(Hashtable JavaDoc entities,
378                       boolean skipLeadingWhitespace)
379     {
380         this(entities, skipLeadingWhitespace, true, true);
381     }
382
383
384     /**
385      * Creates and initializes a new XML element.
386      *
387      * @param entities
388      * The entity conversion table.
389      * @param skipLeadingWhitespace
390      * <code>true</code> if leading and trailing whitespace in PCDATA
391      * content has to be removed.
392      * @param ignoreCase
393      * <code>true</code> if the case of element and attribute names have
394      * to be ignored.
395      *
396      * </dl><dl><dt><b>Preconditions:</b></dt><dd>
397      * <ul><li><code>entities != null</code>
398      * </ul></dd></dl>
399      *
400      * <dl><dt><b>Postconditions:</b></dt><dd>
401      * <ul><li>countChildren() => 0
402      * <li>enumerateChildren() => empty enumeration
403      * <li>enumeratePropertyNames() => empty enumeration
404      * <li>getChildren() => empty vector
405      * <li>getContent() => ""
406      * <li>getLineNr() => 0
407      * <li>getName() => null
408      * </ul></dd></dl><dl>
409      *
410      * @see XMLElement#XMLElement()
411      * @see XMLElement#XMLElement(boolean)
412      * @see XMLElement#XMLElement(java.util.Hashtable)
413      * XMLElement(Hashtable)
414      * @see XMLElement#XMLElement(java.util.Hashtable,boolean)
415      * XMLElement(Hashtable, boolean)
416      */

417     public XMLElement(Hashtable JavaDoc entities,
418                       boolean skipLeadingWhitespace,
419                       boolean ignoreCase)
420     {
421         this(entities, skipLeadingWhitespace, true, ignoreCase);
422     }
423
424
425     /**
426      * Creates and initializes a new XML element.
427      * <P>
428      * This constructor should <I>only</I> be called from
429      * {@link #createAnotherElement() createAnotherElement}
430      * to create child elements.
431      *
432      * @param entities
433      * The entity conversion table.
434      * @param skipLeadingWhitespace
435      * <code>true</code> if leading and trailing whitespace in PCDATA
436      * content has to be removed.
437      * @param fillBasicConversionTable
438      * <code>true</code> if the basic entities need to be added to
439      * the entity list.
440      * @param ignoreCase
441      * <code>true</code> if the case of element and attribute names have
442      * to be ignored.
443      *
444      * </dl><dl><dt><b>Preconditions:</b></dt><dd>
445      * <ul><li><code>entities != null</code>
446      * <li>if <code>fillBasicConversionTable == false</code>
447      * then <code>entities</code> contains at least the following
448      * entries: <code>amp</code>, <code>lt</code>, <code>gt</code>,
449      * <code>apos</code> and <code>quot</code>
450      * </ul></dd></dl>
451      *
452      * <dl><dt><b>Postconditions:</b></dt><dd>
453      * <ul><li>countChildren() => 0
454      * <li>enumerateChildren() => empty enumeration
455      * <li>enumeratePropertyNames() => empty enumeration
456      * <li>getChildren() => empty vector
457      * <li>getContent() => ""
458      * <li>getLineNr() => 0
459      * <li>getName() => null
460      * </ul></dd></dl><dl>
461      *
462      * @see XMLElement#createAnotherElement()
463      */

464     protected XMLElement(Hashtable JavaDoc entities,
465                          boolean skipLeadingWhitespace,
466                          boolean fillBasicConversionTable,
467                          boolean ignoreCase)
468     {
469         this.ignoreWhitespace = skipLeadingWhitespace;
470         this.ignoreCase = ignoreCase;
471         this.name = null;
472         this.contents = ""; //$NON-NLS-1$
473
this.attributes = new Hashtable JavaDoc();
474         this.children = new Vector JavaDoc();
475         this.entities = entities;
476         this.lineNr = 0;
477         Enumeration JavaDoc e = this.entities.keys();
478         while (e.hasMoreElements()) {
479             Object JavaDoc key = e.nextElement();
480             Object JavaDoc value = this.entities.get(key);
481             if (value instanceof String JavaDoc) {
482                 value = ((String JavaDoc) value).toCharArray();
483                 this.entities.put(key, value);
484             }
485         }
486         if (fillBasicConversionTable) {
487             this.entities.put("amp", new char[] { '&' }); //$NON-NLS-1$
488
this.entities.put("quot", new char[] { '"' }); //$NON-NLS-1$
489
this.entities.put("apos", new char[] { '\'' }); //$NON-NLS-1$
490
this.entities.put("lt", new char[] { '<' }); //$NON-NLS-1$
491
this.entities.put("gt", new char[] { '>' }); //$NON-NLS-1$
492
}
493     }
494
495
496     /**
497      * Adds a child element.
498      *
499      * @param child
500      * The child element to add.
501      *
502      * </dl><dl><dt><b>Preconditions:</b></dt><dd>
503      * <ul><li><code>child != null</code>
504      * <li><code>child.getName() != null</code>
505      * <li><code>child</code> does not have a parent element
506      * </ul></dd></dl>
507      *
508      * <dl><dt><b>Postconditions:</b></dt><dd>
509      * <ul><li>countChildren() => old.countChildren() + 1
510      * <li>enumerateChildren() => old.enumerateChildren() + child
511      * <li>getChildren() => old.enumerateChildren() + child
512      * </ul></dd></dl><dl>
513      *
514      * @see XMLElement#countChildren()
515      * @see XMLElement#enumerateChildren()
516      * @see XMLElement#getChildren()
517      * @see XMLElement#removeChild(XMLElement)
518      * removeChild(XMLElement)
519      */

520     public void addChild(XMLElement child)
521     {
522         this.children.addElement(child);
523     }
524
525
526     /**
527      * Adds or modifies an attribute.
528      *
529      * @param name
530      * The name of the attribute.
531      * @param value
532      * The value of the attribute.
533      *
534      * </dl><dl><dt><b>Preconditions:</b></dt><dd>
535      * <ul><li><code>name != null</code>
536      * <li><code>name</code> is a valid XML identifier
537      * <li><code>value != null</code>
538      * </ul></dd></dl>
539      *
540      * <dl><dt><b>Postconditions:</b></dt><dd>
541      * <ul><li>enumerateAttributeNames()
542      * => old.enumerateAttributeNames() + name
543      * <li>getAttribute(name) => value
544      * </ul></dd></dl><dl>
545      *
546      * @see XMLElement#setDoubleAttribute(java.lang.String, double)
547      * setDoubleAttribute(String, double)
548      * @see XMLElement#setIntAttribute(java.lang.String, int)
549      * setIntAttribute(String, int)
550      * @see XMLElement#enumerateAttributeNames()
551      * @see XMLElement#getAttribute(java.lang.String)
552      * getAttribute(String)
553      * @see XMLElement#getAttribute(java.lang.String, java.lang.Object)
554      * getAttribute(String, Object)
555      * @see XMLElement#getAttribute(java.lang.String,
556      * java.util.Hashtable,
557      * java.lang.String, boolean)
558      * getAttribute(String, Hashtable, String, boolean)
559      * @see XMLElement#getStringAttribute(java.lang.String)
560      * getStringAttribute(String)
561      * @see XMLElement#getStringAttribute(java.lang.String,
562      * java.lang.String)
563      * getStringAttribute(String, String)
564      * @see XMLElement#getStringAttribute(java.lang.String,
565      * java.util.Hashtable,
566      * java.lang.String, boolean)
567      * getStringAttribute(String, Hashtable, String, boolean)
568      */

569     public void setAttribute(String JavaDoc name,
570                              Object JavaDoc value)
571     {
572         if (this.ignoreCase) {
573             name = name.toUpperCase();
574         }
575         this.attributes.put(name, value.toString());
576     }
577
578
579     /**
580      * Adds or modifies an attribute.
581      *
582      * @param name
583      * The name of the attribute.
584      * @param value
585      * The value of the attribute.
586      *
587      * @deprecated Use {@link #setAttribute(java.lang.String, java.lang.Object)
588      * setAttribute} instead.
589      */

590     public void addProperty(String JavaDoc name,
591                             Object JavaDoc value)
592     {
593         this.setAttribute(name, value);
594     }
595
596
597     /**
598      * Adds or modifies an attribute.
599      *
600      * @param name
601      * The name of the attribute.
602      * @param value
603      * The value of the attribute.
604      *
605      * </dl><dl><dt><b>Preconditions:</b></dt><dd>
606      * <ul><li><code>name != null</code>
607      * <li><code>name</code> is a valid XML identifier
608      * </ul></dd></dl>
609      *
610      * <dl><dt><b>Postconditions:</b></dt><dd>
611      * <ul><li>enumerateAttributeNames()
612      * => old.enumerateAttributeNames() + name
613      * <li>getIntAttribute(name) => value
614      * </ul></dd></dl><dl>
615      *
616      * @see XMLElement#setDoubleAttribute(java.lang.String, double)
617      * setDoubleAttribute(String, double)
618      * @see XMLElement#setAttribute(java.lang.String, java.lang.Object)
619      * setAttribute(String, Object)
620      * @see XMLElement#removeAttribute(java.lang.String)
621      * removeAttribute(String)
622      * @see XMLElement#enumerateAttributeNames()
623      * @see XMLElement#getIntAttribute(java.lang.String)
624      * getIntAttribute(String)
625      * @see XMLElement#getIntAttribute(java.lang.String, int)
626      * getIntAttribute(String, int)
627      * @see XMLElement#getIntAttribute(java.lang.String,
628      * java.util.Hashtable,
629      * java.lang.String, boolean)
630      * getIntAttribute(String, Hashtable, String, boolean)
631      */

632     public void setIntAttribute(String JavaDoc name,
633                                 int value)
634     {
635         if (this.ignoreCase) {
636             name = name.toUpperCase();
637         }
638         this.attributes.put(name, Integer.toString(value));
639     }
640
641
642     /**
643      * Adds or modifies an attribute.
644      *
645      * @param key
646      * The key of the attribute.
647      * @param value
648      * The value of the attribute.
649      *
650      * @deprecated Use {@link #setIntAttribute(java.lang.String, int)
651      * setIntAttribute} instead.
652      */

653     public void addProperty(String JavaDoc key,
654                             int value)
655     {
656         this.setIntAttribute(key, value);
657     }
658
659
660     /**
661      * Adds or modifies an attribute.
662      *
663      * @param name
664      * The name of the attribute.
665      * @param value
666      * The value of the attribute.
667      *
668      * </dl><dl><dt><b>Preconditions:</b></dt><dd>
669      * <ul><li><code>name != null</code>
670      * <li><code>name</code> is a valid XML identifier
671      * </ul></dd></dl>
672      *
673      * <dl><dt><b>Postconditions:</b></dt><dd>
674      * <ul><li>enumerateAttributeNames()
675      * => old.enumerateAttributeNames() + name
676      * <li>getDoubleAttribute(name) => value
677      * </ul></dd></dl><dl>
678      *
679      * @see XMLElement#setIntAttribute(java.lang.String, int)
680      * setIntAttribute(String, int)
681      * @see XMLElement#setAttribute(java.lang.String, java.lang.Object)
682      * setAttribute(String, Object)
683      * @see XMLElement#removeAttribute(java.lang.String)
684      * removeAttribute(String)
685      * @see XMLElement#enumerateAttributeNames()
686      * @see XMLElement#getDoubleAttribute(java.lang.String)
687      * getDoubleAttribute(String)
688      * @see XMLElement#getDoubleAttribute(java.lang.String, double)
689      * getDoubleAttribute(String, double)
690      * @see XMLElement#getDoubleAttribute(java.lang.String,
691      * java.util.Hashtable,
692      * java.lang.String, boolean)
693      * getDoubleAttribute(String, Hashtable, String, boolean)
694      */

695     public void setDoubleAttribute(String JavaDoc name,
696                                    double value)
697     {
698         if (this.ignoreCase) {
699             name = name.toUpperCase();
700         }
701         this.attributes.put(name, Double.toString(value));
702     }
703
704
705     /**
706      * Adds or modifies an attribute.
707      *
708      * @param name
709      * The name of the attribute.
710      * @param value
711      * The value of the attribute.
712      *
713      * @deprecated Use {@link #setDoubleAttribute(java.lang.String, double)
714      * setDoubleAttribute} instead.
715      */

716     public void addProperty(String JavaDoc name,
717                             double value)
718     {
719         this.setDoubleAttribute(name, value);
720     }
721
722
723     /**
724      * Returns the number of child elements of the element.
725      *
726      * <dl><dt><b>Postconditions:</b></dt><dd>
727      * <ul><li><code>result >= 0</code>
728      * </ul></dd></dl>
729      * @return child count
730      *
731      * @see XMLElement#addChild(XMLElement)
732      * addChild(XMLElement)
733      * @see XMLElement#enumerateChildren()
734      * @see XMLElement#getChildren()
735      * @see XMLElement#removeChild(XMLElement)
736      * removeChild(XMLElement)
737      */

738     public int countChildren()
739     {
740         return this.children.size();
741     }
742
743
744     /**
745      * Enumerates the attribute names.
746      *
747      * <dl><dt><b>Postconditions:</b></dt><dd>
748      * <ul><li><code>result != null</code>
749      * </ul></dd></dl>
750      * @return attribute names
751      *
752      * @see XMLElement#setDoubleAttribute(java.lang.String, double)
753      * setDoubleAttribute(String, double)
754      * @see XMLElement#setIntAttribute(java.lang.String, int)
755      * setIntAttribute(String, int)
756      * @see XMLElement#setAttribute(java.lang.String, java.lang.Object)
757      * setAttribute(String, Object)
758      * @see XMLElement#removeAttribute(java.lang.String)
759      * removeAttribute(String)
760      * @see XMLElement#getAttribute(java.lang.String)
761      * getAttribute(String)
762      * @see XMLElement#getAttribute(java.lang.String, java.lang.Object)
763      * getAttribute(String, String)
764      * @see XMLElement#getAttribute(java.lang.String,
765      * java.util.Hashtable,
766      * java.lang.String, boolean)
767      * getAttribute(String, Hashtable, String, boolean)
768      * @see XMLElement#getStringAttribute(java.lang.String)
769      * getStringAttribute(String)
770      * @see XMLElement#getStringAttribute(java.lang.String,
771      * java.lang.String)
772      * getStringAttribute(String, String)
773      * @see XMLElement#getStringAttribute(java.lang.String,
774      * java.util.Hashtable,
775      * java.lang.String, boolean)
776      * getStringAttribute(String, Hashtable, String, boolean)
777      * @see XMLElement#getIntAttribute(java.lang.String)
778      * getIntAttribute(String)
779      * @see XMLElement#getIntAttribute(java.lang.String, int)
780      * getIntAttribute(String, int)
781      * @see XMLElement#getIntAttribute(java.lang.String,
782      * java.util.Hashtable,
783      * java.lang.String, boolean)
784      * getIntAttribute(String, Hashtable, String, boolean)
785      * @see XMLElement#getDoubleAttribute(java.lang.String)
786      * getDoubleAttribute(String)
787      * @see XMLElement#getDoubleAttribute(java.lang.String, double)
788      * getDoubleAttribute(String, double)
789      * @see XMLElement#getDoubleAttribute(java.lang.String,
790      * java.util.Hashtable,
791      * java.lang.String, boolean)
792      * getDoubleAttribute(String, Hashtable, String, boolean)
793      * @see XMLElement#getBooleanAttribute(java.lang.String,
794      * java.lang.String,
795      * java.lang.String, boolean)
796      * getBooleanAttribute(String, String, String, boolean)
797      */

798     public Enumeration JavaDoc enumerateAttributeNames()
799     {
800         return this.attributes.keys();
801     }
802
803
804     /**
805      * Enumerates the attribute names.
806      * @return attribute names
807      *
808      * @deprecated Use {@link #enumerateAttributeNames()
809      * enumerateAttributeNames} instead.
810      */

811     public Enumeration JavaDoc enumeratePropertyNames()
812     {
813         return this.enumerateAttributeNames();
814     }
815
816
817     /**
818      * Enumerates the child elements.
819      *
820      * <dl><dt><b>Postconditions:</b></dt><dd>
821      * <ul><li><code>result != null</code>
822      * </ul></dd></dl>
823      * @return children
824      *
825      * @see XMLElement#addChild(XMLElement)
826      * addChild(XMLElement)
827      * @see XMLElement#countChildren()
828      * @see XMLElement#getChildren()
829      * @see XMLElement#removeChild(XMLElement)
830      * removeChild(XMLElement)
831      */

832     public Enumeration JavaDoc enumerateChildren()
833     {
834         return this.children.elements();
835     }
836
837
838     /**
839      * Returns the child elements as a Vector. It is safe to modify this
840      * Vector.
841      *
842      * <dl><dt><b>Postconditions:</b></dt><dd>
843      * <ul><li><code>result != null</code>
844      * </ul></dd></dl>
845      * @return children
846      *
847      * @see XMLElement#addChild(XMLElement)
848      * addChild(XMLElement)
849      * @see XMLElement#countChildren()
850      * @see XMLElement#enumerateChildren()
851      * @see XMLElement#removeChild(XMLElement)
852      * removeChild(XMLElement)
853      */

854     public Vector JavaDoc getChildren()
855     {
856         try {
857             return (Vector JavaDoc) this.children.clone();
858         } catch (Exception JavaDoc e) {
859             // this never happens, however, some Java compilers are so
860
// braindead that they require this exception clause
861
return null;
862         }
863     }
864
865
866     /**
867      * Returns the PCDATA content of the object. If there is no such content,
868      * <CODE>null</CODE> is returned.
869      * @return content
870      * @deprecated Use {@link #getContent() getContent} instead.
871      */

872     public String JavaDoc getContents()
873     {
874         return this.getContent();
875     }
876
877
878     /**
879      * Returns the PCDATA content of the object. If there is no such content,
880      * <CODE>null</CODE> is returned.
881      * @return content
882      *
883      * @see XMLElement#setContent(java.lang.String)
884      * setContent(String)
885      */

886     public String JavaDoc getContent()
887     {
888         return this.contents;
889     }
890
891
892     /**
893      * Returns the line nr in the source data on which the element is found.
894      * This method returns <code>0</code> there is no associated source data.
895      *
896      * <dl><dt><b>Postconditions:</b></dt><dd>
897      * <ul><li><code>result >= 0</code>
898      * </ul></dd></dl>
899      * @return line number
900      */

901     public int getLineNr()
902     {
903         return this.lineNr;
904     }
905
906
907     /**
908      * Returns an attribute of the element.
909      * If the attribute doesn't exist, <code>null</code> is returned.
910      *
911      * @param name The name of the attribute.
912      *
913      * </dl><dl><dt><b>Preconditions:</b></dt><dd>
914      * <ul><li><code>name != null</code>
915      * <li><code>name</code> is a valid XML identifier
916      * </ul></dd></dl><dl>
917      * @return attribute value
918      *
919      * @see XMLElement#setAttribute(java.lang.String, java.lang.Object)
920      * setAttribute(String, Object)
921      * @see XMLElement#removeAttribute(java.lang.String)
922      * removeAttribute(String)
923      * @see XMLElement#enumerateAttributeNames()
924      * @see XMLElement#getAttribute(java.lang.String, java.lang.Object)
925      * getAttribute(String, Object)
926      * @see XMLElement#getAttribute(java.lang.String,
927      * java.util.Hashtable,
928      * java.lang.String, boolean)
929      * getAttribute(String, Hashtable, String, boolean)
930      */

931     public Object JavaDoc getAttribute(String JavaDoc name)
932     {
933         return this.getAttribute(name, null);
934     }
935
936
937     /**
938      * Returns an attribute of the element.
939      * If the attribute doesn't exist, <code>defaultValue</code> is returned.
940      *
941      * @param name The name of the attribute.
942      * @param defaultValue Key to use if the attribute is missing.
943      *
944      * </dl><dl><dt><b>Preconditions:</b></dt><dd>
945      * <ul><li><code>name != null</code>
946      * <li><code>name</code> is a valid XML identifier
947      * </ul></dd></dl><dl>
948      * @return attribute
949      *
950      * @see XMLElement#setAttribute(java.lang.String, java.lang.Object)
951      * setAttribute(String, Object)
952      * @see XMLElement#removeAttribute(java.lang.String)
953      * removeAttribute(String)
954      * @see XMLElement#enumerateAttributeNames()
955      * @see XMLElement#getAttribute(java.lang.String)
956      * getAttribute(String)
957      * @see XMLElement#getAttribute(java.lang.String,
958      * java.util.Hashtable,
959      * java.lang.String, boolean)
960      * getAttribute(String, Hashtable, String, boolean)
961      */

962     public Object JavaDoc getAttribute(String JavaDoc name,
963                                Object JavaDoc defaultValue)
964     {
965         if (this.ignoreCase) {
966             name = name.toUpperCase();
967         }
968         Object JavaDoc value = this.attributes.get(name);
969         if (value == null) {
970             value = defaultValue;
971         }
972         return value;
973     }
974
975
976     /**
977      * Returns an attribute by looking up a key in a hashtable.
978      * If the attribute doesn't exist, the value corresponding to defaultKey
979      * is returned.
980      * <P>
981      * As an example, if valueSet contains the mapping <code>"one" =>
982      * "1"</code>
983      * and the element contains the attribute <code>attr="one"</code>, then
984      * <code>getAttribute("attr", mapping, defaultKey, false)</code> returns
985      * <code>"1"</code>.
986      *
987      * @param name
988      * The name of the attribute.
989      * @param valueSet
990      * Hashtable mapping keys to values.
991      * @param defaultKey
992      * Key to use if the attribute is missing.
993      * @param allowLiterals
994      * <code>true</code> if literals are valid.
995      *
996      * </dl><dl><dt><b>Preconditions:</b></dt><dd>
997      * <ul><li><code>name != null</code>
998      * <li><code>name</code> is a valid XML identifier
999      * <li><code>valueSet</code> != null
1000     * <li>the keys of <code>valueSet</code> are strings
1001     * </ul></dd></dl><dl>
1002     * @return attribute value
1003     *
1004     * @see XMLElement#setAttribute(java.lang.String, java.lang.Object)
1005     * setAttribute(String, Object)
1006     * @see XMLElement#removeAttribute(java.lang.String)
1007     * removeAttribute(String)
1008     * @see XMLElement#enumerateAttributeNames()
1009     * @see XMLElement#getAttribute(java.lang.String)
1010     * getAttribute(String)
1011     * @see XMLElement#getAttribute(java.lang.String, java.lang.Object)
1012     * getAttribute(String, Object)
1013     */

1014    public Object JavaDoc getAttribute(String JavaDoc name,
1015                               Hashtable JavaDoc valueSet,
1016                               String JavaDoc defaultKey,
1017                               boolean allowLiterals)
1018    {
1019        if (this.ignoreCase) {
1020            name = name.toUpperCase();
1021        }
1022        Object JavaDoc key = this.attributes.get(name);
1023        Object JavaDoc result;
1024        if (key == null) {
1025            key = defaultKey;
1026        }
1027        result = valueSet.get(key);
1028        if (result == null) {
1029            if (allowLiterals) {
1030                result = key;
1031            } else {
1032                throw this.invalidValue(name, (String JavaDoc) key);
1033            }
1034        }
1035        return result;
1036    }
1037
1038
1039    /**
1040     * Returns an attribute of the element.
1041     * If the attribute doesn't exist, <code>null</code> is returned.
1042     *
1043     * @param name The name of the attribute.
1044     *
1045     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
1046     * <ul><li><code>name != null</code>
1047     * <li><code>name</code> is a valid XML identifier
1048     * </ul></dd></dl><dl>
1049     * @return attribute value
1050     *
1051     * @see XMLElement#setAttribute(java.lang.String, java.lang.Object)
1052     * setAttribute(String, Object)
1053     * @see XMLElement#removeAttribute(java.lang.String)
1054     * removeAttribute(String)
1055     * @see XMLElement#enumerateAttributeNames()
1056     * @see XMLElement#getStringAttribute(java.lang.String,
1057     * java.lang.String)
1058     * getStringAttribute(String, String)
1059     * @see XMLElement#getStringAttribute(java.lang.String,
1060     * java.util.Hashtable,
1061     * java.lang.String, boolean)
1062     * getStringAttribute(String, Hashtable, String, boolean)
1063     */

1064    public String JavaDoc getStringAttribute(String JavaDoc name)
1065    {
1066        return this.getStringAttribute(name, null);
1067    }
1068
1069
1070    /**
1071     * Returns an attribute of the element.
1072     * If the attribute doesn't exist, <code>defaultValue</code> is returned.
1073     *
1074     * @param name The name of the attribute.
1075     * @param defaultValue Key to use if the attribute is missing.
1076     *
1077     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
1078     * <ul><li><code>name != null</code>
1079     * <li><code>name</code> is a valid XML identifier
1080     * </ul></dd></dl><dl>
1081     * @return attribute value
1082     *
1083     * @see XMLElement#setAttribute(java.lang.String, java.lang.Object)
1084     * setAttribute(String, Object)
1085     * @see XMLElement#removeAttribute(java.lang.String)
1086     * removeAttribute(String)
1087     * @see XMLElement#enumerateAttributeNames()
1088     * @see XMLElement#getStringAttribute(java.lang.String)
1089     * getStringAttribute(String)
1090     * @see XMLElement#getStringAttribute(java.lang.String,
1091     * java.util.Hashtable,
1092     * java.lang.String, boolean)
1093     * getStringAttribute(String, Hashtable, String, boolean)
1094     */

1095    public String JavaDoc getStringAttribute(String JavaDoc name,
1096                                     String JavaDoc defaultValue)
1097    {
1098        return (String JavaDoc) this.getAttribute(name, defaultValue);
1099    }
1100
1101
1102    /**
1103     * Returns an attribute by looking up a key in a hashtable.
1104     * If the attribute doesn't exist, the value corresponding to defaultKey
1105     * is returned.
1106     * <P>
1107     * As an example, if valueSet contains the mapping <code>"one" =>
1108     * "1"</code>
1109     * and the element contains the attribute <code>attr="one"</code>, then
1110     * <code>getAttribute("attr", mapping, defaultKey, false)</code> returns
1111     * <code>"1"</code>.
1112     *
1113     * @param name
1114     * The name of the attribute.
1115     * @param valueSet
1116     * Hashtable mapping keys to values.
1117     * @param defaultKey
1118     * Key to use if the attribute is missing.
1119     * @param allowLiterals
1120     * <code>true</code> if literals are valid.
1121     *
1122     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
1123     * <ul><li><code>name != null</code>
1124     * <li><code>name</code> is a valid XML identifier
1125     * <li><code>valueSet</code> != null
1126     * <li>the keys of <code>valueSet</code> are strings
1127     * <li>the values of <code>valueSet</code> are strings
1128     * </ul></dd></dl><dl>
1129     * @return attribute value
1130     *
1131     * @see XMLElement#setAttribute(java.lang.String, java.lang.Object)
1132     * setAttribute(String, Object)
1133     * @see XMLElement#removeAttribute(java.lang.String)
1134     * removeAttribute(String)
1135     * @see XMLElement#enumerateAttributeNames()
1136     * @see XMLElement#getStringAttribute(java.lang.String)
1137     * getStringAttribute(String)
1138     * @see XMLElement#getStringAttribute(java.lang.String,
1139     * java.lang.String)
1140     * getStringAttribute(String, String)
1141     */

1142    public String JavaDoc getStringAttribute(String JavaDoc name,
1143                                     Hashtable JavaDoc valueSet,
1144                                     String JavaDoc defaultKey,
1145                                     boolean allowLiterals)
1146    {
1147        return (String JavaDoc) this.getAttribute(name, valueSet, defaultKey,
1148                                          allowLiterals);
1149    }
1150
1151
1152    /**
1153     * Returns an attribute of the element.
1154     * If the attribute doesn't exist, <code>0</code> is returned.
1155     *
1156     * @param name The name of the attribute.
1157     *
1158     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
1159     * <ul><li><code>name != null</code>
1160     * <li><code>name</code> is a valid XML identifier
1161     * </ul></dd></dl><dl>
1162     * @return attribute value
1163     *
1164     * @see XMLElement#setIntAttribute(java.lang.String, int)
1165     * setIntAttribute(String, int)
1166     * @see XMLElement#enumerateAttributeNames()
1167     * @see XMLElement#getIntAttribute(java.lang.String, int)
1168     * getIntAttribute(String, int)
1169     * @see XMLElement#getIntAttribute(java.lang.String,
1170     * java.util.Hashtable,
1171     * java.lang.String, boolean)
1172     * getIntAttribute(String, Hashtable, String, boolean)
1173     */

1174    public int getIntAttribute(String JavaDoc name)
1175    {
1176        return this.getIntAttribute(name, 0);
1177    }
1178
1179
1180    /**
1181     * Returns an attribute of the element.
1182     * If the attribute doesn't exist, <code>defaultValue</code> is returned.
1183     *
1184     * @param name The name of the attribute.
1185     * @param defaultValue Key to use if the attribute is missing.
1186     *
1187     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
1188     * <ul><li><code>name != null</code>
1189     * <li><code>name</code> is a valid XML identifier
1190     * </ul></dd></dl><dl>
1191     * @return attribute value
1192     *
1193     * @see XMLElement#setIntAttribute(java.lang.String, int)
1194     * setIntAttribute(String, int)
1195     * @see XMLElement#enumerateAttributeNames()
1196     * @see XMLElement#getIntAttribute(java.lang.String)
1197     * getIntAttribute(String)
1198     * @see XMLElement#getIntAttribute(java.lang.String,
1199     * java.util.Hashtable,
1200     * java.lang.String, boolean)
1201     * getIntAttribute(String, Hashtable, String, boolean)
1202     */

1203    public int getIntAttribute(String JavaDoc name,
1204                               int defaultValue)
1205    {
1206        if (this.ignoreCase) {
1207            name = name.toUpperCase();
1208        }
1209        String JavaDoc value = (String JavaDoc) this.attributes.get(name);
1210        if (value == null) {
1211            return defaultValue;
1212        } else {
1213            try {
1214                return Integer.parseInt(value);
1215            } catch (NumberFormatException JavaDoc e) {
1216                throw this.invalidValue(name, value);
1217            }
1218        }
1219    }
1220
1221
1222    /**
1223     * Returns an attribute by looking up a key in a hashtable.
1224     * If the attribute doesn't exist, the value corresponding to defaultKey
1225     * is returned.
1226     * <P>
1227     * As an example, if valueSet contains the mapping <code>"one" => 1</code>
1228     * and the element contains the attribute <code>attr="one"</code>, then
1229     * <code>getIntAttribute("attr", mapping, defaultKey, false)</code> returns
1230     * <code>1</code>.
1231     *
1232     * @param name
1233     * The name of the attribute.
1234     * @param valueSet
1235     * Hashtable mapping keys to values.
1236     * @param defaultKey
1237     * Key to use if the attribute is missing.
1238     * @param allowLiteralNumbers
1239     * <code>true</code> if literal numbers are valid.
1240     *
1241     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
1242     * <ul><li><code>name != null</code>
1243     * <li><code>name</code> is a valid XML identifier
1244     * <li><code>valueSet</code> != null
1245     * <li>the keys of <code>valueSet</code> are strings
1246     * <li>the values of <code>valueSet</code> are Integer objects
1247     * <li><code>defaultKey</code> is either <code>null</code>, a
1248     * key in <code>valueSet</code> or an integer.
1249     * </ul></dd></dl><dl>
1250     *
1251     * @return attribute value
1252     * @see XMLElement#setIntAttribute(java.lang.String, int)
1253     * setIntAttribute(String, int)
1254     * @see XMLElement#enumerateAttributeNames()
1255     * @see XMLElement#getIntAttribute(java.lang.String)
1256     * getIntAttribute(String)
1257     * @see XMLElement#getIntAttribute(java.lang.String, int)
1258     * getIntAttribute(String, int)
1259     */

1260    public int getIntAttribute(String JavaDoc name,
1261                               Hashtable JavaDoc valueSet,
1262                               String JavaDoc defaultKey,
1263                               boolean allowLiteralNumbers)
1264    {
1265        if (this.ignoreCase) {
1266            name = name.toUpperCase();
1267        }
1268        Object JavaDoc key = this.attributes.get(name);
1269        Integer JavaDoc result;
1270        if (key == null) {
1271            key = defaultKey;
1272        }
1273        try {
1274            result = (Integer JavaDoc) valueSet.get(key);
1275        } catch (ClassCastException JavaDoc e) {
1276            throw this.invalidValueSet(name);
1277        }
1278        if (result == null) {
1279            if (! allowLiteralNumbers) {
1280                throw this.invalidValue(name, (String JavaDoc) key);
1281            }
1282            try {
1283                result = Integer.valueOf((String JavaDoc) key);
1284            } catch (NumberFormatException JavaDoc e) {
1285                throw this.invalidValue(name, (String JavaDoc) key);
1286            }
1287        }
1288        return result.intValue();
1289    }
1290
1291
1292    /**
1293     * Returns an attribute of the element.
1294     * If the attribute doesn't exist, <code>0.0</code> is returned.
1295     *
1296     * @param name The name of the attribute.
1297     *
1298     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
1299     * <ul><li><code>name != null</code>
1300     * <li><code>name</code> is a valid XML identifier
1301     * </ul></dd></dl><dl>
1302     * @return attribute value
1303     *
1304     * @see XMLElement#setDoubleAttribute(java.lang.String, double)
1305     * setDoubleAttribute(String, double)
1306     * @see XMLElement#enumerateAttributeNames()
1307     * @see XMLElement#getDoubleAttribute(java.lang.String, double)
1308     * getDoubleAttribute(String, double)
1309     * @see XMLElement#getDoubleAttribute(java.lang.String,
1310     * java.util.Hashtable,
1311     * java.lang.String, boolean)
1312     * getDoubleAttribute(String, Hashtable, String, boolean)
1313     */

1314    public double getDoubleAttribute(String JavaDoc name)
1315    {
1316        return this.getDoubleAttribute(name, 0.);
1317    }
1318
1319
1320    /**
1321     * Returns an attribute of the element.
1322     * If the attribute doesn't exist, <code>defaultValue</code> is returned.
1323     *
1324     * @param name The name of the attribute.
1325     * @param defaultValue Key to use if the attribute is missing.
1326     *
1327     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
1328     * <ul><li><code>name != null</code>
1329     * <li><code>name</code> is a valid XML identifier
1330     * </ul></dd></dl><dl>
1331     * @return attribute value
1332     *
1333     * @see XMLElement#setDoubleAttribute(java.lang.String, double)
1334     * setDoubleAttribute(String, double)
1335     * @see XMLElement#enumerateAttributeNames()
1336     * @see XMLElement#getDoubleAttribute(java.lang.String)
1337     * getDoubleAttribute(String)
1338     * @see XMLElement#getDoubleAttribute(java.lang.String,
1339     * java.util.Hashtable,
1340     * java.lang.String, boolean)
1341     * getDoubleAttribute(String, Hashtable, String, boolean)
1342     */

1343    public double getDoubleAttribute(String JavaDoc name,
1344                                     double defaultValue)
1345    {
1346        if (this.ignoreCase) {
1347            name = name.toUpperCase();
1348        }
1349        String JavaDoc value = (String JavaDoc) this.attributes.get(name);
1350        if (value == null) {
1351            return defaultValue;
1352        } else {
1353            try {
1354                return Double.valueOf(value).doubleValue();
1355            } catch (NumberFormatException JavaDoc e) {
1356                throw this.invalidValue(name, value);
1357            }
1358        }
1359    }
1360
1361
1362    /**
1363     * Returns an attribute by looking up a key in a hashtable.
1364     * If the attribute doesn't exist, the value corresponding to defaultKey
1365     * is returned.
1366     * <P>
1367     * As an example, if valueSet contains the mapping <code>"one" =&gt;
1368     * 1.0</code>
1369     * and the element contains the attribute <code>attr="one"</code>, then
1370     * <code>getDoubleAttribute("attr", mapping, defaultKey, false)</code>
1371     * returns <code>1.0</code>.
1372     *
1373     * @param name
1374     * The name of the attribute.
1375     * @param valueSet
1376     * Hashtable mapping keys to values.
1377     * @param defaultKey
1378     * Key to use if the attribute is missing.
1379     * @param allowLiteralNumbers
1380     * <code>true</code> if literal numbers are valid.
1381     *
1382     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
1383     * <ul><li><code>name != null</code>
1384     * <li><code>name</code> is a valid XML identifier
1385     * <li><code>valueSet != null</code>
1386     * <li>the keys of <code>valueSet</code> are strings
1387     * <li>the values of <code>valueSet</code> are Double objects
1388     * <li><code>defaultKey</code> is either <code>null</code>, a
1389     * key in <code>valueSet</code> or a double.
1390     * </ul></dd></dl><dl>
1391     * @return attribute value
1392     *
1393     * @see XMLElement#setDoubleAttribute(java.lang.String, double)
1394     * setDoubleAttribute(String, double)
1395     * @see XMLElement#enumerateAttributeNames()
1396     * @see XMLElement#getDoubleAttribute(java.lang.String)
1397     * getDoubleAttribute(String)
1398     * @see XMLElement#getDoubleAttribute(java.lang.String, double)
1399     * getDoubleAttribute(String, double)
1400     */

1401    public double getDoubleAttribute(String JavaDoc name,
1402                                     Hashtable JavaDoc valueSet,
1403                                     String JavaDoc defaultKey,
1404                                     boolean allowLiteralNumbers)
1405    {
1406        if (this.ignoreCase) {
1407            name = name.toUpperCase();
1408        }
1409        Object JavaDoc key = this.attributes.get(name);
1410        Double JavaDoc result;
1411        if (key == null) {
1412            key = defaultKey;
1413        }
1414        try {
1415            result = (Double JavaDoc) valueSet.get(key);
1416        } catch (ClassCastException JavaDoc e) {
1417            throw this.invalidValueSet(name);
1418        }
1419        if (result == null) {
1420            if (! allowLiteralNumbers) {
1421                throw this.invalidValue(name, (String JavaDoc) key);
1422            }
1423            try {
1424                result = Double.valueOf((String JavaDoc) key);
1425            } catch (NumberFormatException JavaDoc e) {
1426                throw this.invalidValue(name, (String JavaDoc) key);
1427            }
1428        }
1429        return result.doubleValue();
1430    }
1431
1432
1433    /**
1434     * Returns an attribute of the element.
1435     * If the attribute doesn't exist, <code>defaultValue</code> is returned.
1436     * If the value of the attribute is equal to <code>trueValue</code>,
1437     * <code>true</code> is returned.
1438     * If the value of the attribute is equal to <code>falseValue</code>,
1439     * <code>false</code> is returned.
1440     * If the value doesn't match <code>trueValue</code> or
1441     * <code>falseValue</code>, an exception is thrown.
1442     *
1443     * @param name The name of the attribute.
1444     * @param trueValue The value associated with <code>true</code>.
1445     * @param falseValue The value associated with <code>true</code>.
1446     * @param defaultValue Value to use if the attribute is missing.
1447     *
1448     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
1449     * <ul><li><code>name != null</code>
1450     * <li><code>name</code> is a valid XML identifier
1451     * <li><code>trueValue</code> and <code>falseValue</code>
1452     * are different strings.
1453     * </ul></dd></dl><dl>
1454     * @return attribute value
1455     *
1456     * @see XMLElement#setAttribute(java.lang.String, java.lang.Object)
1457     * setAttribute(String, Object)
1458     * @see XMLElement#removeAttribute(java.lang.String)
1459     * removeAttribute(String)
1460     * @see XMLElement#enumerateAttributeNames()
1461     */

1462    public boolean getBooleanAttribute(String JavaDoc name,
1463                                       String JavaDoc trueValue,
1464                                       String JavaDoc falseValue,
1465                                       boolean defaultValue)
1466    {
1467        if (this.ignoreCase) {
1468            name = name.toUpperCase();
1469        }
1470        Object JavaDoc value = this.attributes.get(name);
1471        if (value == null) {
1472            return defaultValue;
1473        } else if (value.equals(trueValue)) {
1474            return true;
1475        } else if (value.equals(falseValue)) {
1476            return false;
1477        } else {
1478            throw this.invalidValue(name, (String JavaDoc) value);
1479        }
1480    }
1481
1482
1483    /**
1484     * Returns an attribute by looking up a key in a hashtable.
1485     * @param name
1486     * @param valueSet
1487     * @param defaultKey
1488     *
1489     * @return attribute value
1490     * @deprecated Use {@link #getIntAttribute(java.lang.String,
1491     * java.util.Hashtable, java.lang.String, boolean)
1492     * getIntAttribute} instead.
1493     */

1494    public int getIntProperty(String JavaDoc name,
1495                              Hashtable JavaDoc valueSet,
1496                              String JavaDoc defaultKey)
1497    {
1498        return this.getIntAttribute(name, valueSet, defaultKey, false);
1499    }
1500
1501
1502    /**
1503     * Returns an attribute.
1504     * @param name
1505     *
1506     * @return attribute value
1507     * @deprecated Use {@link #getStringAttribute(java.lang.String)
1508     * getStringAttribute} instead.
1509     */

1510    public String JavaDoc getProperty(String JavaDoc name)
1511    {
1512        return this.getStringAttribute(name);
1513    }
1514
1515
1516    /**
1517     * Returns an attribute.
1518     * @param name
1519     * @param defaultValue
1520     *
1521     * @return attribute value
1522     * @deprecated Use {@link #getStringAttribute(java.lang.String,
1523     * java.lang.String) getStringAttribute} instead.
1524     */

1525    public String JavaDoc getProperty(String JavaDoc name,
1526                              String JavaDoc defaultValue)
1527    {
1528        return this.getStringAttribute(name, defaultValue);
1529    }
1530
1531
1532    /**
1533     * Returns an attribute.
1534     * @param name
1535     * @param defaultValue
1536     *
1537     * @return attribute value
1538     * @deprecated Use {@link #getIntAttribute(java.lang.String, int)
1539     * getIntAttribute} instead.
1540     */

1541    public int getProperty(String JavaDoc name,
1542                           int defaultValue)
1543    {
1544        return this.getIntAttribute(name, defaultValue);
1545    }
1546
1547
1548    /**
1549     * Returns an attribute.
1550     * @param name
1551     * @param defaultValue
1552     *
1553     * @return attribute value
1554     * @deprecated Use {@link #getDoubleAttribute(java.lang.String, double)
1555     * getDoubleAttribute} instead.
1556     */

1557    public double getProperty(String JavaDoc name,
1558                              double defaultValue)
1559    {
1560        return this.getDoubleAttribute(name, defaultValue);
1561    }
1562
1563
1564    /**
1565     * Returns an attribute.
1566     * @param key
1567     * @param trueValue
1568     * @param falseValue
1569     * @param defaultValue
1570     *
1571     * @return attribute value
1572     * @deprecated Use {@link #getBooleanAttribute(java.lang.String,
1573     * java.lang.String, java.lang.String, boolean)
1574     * getBooleanAttribute} instead.
1575     */

1576    public boolean getProperty(String JavaDoc key,
1577                               String JavaDoc trueValue,
1578                               String JavaDoc falseValue,
1579                               boolean defaultValue)
1580    {
1581        return this.getBooleanAttribute(key, trueValue, falseValue,
1582                                        defaultValue);
1583    }
1584
1585
1586    /**
1587     * Returns an attribute by looking up a key in a hashtable.
1588     * @param name
1589     * @param valueSet
1590     * @param defaultKey
1591     * @return attribute value
1592     *
1593     * @deprecated Use {@link #getAttribute(java.lang.String,
1594     * java.util.Hashtable, java.lang.String, boolean)
1595     * getAttribute} instead.
1596     */

1597    public Object JavaDoc getProperty(String JavaDoc name,
1598                              Hashtable JavaDoc valueSet,
1599                              String JavaDoc defaultKey)
1600    {
1601        return this.getAttribute(name, valueSet, defaultKey, false);
1602    }
1603
1604
1605    /**
1606     * Returns an attribute by looking up a key in a hashtable.
1607     * @param name
1608     * @param valueSet
1609     * @param defaultKey
1610     * @return attribute value
1611     *
1612     * @deprecated Use {@link #getStringAttribute(java.lang.String,
1613     * java.util.Hashtable, java.lang.String, boolean)
1614     * getStringAttribute} instead.
1615     */

1616    public String JavaDoc getStringProperty(String JavaDoc name,
1617                                    Hashtable JavaDoc valueSet,
1618                                    String JavaDoc defaultKey)
1619    {
1620        return this.getStringAttribute(name, valueSet, defaultKey, false);
1621    }
1622
1623
1624    /**
1625     * Returns an attribute by looking up a key in a hashtable.
1626     * @param name
1627     * @param valueSet
1628     * @param defaultKey
1629     * @return attribute value
1630     *
1631     * @deprecated Use {@link #getIntAttribute(java.lang.String,
1632     * java.util.Hashtable, java.lang.String, boolean)
1633     * getIntAttribute} instead.
1634     */

1635    public int getSpecialIntProperty(String JavaDoc name,
1636                                     Hashtable JavaDoc valueSet,
1637                                     String JavaDoc defaultKey)
1638    {
1639        return this.getIntAttribute(name, valueSet, defaultKey, true);
1640    }
1641
1642
1643    /**
1644     * Returns an attribute by looking up a key in a hashtable.
1645     * @param name
1646     * @param valueSet
1647     * @param defaultKey
1648     * @return attribute value
1649     *
1650     * @deprecated Use {@link #getDoubleAttribute(java.lang.String,
1651     * java.util.Hashtable, java.lang.String, boolean)
1652     * getDoubleAttribute} instead.
1653     */

1654    public double getSpecialDoubleProperty(String JavaDoc name,
1655                                           Hashtable JavaDoc valueSet,
1656                                           String JavaDoc defaultKey)
1657    {
1658        return this.getDoubleAttribute(name, valueSet, defaultKey, true);
1659    }
1660
1661
1662    /**
1663     * Returns the name of the element.
1664     *
1665     * @return name
1666     * @see XMLElement#setName(java.lang.String) setName(String)
1667     */

1668    public String JavaDoc getName()
1669    {
1670        return this.name;
1671    }
1672
1673
1674    /**
1675     * Returns the name of the element.
1676     *
1677     * @return name
1678     * @deprecated Use {@link #getName() getName} instead.
1679     */

1680    public String JavaDoc getTagName()
1681    {
1682        return this.getName();
1683    }
1684
1685
1686    /**
1687     * Reads one XML element from a java.io.Reader and parses it.
1688     *
1689     * @param reader
1690     * The reader from which to retrieve the XML data.
1691     *
1692     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
1693     * <ul><li><code>reader != null</code>
1694     * <li><code>reader</code> is not closed
1695     * </ul></dd></dl>
1696     *
1697     * <dl><dt><b>Postconditions:</b></dt><dd>
1698     * <ul><li>the state of the receiver is updated to reflect the XML element
1699     * parsed from the reader
1700     * <li>the reader points to the first character following the last
1701     * '&gt;' character of the XML element
1702     * </ul></dd></dl><dl>
1703     *
1704     * @throws java.io.IOException
1705     * If an error occured while reading the input.
1706     * @throws XMLParseException
1707     * If an error occured while parsing the read data.
1708     */

1709    public void parseFromReader(Reader JavaDoc reader)
1710    throws IOException JavaDoc, XMLParseException
1711    {
1712        this.parseFromReader(reader, /*startingLineNr*/ 1);
1713    }
1714
1715
1716    /**
1717     * Reads one XML element from a java.io.Reader and parses it.
1718     *
1719     * @param reader
1720     * The reader from which to retrieve the XML data.
1721     * @param startingLineNr
1722     * The line number of the first line in the data.
1723     *
1724     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
1725     * <ul><li><code>reader != null</code>
1726     * <li><code>reader</code> is not closed
1727     * </ul></dd></dl>
1728     *
1729     * <dl><dt><b>Postconditions:</b></dt><dd>
1730     * <ul><li>the state of the receiver is updated to reflect the XML element
1731     * parsed from the reader
1732     * <li>the reader points to the first character following the last
1733     * '&gt;' character of the XML element
1734     * </ul></dd></dl><dl>
1735     *
1736     * @throws java.io.IOException
1737     * If an error occured while reading the input.
1738     * @throws XMLParseException
1739     * If an error occured while parsing the read data.
1740     */

1741    public void parseFromReader(Reader JavaDoc reader,
1742                                int startingLineNr)
1743        throws IOException JavaDoc, XMLParseException
1744    {
1745        this.charReadTooMuch = '\0';
1746        this.reader = reader;
1747        this.parserLineNr = startingLineNr;
1748
1749        for (;;) {
1750            char ch = this.scanWhitespace();
1751
1752            if (ch != '<') {
1753                throw this.expectedInput("<"); //$NON-NLS-1$
1754
}
1755
1756            ch = this.readChar();
1757
1758            if ((ch == '!') || (ch == '?')) {
1759                this.skipSpecialTag(0);
1760            } else {
1761                this.unreadChar(ch);
1762                this.scanElement(this);
1763                return;
1764            }
1765        }
1766    }
1767
1768
1769    /**
1770     * Reads one XML element from a String and parses it.
1771     *
1772     * @param string string
1773     *
1774     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
1775     * <ul><li><code>string != null</code>
1776     * <li><code>string.length() &gt; 0</code>
1777     * </ul></dd></dl>
1778     *
1779     * <dl><dt><b>Postconditions:</b></dt><dd>
1780     * <ul><li>the state of the receiver is updated to reflect the XML element
1781     * parsed from the reader
1782     * </ul></dd></dl><dl>
1783     *
1784     * @throws XMLParseException
1785     * If an error occured while parsing the string.
1786     */

1787    public void parseString(String JavaDoc string)
1788        throws XMLParseException
1789    {
1790        try {
1791            this.parseFromReader(new StringReader JavaDoc(string),
1792                                 /*startingLineNr*/ 1);
1793        } catch (IOException JavaDoc e) {
1794            // Java exception handling suxx
1795
}
1796    }
1797
1798
1799    /**
1800     * Reads one XML element from a String and parses it.
1801     * @param string
1802     * @param offset offset
1803     *
1804     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
1805     * <ul><li><code>string != null</code>
1806     * <li><code>offset &lt; string.length()</code>
1807     * <li><code>offset &gt;= 0</code>
1808     * </ul></dd></dl>
1809     *
1810     * <dl><dt><b>Postconditions:</b></dt><dd>
1811     * <ul><li>the state of the receiver is updated to reflect the XML element
1812     * parsed from the reader
1813     * </ul></dd></dl><dl>
1814     *
1815     * @throws XMLParseException
1816     * If an error occured while parsing the string.
1817     */

1818    public void parseString(String JavaDoc string,
1819                            int offset)
1820        throws XMLParseException
1821    {
1822        this.parseString(string.substring(offset));
1823    }
1824
1825
1826    /**
1827     * Reads one XML element from a String and parses it.
1828     * @param string string
1829     * @param offset
1830     * The first character in <code>string</code> to scan.
1831     * @param end
1832     * The character where to stop scanning.
1833     * This character is not scanned.
1834     *
1835     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
1836     * <ul><li><code>string != null</code>
1837     * <li><code>end &lt;= string.length()</code>
1838     * <li><code>offset &lt; end</code>
1839     * <li><code>offset &gt;= 0</code>
1840     * </ul></dd></dl>
1841     *
1842     * <dl><dt><b>Postconditions:</b></dt><dd>
1843     * <ul><li>the state of the receiver is updated to reflect the XML element
1844     * parsed from the reader
1845     * </ul></dd></dl><dl>
1846     *
1847     * @throws XMLParseException
1848     * If an error occured while parsing the string.
1849     */

1850    public void parseString(String JavaDoc string,
1851                            int offset,
1852                            int end)
1853        throws XMLParseException
1854    {
1855        this.parseString(string.substring(offset, end));
1856    }
1857
1858
1859    /**
1860     * Reads one XML element from a String and parses it.
1861     *
1862     * @param string string
1863     * @param offset
1864     * The first character in <code>string</code> to scan.
1865     * @param end
1866     * The character where to stop scanning.
1867     * This character is not scanned.
1868     * @param startingLineNr
1869     * The line number of the first line in the data.
1870     *
1871     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
1872     * <ul><li><code>string != null</code>
1873     * <li><code>end &lt;= string.length()</code>
1874     * <li><code>offset &lt; end</code>
1875     * <li><code>offset &gt;= 0</code>
1876     * </ul></dd></dl>
1877     *
1878     * <dl><dt><b>Postconditions:</b></dt><dd>
1879     * <ul><li>the state of the receiver is updated to reflect the XML element
1880     * parsed from the reader
1881     * </ul></dd></dl><dl>
1882     *
1883     * @throws XMLParseException
1884     * If an error occured while parsing the string.
1885     */

1886    public void parseString(String JavaDoc string,
1887                            int offset,
1888                            int end,
1889                            int startingLineNr)
1890        throws XMLParseException
1891    {
1892        string = string.substring(offset, end);
1893        try {
1894            this.parseFromReader(new StringReader JavaDoc(string), startingLineNr);
1895        } catch (IOException JavaDoc e) {
1896            // Java exception handling suxx
1897
}
1898    }
1899
1900
1901    /**
1902     * Reads one XML element from a char array and parses it.
1903     * @param input input
1904     * @param offset
1905     * The first character in <code>string</code> to scan.
1906     * @param end
1907     * The character where to stop scanning.
1908     * This character is not scanned.
1909     *
1910     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
1911     * <ul><li><code>input != null</code>
1912     * <li><code>end &lt;= input.length</code>
1913     * <li><code>offset &lt; end</code>
1914     * <li><code>offset &gt;= 0</code>
1915     * </ul></dd></dl>
1916     *
1917     * <dl><dt><b>Postconditions:</b></dt><dd>
1918     * <ul><li>the state of the receiver is updated to reflect the XML element
1919     * parsed from the reader
1920     * </ul></dd></dl><dl>
1921     *
1922     * @throws XMLParseException
1923     * If an error occured while parsing the string.
1924     */

1925    public void parseCharArray(char[] input,
1926                               int offset,
1927                               int end)
1928        throws XMLParseException
1929    {
1930        this.parseCharArray(input, offset, end, /*startingLineNr*/ 1);
1931    }
1932
1933
1934    /**
1935     * Reads one XML element from a char array and parses it.
1936     * @param input input
1937     * @param offset
1938     * The first character in <code>string</code> to scan.
1939     * @param end
1940     * The character where to stop scanning.
1941     * This character is not scanned.
1942     * @param startingLineNr
1943     * The line number of the first line in the data.
1944     *
1945     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
1946     * <ul><li><code>input != null</code>
1947     * <li><code>end &lt;= input.length</code>
1948     * <li><code>offset &lt; end</code>
1949     * <li><code>offset &gt;= 0</code>
1950     * </ul></dd></dl>
1951     *
1952     * <dl><dt><b>Postconditions:</b></dt><dd>
1953     * <ul><li>the state of the receiver is updated to reflect the XML element
1954     * parsed from the reader
1955     * </ul></dd></dl><dl>
1956     *
1957     * @throws XMLParseException
1958     * If an error occured while parsing the string.
1959     */

1960    public void parseCharArray(char[] input,
1961                               int offset,
1962                               int end,
1963                               int startingLineNr)
1964        throws XMLParseException
1965    {
1966        try {
1967            Reader JavaDoc reader = new CharArrayReader JavaDoc(input, offset, end);
1968            this.parseFromReader(reader, startingLineNr);
1969        } catch (IOException JavaDoc e) {
1970            // This exception will never happen.
1971
}
1972    }
1973
1974
1975    /**
1976     * Removes a child element.
1977     *
1978     * @param child
1979     * The child element to remove.
1980     *
1981     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
1982     * <ul><li><code>child != null</code>
1983     * <li><code>child</code> is a child element of the receiver
1984     * </ul></dd></dl>
1985     *
1986     * <dl><dt><b>Postconditions:</b></dt><dd>
1987     * <ul><li>countChildren() => old.countChildren() - 1
1988     * <li>enumerateChildren() => old.enumerateChildren() - child
1989     * <li>getChildren() => old.enumerateChildren() - child
1990     * </ul></dd></dl><dl>
1991     *
1992     * @see XMLElement#addChild(XMLElement)
1993     * addChild(XMLElement)
1994     * @see XMLElement#countChildren()
1995     * @see XMLElement#enumerateChildren()
1996     * @see XMLElement#getChildren()
1997     */

1998    public void removeChild(XMLElement child)
1999    {
2000        this.children.removeElement(child);
2001    }
2002
2003
2004    /**
2005     * Removes an attribute.
2006     *
2007     * @param name
2008     * The name of the attribute.
2009     *
2010     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
2011     * <ul><li><code>name != null</code>
2012     * <li><code>name</code> is a valid XML identifier
2013     * </ul></dd></dl>
2014     *
2015     * <dl><dt><b>Postconditions:</b></dt><dd>
2016     * <ul><li>enumerateAttributeNames()
2017     * => old.enumerateAttributeNames() - name
2018     * <li>getAttribute(name) => <code>null</code>
2019     * </ul></dd></dl><dl>
2020     *
2021     * @see XMLElement#enumerateAttributeNames()
2022     * @see XMLElement#setDoubleAttribute(java.lang.String, double)
2023     * setDoubleAttribute(String, double)
2024     * @see XMLElement#setIntAttribute(java.lang.String, int)
2025     * setIntAttribute(String, int)
2026     * @see XMLElement#setAttribute(java.lang.String, java.lang.Object)
2027     * setAttribute(String, Object)
2028     * @see XMLElement#getAttribute(java.lang.String)
2029     * getAttribute(String)
2030     * @see XMLElement#getAttribute(java.lang.String, java.lang.Object)
2031     * getAttribute(String, Object)
2032     * @see XMLElement#getAttribute(java.lang.String,
2033     * java.util.Hashtable,
2034     * java.lang.String, boolean)
2035     * getAttribute(String, Hashtable, String, boolean)
2036     * @see XMLElement#getStringAttribute(java.lang.String)
2037     * getStringAttribute(String)
2038     * @see XMLElement#getStringAttribute(java.lang.String,
2039     * java.lang.String)
2040     * getStringAttribute(String, String)
2041     * @see XMLElement#getStringAttribute(java.lang.String,
2042     * java.util.Hashtable,
2043     * java.lang.String, boolean)
2044     * getStringAttribute(String, Hashtable, String, boolean)
2045     * @see XMLElement#getIntAttribute(java.lang.String)
2046     * getIntAttribute(String)
2047     * @see XMLElement#getIntAttribute(java.lang.String, int)
2048     * getIntAttribute(String, int)
2049     * @see XMLElement#getIntAttribute(java.lang.String,
2050     * java.util.Hashtable,
2051     * java.lang.String, boolean)
2052     * getIntAttribute(String, Hashtable, String, boolean)
2053     * @see XMLElement#getDoubleAttribute(java.lang.String)
2054     * getDoubleAttribute(String)
2055     * @see XMLElement#getDoubleAttribute(java.lang.String, double)
2056     * getDoubleAttribute(String, double)
2057     * @see XMLElement#getDoubleAttribute(java.lang.String,
2058     * java.util.Hashtable,
2059     * java.lang.String, boolean)
2060     * getDoubleAttribute(String, Hashtable, String, boolean)
2061     * @see XMLElement#getBooleanAttribute(java.lang.String,
2062     * java.lang.String,
2063     * java.lang.String, boolean)
2064     * getBooleanAttribute(String, String, String, boolean)
2065     */

2066    public void removeAttribute(String JavaDoc name)
2067    {
2068        if (this.ignoreCase) {
2069            name = name.toUpperCase();
2070        }
2071        this.attributes.remove(name);
2072    }
2073
2074
2075    /**
2076     * Removes an attribute.
2077     *
2078     * @param name
2079     * The name of the attribute.
2080     *
2081     * @deprecated Use {@link #removeAttribute(java.lang.String)
2082     * removeAttribute} instead.
2083     */

2084    public void removeProperty(String JavaDoc name)
2085    {
2086        this.removeAttribute(name);
2087    }
2088
2089
2090    /**
2091     * Removes an attribute.
2092     *
2093     * @param name
2094     * The name of the attribute.
2095     *
2096     * @deprecated Use {@link #removeAttribute(java.lang.String)
2097     * removeAttribute} instead.
2098     */

2099    public void removeChild(String JavaDoc name)
2100    {
2101        this.removeAttribute(name);
2102    }
2103
2104
2105    /**
2106     * Creates a new similar XML element.
2107     * <P>
2108     * You should override this method when subclassing XMLElement.
2109     */

2110    protected XMLElement createAnotherElement()
2111    {
2112        return new XMLElement(this.entities,
2113                              this.ignoreWhitespace,
2114                              false,
2115                              this.ignoreCase);
2116    }
2117
2118
2119    /**
2120     * Changes the content string.
2121     *
2122     * @param content
2123     * The new content string.
2124     */

2125    public void setContent(String JavaDoc content)
2126    {
2127        this.contents = content;
2128    }
2129
2130
2131    /**
2132     * Changes the name of the element.
2133     *
2134     * @param name
2135     * The new name.
2136     *
2137     * @deprecated Use {@link #setName(java.lang.String) setName} instead.
2138     */

2139    public void setTagName(String JavaDoc name)
2140    {
2141        this.setName(name);
2142    }
2143
2144
2145    /**
2146     * Changes the name of the element.
2147     *
2148     * @param name
2149     * The new name.
2150     *
2151     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
2152     * <ul><li><code>name != null</code>
2153     * <li><code>name</code> is a valid XML identifier
2154     * </ul></dd></dl>
2155     *
2156     * @see XMLElement#getName()
2157     */

2158    public void setName(String JavaDoc name)
2159    {
2160        this.name = name;
2161    }
2162
2163
2164    /**
2165     * Writes the XML element to a string.
2166     *
2167     * @see XMLElement#write(java.io.Writer) write(Writer)
2168     */

2169    public String JavaDoc toString()
2170    {
2171        try {
2172            ByteArrayOutputStream JavaDoc out = new ByteArrayOutputStream JavaDoc();
2173            OutputStreamWriter JavaDoc writer = new OutputStreamWriter JavaDoc(out);
2174            this.write(writer);
2175            writer.flush();
2176            return new String JavaDoc(out.toByteArray());
2177        } catch (IOException JavaDoc e) {
2178            // Java exception handling suxx
2179
return super.toString();
2180        }
2181    }
2182
2183
2184    /**
2185     * Writes the XML element to a writer.
2186     *
2187     * @param writer
2188     * The writer to write the XML data to.
2189     *
2190     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
2191     * <ul><li><code>writer != null</code>
2192     * <li><code>writer</code> is not closed
2193     * </ul></dd></dl>
2194     *
2195     * @throws java.io.IOException
2196     * If the data could not be written to the writer.
2197     *
2198     * @see XMLElement#toString()
2199     */

2200    public void write(Writer JavaDoc writer)
2201        throws IOException JavaDoc
2202    {
2203        if (this.name == null) {
2204            this.writeEncoded(writer, this.contents);
2205            return;
2206        }
2207        writer.write('<');
2208        writer.write(this.name);
2209        if (! this.attributes.isEmpty()) {
2210            Enumeration JavaDoc e = this.attributes.keys();
2211            while (e.hasMoreElements()) {
2212                writer.write(' ');
2213                String JavaDoc key = (String JavaDoc) e.nextElement();
2214                String JavaDoc value = (String JavaDoc) this.attributes.get(key);
2215                writer.write(key);
2216                writer.write('='); writer.write('"');
2217                this.writeEncoded(writer, value);
2218                writer.write('"');
2219            }
2220        }
2221        if ((this.contents != null) && (this.contents.length() > 0)) {
2222            writer.write('>');
2223            this.writeEncoded(writer, this.contents);
2224            writer.write('<'); writer.write('/');
2225            writer.write(this.name);
2226            writer.write('>');
2227        } else if (this.children.isEmpty()) {
2228            writer.write('/'); writer.write('>');
2229        } else {
2230            writer.write('>');
2231            Enumeration JavaDoc e = this.enumerateChildren();
2232            while (e.hasMoreElements()) {
2233                XMLElement child = (XMLElement) e.nextElement();
2234                child.write(writer);
2235            }
2236            writer.write('<'); writer.write('/');
2237            writer.write(this.name);
2238            writer.write('>');
2239        }
2240    }
2241
2242
2243    /**
2244     * Writes a string encoded to a writer.
2245     *
2246     * @param writer
2247     * The writer to write the XML data to.
2248     * @param str
2249     * The string to write encoded.
2250     *
2251     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
2252     * <ul><li><code>writer != null</code>
2253     * <li><code>writer</code> is not closed
2254     * <li><code>str != null</code>
2255     * </ul></dd></dl>
2256     */

2257    protected void writeEncoded(Writer JavaDoc writer,
2258                                String JavaDoc str)
2259        throws IOException JavaDoc
2260    {
2261        for (int i = 0; i < str.length(); i += 1) {
2262            char ch = str.charAt(i);
2263            switch (ch) {
2264                case '<':
2265                    writer.write('&'); writer.write('l'); writer.write('t');
2266                    writer.write(';');
2267                    break;
2268                case '>':
2269                    writer.write('&'); writer.write('g'); writer.write('t');
2270                    writer.write(';');
2271                    break;
2272                case '&':
2273                    writer.write('&'); writer.write('a'); writer.write('m');
2274                    writer.write('p'); writer.write(';');
2275                    break;
2276                case '"':
2277                    writer.write('&'); writer.write('q'); writer.write('u');
2278                    writer.write('o'); writer.write('t'); writer.write(';');
2279                    break;
2280                case '\'':
2281                    writer.write('&'); writer.write('a'); writer.write('p');
2282                    writer.write('o'); writer.write('s'); writer.write(';');
2283                    break;
2284                default:
2285                    int unicode = (int) ch;
2286                    if ((unicode < 32) || (unicode > 126)) {
2287                        writer.write('&'); writer.write('#');
2288                        writer.write('x');
2289                        writer.write(Integer.toString(unicode, 16));
2290                        writer.write(';');
2291                    } else {
2292                        writer.write(ch);
2293                    }
2294            }
2295        }
2296    }
2297
2298
2299    /**
2300     * Scans an identifier from the current reader.
2301     * The scanned identifier is appended to <code>result</code>.
2302     *
2303     * @param result
2304     * The buffer in which the scanned identifier will be put.
2305     *
2306     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
2307     * <ul><li><code>result != null</code>
2308     * <li>The next character read from the reader is a valid first
2309     * character of an XML identifier.
2310     * </ul></dd></dl>
2311     *
2312     * <dl><dt><b>Postconditions:</b></dt><dd>
2313     * <ul><li>The next character read from the reader won't be an identifier
2314     * character.
2315     * </ul></dd></dl><dl>
2316     */

2317    protected void scanIdentifier(StringBuffer JavaDoc result)
2318        throws IOException JavaDoc
2319    {
2320        for (;;) {
2321            char ch = this.readChar();
2322            if (((ch < 'A') || (ch > 'Z')) && ((ch < 'a') || (ch > 'z'))
2323                && ((ch < '0') || (ch > '9')) && (ch != '_') && (ch != '.')
2324                && (ch != ':') && (ch != '-') && (ch <= '\u007E')) {
2325                this.unreadChar(ch);
2326                return;
2327            }
2328            result.append(ch);
2329        }
2330    }
2331
2332
2333    /**
2334     * This method scans an identifier from the current reader.
2335     *
2336     * @return the next character following the whitespace.
2337     */

2338    protected char scanWhitespace()
2339        throws IOException JavaDoc
2340    {
2341        for (;;) {
2342            char ch = this.readChar();
2343            switch (ch) {
2344                case ' ':
2345                case '\t':
2346                case '\n':
2347                case '\r':
2348                    break;
2349                default:
2350                    return ch;
2351            }
2352        }
2353    }
2354
2355
2356    /**
2357     * This method scans an identifier from the current reader.
2358     * The scanned whitespace is appended to <code>result</code>.
2359     *
2360     * @return the next character following the whitespace.
2361     *
2362     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
2363     * <ul><li><code>result != null</code>
2364     * </ul></dd></dl>
2365     */

2366    protected char scanWhitespace(StringBuffer JavaDoc result)
2367        throws IOException JavaDoc
2368    {
2369        for (;;) {
2370            char ch = this.readChar();
2371            switch (ch) {
2372                case ' ':
2373                case '\t':
2374                case '\n':
2375                    result.append(ch);
2376                case '\r':
2377                    break;
2378                default:
2379                    return ch;
2380            }
2381        }
2382    }
2383
2384
2385    /**
2386     * This method scans a delimited string from the current reader.
2387     * The scanned string without delimiters is appended to
2388     * <code>string</code>.
2389     *
2390     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
2391     * <ul><li><code>string != null</code>
2392     * <li>the next char read is the string delimiter
2393     * </ul></dd></dl>
2394     */

2395    protected void scanString(StringBuffer JavaDoc string)
2396        throws IOException JavaDoc
2397    {
2398        char delimiter = this.readChar();
2399        if ((delimiter != '\'') && (delimiter != '"')) {
2400            throw this.expectedInput("' or \""); //$NON-NLS-1$
2401
}
2402        for (;;) {
2403            char ch = this.readChar();
2404            if (ch == delimiter) {
2405                return;
2406            } else if (ch == '&') {
2407                this.resolveEntity(string);
2408            } else {
2409                string.append(ch);
2410            }
2411        }
2412    }
2413
2414
2415    /**
2416     * Scans a #PCDATA element. CDATA sections and entities are resolved.
2417     * The next &lt; char is skipped.
2418     * The scanned data is appended to <code>data</code>.
2419     *
2420     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
2421     * <ul><li><code>data != null</code>
2422     * </ul></dd></dl>
2423     */

2424    protected void scanPCData(StringBuffer JavaDoc data)
2425        throws IOException JavaDoc
2426    {
2427        for (;;) {
2428            char ch = this.readChar();
2429            if (ch == '<') {
2430                ch = this.readChar();
2431                if (ch == '!') {
2432                    this.checkCDATA(data);
2433                } else {
2434                    this.unreadChar(ch);
2435                    return;
2436                }
2437            } else if (ch == '&') {
2438                this.resolveEntity(data);
2439            } else {
2440                data.append(ch);
2441            }
2442        }
2443    }
2444
2445
2446    /**
2447     * Scans a special tag and if the tag is a CDATA section, append its
2448     * content to <code>buf</code>.
2449     *
2450     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
2451     * <ul><li><code>buf != null</code>
2452     * <li>The first &lt; has already been read.
2453     * </ul></dd></dl>
2454     */

2455    protected boolean checkCDATA(StringBuffer JavaDoc buf)
2456        throws IOException JavaDoc
2457    {
2458        char ch = this.readChar();
2459        if (ch != '[') {
2460            this.unreadChar(ch);
2461            this.skipSpecialTag(0);
2462            return false;
2463        } else if (! this.checkLiteral("CDATA[")) { //$NON-NLS-1$
2464
this.skipSpecialTag(1); // one [ has already been read
2465
return false;
2466        } else {
2467            int delimiterCharsSkipped = 0;
2468            while (delimiterCharsSkipped < 3) {
2469                ch = this.readChar();
2470                switch (ch) {
2471                    case ']':
2472                        if (delimiterCharsSkipped < 2) {
2473                            delimiterCharsSkipped += 1;
2474                        } else {
2475                            buf.append(']');
2476                            buf.append(']');
2477                            delimiterCharsSkipped = 0;
2478                        }
2479                        break;
2480                    case '>':
2481                        if (delimiterCharsSkipped < 2) {
2482                            for (int i = 0; i < delimiterCharsSkipped; i++) {
2483                                buf.append(']');
2484                            }
2485                            delimiterCharsSkipped = 0;
2486                            buf.append('>');
2487                        } else {
2488                            delimiterCharsSkipped = 3;
2489                        }
2490                        break;
2491                    default:
2492                        for (int i = 0; i < delimiterCharsSkipped; i += 1) {
2493                            buf.append(']');
2494                        }
2495                        buf.append(ch);
2496                        delimiterCharsSkipped = 0;
2497                }
2498            }
2499            return true;
2500        }
2501    }
2502
2503
2504    /**
2505     * Skips a comment.
2506     *
2507     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
2508     * <ul><li>The first &lt;!-- has already been read.
2509     * </ul></dd></dl>
2510     */

2511    protected void skipComment()
2512        throws IOException JavaDoc
2513    {
2514        int dashesToRead = 2;
2515        while (dashesToRead > 0) {
2516            char ch = this.readChar();
2517            if (ch == '-') {
2518                dashesToRead -= 1;
2519            } else {
2520                dashesToRead = 2;
2521            }
2522        }
2523        if (this.readChar() != '>') {
2524            throw this.expectedInput(">"); //$NON-NLS-1$
2525
}
2526    }
2527
2528
2529    /**
2530     * Skips a special tag or comment.
2531     *
2532     * @param bracketLevel The number of open square brackets ([) that have
2533     * already been read.
2534     *
2535     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
2536     * <ul><li>The first &lt;! has already been read.
2537     * <li><code>bracketLevel >= 0</code>
2538     * </ul></dd></dl>
2539     */

2540    protected void skipSpecialTag(int bracketLevel)
2541        throws IOException JavaDoc
2542    {
2543        int tagLevel = 1; // <
2544
char stringDelimiter = '\0';
2545        if (bracketLevel == 0) {
2546            char ch = this.readChar();
2547            if (ch == '[') {
2548                bracketLevel += 1;
2549            } else if (ch == '-') {
2550                ch = this.readChar();
2551                if (ch == '[') {
2552                    bracketLevel += 1;
2553                } else if (ch == ']') {
2554                    bracketLevel -= 1;
2555                } else if (ch == '-') {
2556                    this.skipComment();
2557                    return;
2558                }
2559            }
2560        }
2561        while (tagLevel > 0) {
2562            char ch = this.readChar();
2563            if (stringDelimiter == '\0') {
2564                if ((ch == '"') || (ch == '\'')) {
2565                    stringDelimiter = ch;
2566                } else if (bracketLevel <= 0) {
2567                    if (ch == '<') {
2568                        tagLevel += 1;
2569                    } else if (ch == '>') {
2570                        tagLevel -= 1;
2571                    }
2572                }
2573                if (ch == '[') {
2574                    bracketLevel += 1;
2575                } else if (ch == ']') {
2576                    bracketLevel -= 1;
2577                }
2578            } else {
2579                if (ch == stringDelimiter) {
2580                    stringDelimiter = '\0';
2581                }
2582            }
2583        }
2584    }
2585
2586
2587    /**
2588     * Scans the data for literal text.
2589     * Scanning stops when a character does not match or after the complete
2590     * text has been checked, whichever comes first.
2591     *
2592     * @param literal the literal to check.
2593     *
2594     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
2595     * <ul><li><code>literal != null</code>
2596     * </ul></dd></dl>
2597     */

2598    protected boolean checkLiteral(String JavaDoc literal)
2599        throws IOException JavaDoc
2600    {
2601        int length = literal.length();
2602        for (int i = 0; i < length; i += 1) {
2603            if (this.readChar() != literal.charAt(i)) {
2604                return false;
2605            }
2606        }
2607        return true;
2608    }
2609
2610
2611    /**
2612     * Reads a character from a reader.
2613     */

2614    protected char readChar()
2615        throws IOException JavaDoc
2616    {
2617        if (this.charReadTooMuch != '\0') {
2618            char ch = this.charReadTooMuch;
2619            this.charReadTooMuch = '\0';
2620            return ch;
2621        } else {
2622            int i = this.reader.read();
2623            if (i < 0) {
2624                throw this.unexpectedEndOfData();
2625            } else if (i == 10) {
2626                this.parserLineNr += 1;
2627                return '\n';
2628            } else {
2629                return (char) i;
2630            }
2631        }
2632    }
2633
2634
2635    /**
2636     * Scans an XML element.
2637     *
2638     * @param elt The element that will contain the result.
2639     *
2640     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
2641     * <ul><li>The first &lt; has already been read.
2642     * <li><code>elt != null</code>
2643     * </ul></dd></dl>
2644     */

2645    protected void scanElement(XMLElement elt)
2646        throws IOException JavaDoc
2647    {
2648        StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
2649        this.scanIdentifier(buf);
2650        String JavaDoc name = buf.toString();
2651        elt.setName(name);
2652        char ch = this.scanWhitespace();
2653        while ((ch != '>') && (ch != '/')) {
2654            buf.setLength(0);
2655            this.unreadChar(ch);
2656            this.scanIdentifier(buf);
2657            String JavaDoc key = buf.toString();
2658            ch = this.scanWhitespace();
2659            if (ch != '=') {
2660                throw this.expectedInput("="); //$NON-NLS-1$
2661
}
2662            this.unreadChar(this.scanWhitespace());
2663            buf.setLength(0);
2664            this.scanString(buf);
2665            elt.setAttribute(key, buf);
2666            ch = this.scanWhitespace();
2667        }
2668        if (ch == '/') {
2669            ch = this.readChar();
2670            if (ch != '>') {
2671                throw this.expectedInput(">"); //$NON-NLS-1$
2672
}
2673            return;
2674        }
2675        buf.setLength(0);
2676        ch = this.scanWhitespace(buf);
2677        if (ch != '<') {
2678            this.unreadChar(ch);
2679            this.scanPCData(buf);
2680        } else {
2681            for (;;) {
2682                ch = this.readChar();
2683                if (ch == '!') {
2684                    if (this.checkCDATA(buf)) {
2685                        this.scanPCData(buf);
2686                        break;
2687                    } else {
2688                        ch = this.scanWhitespace(buf);
2689                        if (ch != '<') {
2690                            this.unreadChar(ch);
2691                            this.scanPCData(buf);
2692                            break;
2693                        }
2694                    }
2695                } else {
2696                    buf.setLength(0);
2697                    break;
2698                }
2699            }
2700        }
2701        if (buf.length() == 0) {
2702            while (ch != '/') {
2703                if (ch == '!') {
2704                    ch = this.readChar();
2705                    if (ch != '-') {
2706                        throw this.expectedInput(Messages.getString("XMLElement.commentOrElement")); //$NON-NLS-1$
2707
}
2708                    ch = this.readChar();
2709                    if (ch != '-') {
2710                        throw this.expectedInput(Messages.getString("XMLElement.commentOrElement")); //$NON-NLS-1$
2711
}
2712                    this.skipComment();
2713                } else {
2714                    this.unreadChar(ch);
2715                    XMLElement child = this.createAnotherElement();
2716                    this.scanElement(child);
2717                    elt.addChild(child);
2718                }
2719                ch = this.scanWhitespace();
2720                if (ch != '<') {
2721                    throw this.expectedInput("<"); //$NON-NLS-1$
2722
}
2723                ch = this.readChar();
2724            }
2725            this.unreadChar(ch);
2726        } else {
2727            if (this.ignoreWhitespace) {
2728                elt.setContent(buf.toString().trim());
2729            } else {
2730                elt.setContent(buf.toString());
2731            }
2732        }
2733        ch = this.readChar();
2734        if (ch != '/') {
2735            throw this.expectedInput("/"); //$NON-NLS-1$
2736
}
2737        this.unreadChar(this.scanWhitespace());
2738        if (! this.checkLiteral(name)) {
2739            throw this.expectedInput(name);
2740        }
2741        if (this.scanWhitespace() != '>') {
2742            throw this.expectedInput(">"); //$NON-NLS-1$
2743
}
2744    }
2745
2746
2747    /**
2748     * Resolves an entity. The name of the entity is read from the reader.
2749     * The value of the entity is appended to <code>buf</code>.
2750     *
2751     * @param buf Where to put the entity value.
2752     *
2753     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
2754     * <ul><li>The first &amp; has already been read.
2755     * <li><code>buf != null</code>
2756     * </ul></dd></dl>
2757     */

2758    protected void resolveEntity(StringBuffer JavaDoc buf)
2759        throws IOException JavaDoc
2760    {
2761        char ch = '\0';
2762        StringBuffer JavaDoc keyBuf = new StringBuffer JavaDoc();
2763        for (;;) {
2764            ch = this.readChar();
2765            if (ch == ';') {
2766                break;
2767            }
2768            keyBuf.append(ch);
2769        }
2770        String JavaDoc key = keyBuf.toString();
2771        if (key.charAt(0) == '#') {
2772            try {
2773                if (key.charAt(1) == 'x') {
2774                    ch = (char) Integer.parseInt(key.substring(2), 16);
2775                } else {
2776                    ch = (char) Integer.parseInt(key.substring(1), 10);
2777                }
2778            } catch (NumberFormatException JavaDoc e) {
2779                throw this.unknownEntity(key);
2780            }
2781            buf.append(ch);
2782        } else {
2783            char[] value = (char[]) this.entities.get(key);
2784            if (value == null) {
2785                throw this.unknownEntity(key);
2786            }
2787            buf.append(value);
2788        }
2789    }
2790
2791
2792    /**
2793     * Pushes a character back to the read-back buffer.
2794     *
2795     * @param ch The character to push back.
2796     *
2797     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
2798     * <ul><li>The read-back buffer is empty.
2799     * <li><code>ch != '\0'</code>
2800     * </ul></dd></dl>
2801     */

2802    protected void unreadChar(char ch)
2803    {
2804        this.charReadTooMuch = ch;
2805    }
2806
2807
2808    /**
2809     * Creates a parse exception for when an invalid valueset is given to
2810     * a method.
2811     *
2812     * @param name The name of the entity.
2813     *
2814     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
2815     * <ul><li><code>name != null</code>
2816     * </ul></dd></dl>
2817     */

2818    protected XMLParseException invalidValueSet(String JavaDoc name)
2819    {
2820        String JavaDoc msg = MessageFormat.format(Messages.getString("XMLElement.invalidValueSet"), new Object JavaDoc[] { name } ) ;//$NON-NLS-1$
2821
return new XMLParseException(this.getName(), this.parserLineNr, msg);
2822    }
2823
2824
2825    /**
2826     * Creates a parse exception for when an invalid value is given to a
2827     * method.
2828     *
2829     * @param name The name of the entity.
2830     * @param value The value of the entity.
2831     *
2832     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
2833     * <ul><li><code>name != null</code>
2834     * <li><code>value != null</code>
2835     * </ul></dd></dl>
2836     */

2837    protected XMLParseException invalidValue(String JavaDoc name,
2838                                             String JavaDoc value)
2839    {
2840        String JavaDoc msg = MessageFormat.format(Messages.getString("XMLElement.invalidValueInAttribute"), new Object JavaDoc[] { name } );//$NON-NLS-1$
2841
return new XMLParseException(this.getName(), this.parserLineNr, msg);
2842    }
2843
2844
2845    /**
2846     * Creates a parse exception for when the end of the data input has been
2847     * reached.
2848     */

2849    protected XMLParseException unexpectedEndOfData()
2850    {
2851        String JavaDoc msg = Messages.getString("XMLElement.unexpectedEndOfData"); //$NON-NLS-1$
2852
return new XMLParseException(this.getName(), this.parserLineNr, msg);
2853    }
2854
2855
2856    /**
2857     * Creates a parse exception for when a syntax error occured.
2858     *
2859     * @param context The context in which the error occured.
2860     *
2861     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
2862     * <ul><li><code>context != null</code>
2863     * <li><code>context.length() &gt; 0</code>
2864     * </ul></dd></dl>
2865     */

2866    protected XMLParseException syntaxError(String JavaDoc context)
2867    {
2868        String JavaDoc msg = MessageFormat.format(Messages.getString("XMLElement.parsingSyntaxError"), new Object JavaDoc[] { context } ); //$NON-NLS-1$
2869
return new XMLParseException(this.getName(), this.parserLineNr, msg);
2870    }
2871
2872
2873    /**
2874     * Creates a parse exception for when the next character read is not
2875     * the character that was expected.
2876     *
2877     * @param charSet The set of characters (in human readable form) that was
2878     * expected.
2879     *
2880     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
2881     * <ul><li><code>charSet != null</code>
2882     * <li><code>charSet.length() &gt; 0</code>
2883     * </ul></dd></dl>
2884     */

2885    protected XMLParseException expectedInput(String JavaDoc charSet)
2886    {
2887        String JavaDoc msg = MessageFormat.format(Messages.getString("XMLElement.expected"), new Object JavaDoc[] { charSet } ); //$NON-NLS-1$
2888
return new XMLParseException(this.getName(), this.parserLineNr, msg);
2889    }
2890
2891
2892    /**
2893     * Creates a parse exception for when an entity could not be resolved.
2894     *
2895     * @param name The name of the entity.
2896     *
2897     * </dl><dl><dt><b>Preconditions:</b></dt><dd>
2898     * <ul><li><code>name != null</code>
2899     * <li><code>name.length() &gt; 0</code>
2900     * </ul></dd></dl>
2901     */

2902    protected XMLParseException unknownEntity(String JavaDoc name)
2903    {
2904        String JavaDoc msg = Messages.getString("XMLElement.unknownOrInvalidEntity") + name + ";"; //$NON-NLS-1$ //$NON-NLS-2$
2905
return new XMLParseException(this.getName(), this.parserLineNr, msg);
2906    }
2907
2908}
2909
Popular Tags