Method from javax.swing.text.html.parser.DTD Detail: |
protected AttributeList defAttributeList(String name,
int type,
int modifier,
String value,
String values,
AttributeList atts) {
Vector< String > vals = null;
if (values != null) {
vals = new Vector< String >();
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);
}
Creates and returns an AttributeList . |
protected ContentModel defContentModel(int type,
Object obj,
ContentModel next) {
return new ContentModel(type, obj, next);
}
Creates and returns a new content model. |
protected Element defElement(String name,
int type,
boolean omitStart,
boolean omitEnd,
ContentModel content,
String[] exclusions,
String[] inclusions,
AttributeList atts) {
BitSet excl = null;
if (exclusions != null && exclusions.length > 0) {
excl = new BitSet();
for (String str : exclusions) {
if (str.length() > 0) {
excl.set(getElement(str).getIndex());
}
}
}
BitSet incl = null;
if (inclusions != null && inclusions.length > 0) {
incl = new BitSet();
for (String str : inclusions) {
if (str.length() > 0) {
incl.set(getElement(str).getIndex());
}
}
}
return defineElement(name, type, omitStart, omitEnd, content, excl, incl, atts);
}
Creates and returns an Element . |
public Entity defEntity(String name,
int type,
int ch) {
char data[] = {(char)ch};
return defineEntity(name, type, data);
}
Creates and returns a character Entity . |
protected Entity defEntity(String name,
int type,
String str) {
int len = str.length();
char data[] = new char[len];
str.getChars(0, len, data, 0);
return defineEntity(name, type, data);
}
Creates and returns an Entity . |
public void defineAttributes(String name,
AttributeList atts) {
Element e = getElement(name);
e.atts = atts;
}
Defines attributes for an {@code Element}. |
public Element defineElement(String name,
int type,
boolean omitStart,
boolean omitEnd,
ContentModel content,
BitSet exclusions,
BitSet inclusions,
AttributeList atts) {
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;
}
Returns the Element which matches the
specified parameters. If one doesn't exist, a new
one is created and returned. |
public Entity defineEntity(String name,
int type,
char[] data) {
Entity ent = 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(Integer.valueOf(data[0]), ent);
break;
}
}
}
return ent;
}
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. |
boolean elementExists(String name) {
return !"unknown".equals(name) && (elementHash.get(name) != null);
}
Returns true if the element is part of the DTD,
otherwise returns false . |
public static DTD getDTD(String name) throws IOException {
name = name.toLowerCase();
DTD dtd = getDtdHash().get(name);
if (dtd == null)
dtd = new DTD(name);
return dtd;
}
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. |
public Element getElement(String name) {
Element e = elementHash.get(name);
if (e == null) {
e = new Element(name, elements.size());
elements.addElement(e);
elementHash.put(name, e);
}
return e;
}
Gets an element by name. A new element is
created if the element doesn't exist. |
public Element getElement(int index) {
return elements.elementAt(index);
}
Gets an element by index. |
public Entity getEntity(String name) {
return entityHash.get(name);
}
|
public Entity getEntity(int ch) {
return entityHash.get(Integer.valueOf(ch));
}
|
public String getName() {
return name;
}
Gets the name of the DTD. |
public static void putDTDHash(String name,
DTD dtd) {
getDtdHash().put(name, dtd);
}
|
public void read(DataInputStream in) throws IOException {
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);
}
}
Recreates a DTD from an archived format. |
public String toString() {
return name;
}
Returns a string representation of this DTD. |