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