ContentModelpublic final class ContentModel extends Object implements SerializableA representation of a content model. A content model is
basically a restricted BNF expression. It is restricted in
the sense that it must be deterministic. This means that you
don't have to represent it as a finite state automata.
See Annex H on page 556 of the SGML handbook for more information. |
Fields Summary |
---|
public int | typeType. Either '*', '?', '+', ',', '|', '&'. | public Object | contentThe content. Either an Element or a ContentModel. | public ContentModel | nextThe next content model (in a ',', '|' or '&' expression). | private boolean[] | valSet | private boolean[] | val |
Constructors Summary |
---|
public ContentModel()
| public ContentModel(Element content)Create a content model for an element.
this(0, content, null);
| public ContentModel(int type, ContentModel content)Create a content model of a particular type.
this(type, content, null);
| public ContentModel(int type, Object content, ContentModel next)Create a content model of a particular type.
this.type = type;
this.content = content;
this.next = next;
|
Methods Summary |
---|
public boolean | empty()Return true if the content model could
match an empty input stream.
switch (type) {
case '*":
case '?":
return true;
case '+":
case '|":
for (ContentModel m = (ContentModel)content ; m != null ; m = m.next) {
if (m.empty()) {
return true;
}
}
return false;
case ',":
case '&":
for (ContentModel m = (ContentModel)content ; m != null ; m = m.next) {
if (!m.empty()) {
return false;
}
}
return true;
default:
return false;
}
| public boolean | first(java.lang.Object token)Return true if the token could potentially be the
first token in the input stream.
switch (type) {
case '*":
case '?":
case '+":
return ((ContentModel)content).first(token);
case ',":
for (ContentModel m = (ContentModel)content ; m != null ; m = m.next) {
if (m.first(token)) {
return true;
}
if (!m.empty()) {
return false;
}
}
return false;
case '|":
case '&": {
Element e = (Element) token;
if (valSet == null) {
valSet = new boolean[Element.maxIndex + 1];
val = new boolean[Element.maxIndex + 1];
// All Element instances are created before this ever executes
}
if (valSet[e.index]) {
return val[e.index];
}
for (ContentModel m = (ContentModel)content ; m != null ; m = m.next) {
if (m.first(token)) {
val[e.index] = true;
break;
}
}
valSet[e.index] = true;
return val[e.index];
}
default:
return (content == token);
// PENDING: refer to comment in ContentModelState
/*
if (content == token) {
return true;
}
Element e = (Element)content;
if (e.omitStart() && e.content != null) {
return e.content.first(token);
}
return false;
*/
}
| public javax.swing.text.html.parser.Element | first()Return the element that must be next.
switch (type) {
case '&":
case '|":
case '*":
case '?":
return null;
case '+":
case ',":
return ((ContentModel)content).first();
default:
return (Element)content;
}
| public void | getElements(java.util.Vector elemVec)Update elemVec with the list of elements that are
part of the this contentModel.
switch (type) {
case '*":
case '?":
case '+":
((ContentModel)content).getElements(elemVec);
break;
case ',":
case '|":
case '&":
for (ContentModel m=(ContentModel)content; m != null; m=m.next){
m.getElements(elemVec);
}
break;
default:
elemVec.addElement((Element)content);
}
| public java.lang.String | toString()Convert to a string.
switch (type) {
case '*":
return content + "*";
case '?":
return content + "?";
case '+":
return content + "+";
case ',":
case '|":
case '&":
char data[] = {' ", (char)type, ' "};
String str = "";
for (ContentModel m = (ContentModel)content ; m != null ; m = m.next) {
str = str + m;
if (m.next != null) {
str += new String(data);
}
}
return "(" + str + ")";
default:
return content.toString();
}
|
|