1 package com.wutka.dtd;
2
3 import java.util.*;
4 import java.io.*;
5
6 /*** Represents a parsed Document Type Definition
7 *
8 * @author Mark Wutka
9 * @version $Revision: 1.16 $ $Date: 2002/07/19 01:20:11 $ by $Author: wutka $
10 */
11
12
13 public class DTD implements DTDOutput
14 {
15 /*** Contains all the elements defined in the DTD */
16 public Hashtable elements;
17
18 /*** Contains all the entities defined in the DTD */
19 public Hashtable entities;
20
21 /*** Contains all the notations defined in the DTD */
22 public Hashtable notations;
23
24 /*** Contains parsed DTD's for any external entity DTD declarations */
25 public Hashtable externalDTDs;
26
27 /*** Contains all the items defined in the DTD in their original order */
28 public Vector items;
29
30 /*** Contains the element that is most likely the root element or null
31 if the root element can't be determined. */
32 public DTDElement rootElement;
33
34 /*** Creates a new DTD */
35 public DTD()
36 {
37 elements = new Hashtable();
38 entities = new Hashtable();
39 notations = new Hashtable();
40 externalDTDs = new Hashtable();
41 items = new Vector();
42 }
43
44 /*** Writes the DTD to an output writer in standard DTD format (the format
45 * the parser normally reads).
46 * @param outWriter The writer where the DTD will be written
47 */
48 public void write(PrintWriter outWriter)
49 throws IOException
50 {
51 Enumeration e = items.elements();
52
53 while (e.hasMoreElements())
54 {
55 DTDOutput item = (DTDOutput) e.nextElement();
56
57 item.write(outWriter);
58 }
59 }
60
61 /*** Returns true if this object is equal to another */
62 public boolean equals(Object ob)
63 {
64 if (this == ob) return true;
65
66 if (!(ob instanceof DTD)) return false;
67
68 DTD otherDTD = (DTD) ob;
69
70 return items.equals(otherDTD.items);
71 }
72
73 /*** Stores an array of items in the items array */
74 public void setItems(Object[] newItems)
75 {
76 items = new Vector(newItems.length);
77 for (int i=0; i < newItems.length; i++)
78 {
79 items.addElement(newItems[i]);
80 }
81 }
82
83 /*** Returns the items as an array */
84 public Object[] getItems()
85 {
86 return items.toArray();
87 }
88
89 /*** Stores an item in the items array */
90 public void setItem(Object item, int i)
91 {
92 items.setElementAt(item, i);
93 }
94
95 /*** Retrieves an item from the items array */
96 public Object getItem(int i)
97 {
98 return items.elementAt(i);
99 }
100
101 /*** Retrieves a list of items of a particular type */
102 public Vector getItemsByType(Class itemType)
103 {
104 Vector results = new Vector();
105
106 Enumeration e = items.elements();
107
108 while (e.hasMoreElements())
109 {
110 Object ob = e.nextElement();
111
112 if (itemType.isAssignableFrom(ob.getClass()))
113 {
114 results.addElement(ob);
115 }
116 }
117
118 return results;
119 }
120 }