DTDpublic class DTD extends Object implements DTDConstantsThe representation of an SGML DTD. DTD describes a document
syntax and is used in parsing of HTML documents. It contains
a list of elements and their attributes as well as a list of
entities defined in the DTD. |
Fields Summary |
---|
public String | name | public Vector | elements | public Hashtable | elementHash | public Hashtable | entityHash | public final Element | pcdata | public final Element | html | public final Element | meta | public final Element | base | public final Element | isindex | public final Element | head | public final Element | body | public final Element | applet | public final Element | param | public final Element | p | public final Element | title | final Element | style | final Element | link | final Element | script | public static final int | FILE_VERSION | static Hashtable | dtdHashThe hashtable of DTDs. |
Constructors Summary |
---|
protected DTD(String name)Creates a new DTD with the specified name.
this.name = name;
defEntity("#RE", GENERAL, '\r");
defEntity("#RS", GENERAL, '\n");
defEntity("#SPACE", GENERAL, ' ");
defineElement("unknown", EMPTY, false, true, null, null, null, null);
|
Methods Summary |
---|
protected javax.swing.text.html.parser.AttributeList | defAttributeList(java.lang.String name, int type, int modifier, java.lang.String value, java.lang.String values, javax.swing.text.html.parser.AttributeList atts)Creates and returns an AttributeList .
Vector vals = null;
if (values != null) {
vals = new Vector();
for (StringTokenizer s = new StringTokenizer(values, "|") ; s.hasMoreTokens() ;) {
String str = s.nextToken();
if (str.length() > 0) {
vals.addElement(str);
}
}
}
return new AttributeList(name, type, modifier, value, vals, atts);
| protected javax.swing.text.html.parser.ContentModel | defContentModel(int type, java.lang.Object obj, javax.swing.text.html.parser.ContentModel next)Creates and returns a new content model.
return new ContentModel(type, obj, next);
| protected javax.swing.text.html.parser.Element | defElement(java.lang.String name, int type, boolean omitStart, boolean omitEnd, javax.swing.text.html.parser.ContentModel content, java.lang.String[] exclusions, java.lang.String[] inclusions, javax.swing.text.html.parser.AttributeList atts)Creates and returns an Element .
BitSet excl = null;
if (exclusions != null && exclusions.length > 0) {
excl = new BitSet();
for (int i = 0; i < exclusions.length; i++) {
String str = exclusions[i];
if (str.length() > 0) {
excl.set(getElement(str).getIndex());
}
}
}
BitSet incl = null;
if (inclusions != null && inclusions.length > 0) {
incl = new BitSet();
for (int i = 0; i < inclusions.length; i++) {
String str = inclusions[i];
if (str.length() > 0) {
incl.set(getElement(str).getIndex());
}
}
}
return defineElement(name, type, omitStart, omitEnd, content, excl, incl, atts);
| public javax.swing.text.html.parser.Entity | defEntity(java.lang.String name, int type, int ch)Creates and returns a character Entity .
char data[] = {(char)ch};
return defineEntity(name, type, data);
| protected javax.swing.text.html.parser.Entity | defEntity(java.lang.String name, int type, java.lang.String str)Creates and returns an Entity .
int len = str.length();
char data[] = new char[len];
str.getChars(0, len, data, 0);
return defineEntity(name, type, data);
| public void | defineAttributes(java.lang.String name, javax.swing.text.html.parser.AttributeList atts)Returns the Element which matches the
specified AttributeList .
If one doesn't exist, a new one is created and returned.
Element e = getElement(name);
e.atts = atts;
| public javax.swing.text.html.parser.Element | defineElement(java.lang.String name, int type, boolean omitStart, boolean omitEnd, javax.swing.text.html.parser.ContentModel content, java.util.BitSet exclusions, java.util.BitSet inclusions, javax.swing.text.html.parser.AttributeList atts)Returns the Element which matches the
specified parameters. If one doesn't exist, a new
one is created and returned.
Element e = getElement(name);
e.type = type;
e.oStart = omitStart;
e.oEnd = omitEnd;
e.content = content;
e.exclusions = exclusions;
e.inclusions = inclusions;
e.atts = atts;
return e;
| public javax.swing.text.html.parser.Entity | defineEntity(java.lang.String name, int type, char[] data)Defines an entity. If the Entity specified
by name , type , and data
exists, it is returned; otherwise a new Entity
is created and is returned.
Entity ent = (Entity)entityHash.get(name);
if (ent == null) {
ent = new Entity(name, type, data);
entityHash.put(name, ent);
if (((type & GENERAL) != 0) && (data.length == 1)) {
switch (type & ~GENERAL) {
case CDATA:
case SDATA:
entityHash.put(new Integer(data[0]), ent);
break;
}
}
}
return ent;
| boolean | elementExists(java.lang.String name)Returns true if the element is part of the DTD,
otherwise returns false .
Element e = (Element)elementHash.get(name);
return ((e == null) ? false : true);
| public static javax.swing.text.html.parser.DTD | getDTD(java.lang.String name)Returns a DTD with the specified name . If
a DTD with that name doesn't exist, one is created
and returned. Any uppercase characters in the name
are converted to lowercase.
name = name.toLowerCase();
DTD dtd = (DTD)dtdHash.get(name);
if (dtd == null)
dtd = new DTD(name);
return dtd;
| public javax.swing.text.html.parser.Element | getElement(java.lang.String name)Gets an element by name. A new element is
created if the element doesn't exist.
Element e = (Element)elementHash.get(name);
if (e == null) {
e = new Element(name, elements.size());
elements.addElement(e);
elementHash.put(name, e);
}
return e;
| public javax.swing.text.html.parser.Element | getElement(int index)Gets an element by index.
return (Element)elements.elementAt(index);
| public javax.swing.text.html.parser.Entity | getEntity(java.lang.String name)Gets an entity by name.
return (Entity)entityHash.get(name);
| public javax.swing.text.html.parser.Entity | getEntity(int ch)Gets a character entity.
return (Entity)entityHash.get(new Integer(ch));
| public java.lang.String | getName()Gets the name of the DTD.
return name;
| public static void | putDTDHash(java.lang.String name, javax.swing.text.html.parser.DTD dtd)
dtdHash.put(name, dtd);
| public void | read(java.io.DataInputStream in)Recreates a DTD from an archived format.
if (in.readInt() != FILE_VERSION) {
}
//
// Read the list of names
//
String[] names = new String[in.readShort()];
for (int i = 0; i < names.length; i++) {
names[i] = in.readUTF();
}
//
// Read the entities
//
int num = in.readShort();
for (int i = 0; i < num; i++) {
short nameId = in.readShort();
int type = in.readByte();
String name = in.readUTF();
defEntity(names[nameId], type | GENERAL, name);
}
// Read the elements
//
num = in.readShort();
for (int i = 0; i < num; i++) {
short nameId = in.readShort();
int type = in.readByte();
byte flags = in.readByte();
ContentModel m = readContentModel(in, names);
String[] exclusions = readNameArray(in, names);
String[] inclusions = readNameArray(in, names);
AttributeList atts = readAttributeList(in, names);
defElement(names[nameId], type,
((flags & 0x01) != 0), ((flags & 0x02) != 0),
m, exclusions, inclusions, atts);
}
| private javax.swing.text.html.parser.AttributeList | readAttributeList(java.io.DataInputStream in, java.lang.String[] names)
AttributeList result = null;
for (int num = in.readByte(); num > 0; --num) {
short nameId = in.readShort();
int type = in.readByte();
int modifier = in.readByte();
short valueId = in.readShort();
String value = (valueId == -1) ? null : names[valueId];
Vector values = null;
short numValues = in.readShort();
if (numValues > 0) {
values = new Vector(numValues);
for (int i = 0; i < numValues; i++) {
values.addElement(names[in.readShort()]);
}
}
result = new AttributeList(names[nameId], type, modifier, value,
values, result);
// We reverse the order of the linked list by doing this, but
// that order isn't important.
}
return result;
| private javax.swing.text.html.parser.ContentModel | readContentModel(java.io.DataInputStream in, java.lang.String[] names)
byte flag = in.readByte();
switch(flag) {
case 0: // null
return null;
case 1: { // content_c
int type = in.readByte();
ContentModel m = readContentModel(in, names);
ContentModel next = readContentModel(in, names);
return defContentModel(type, m, next);
}
case 2: { // content_e
int type = in.readByte();
Element el = getElement(names[in.readShort()]);
ContentModel next = readContentModel(in, names);
return defContentModel(type, el, next);
}
default:
throw new IOException("bad bdtd");
}
| private java.lang.String[] | readNameArray(java.io.DataInputStream in, java.lang.String[] names)
int num = in.readShort();
if (num == 0) {
return null;
}
String[] result = new String[num];
for (int i = 0; i < num; i++) {
result[i] = names[in.readShort()];
}
return result;
| public java.lang.String | toString()Returns a string representation of this DTD.
return name;
|
|