1 7 8 package javax.swing.text.html.parser; 9 10 import java.util.Vector ; 11 import java.util.Enumeration ; 12 import java.io.*; 13 14 15 26 public final class ContentModel implements Serializable { 27 30 public int type; 31 32 35 public Object content; 36 37 40 public ContentModel next; 41 42 public ContentModel() { 43 } 44 45 48 public ContentModel(Element content) { 49 this(0, content, null); 50 } 51 52 55 public ContentModel(int type, ContentModel content) { 56 this(type, content, null); 57 } 58 59 62 public ContentModel(int type, Object content, ContentModel next) { 63 this.type = type; 64 this.content = content; 65 this.next = next; 66 } 67 68 72 public boolean empty() { 73 switch (type) { 74 case '*': 75 case '?': 76 return true; 77 78 case '+': 79 case '|': 80 for (ContentModel m = (ContentModel )content ; m != null ; m = m.next) { 81 if (m.empty()) { 82 return true; 83 } 84 } 85 return false; 86 87 case ',': 88 case '&': 89 for (ContentModel m = (ContentModel )content ; m != null ; m = m.next) { 90 if (!m.empty()) { 91 return false; 92 } 93 } 94 return true; 95 96 default: 97 return false; 98 } 99 } 100 101 105 public void getElements(Vector <Element > elemVec) { 106 switch (type) { 107 case '*': 108 case '?': 109 case '+': 110 ((ContentModel )content).getElements(elemVec); 111 break; 112 case ',': 113 case '|': 114 case '&': 115 for (ContentModel m=(ContentModel )content; m != null; m=m.next){ 116 m.getElements(elemVec); 117 } 118 break; 119 default: 120 elemVec.addElement((Element )content); 121 } 122 } 123 124 private boolean valSet[]; 125 private boolean val[]; 126 130 134 public boolean first(Object token) { 135 switch (type) { 136 case '*': 137 case '?': 138 case '+': 139 return ((ContentModel )content).first(token); 140 141 case ',': 142 for (ContentModel m = (ContentModel )content ; m != null ; m = m.next) { 143 if (m.first(token)) { 144 return true; 145 } 146 if (!m.empty()) { 147 return false; 148 } 149 } 150 return false; 151 152 case '|': 153 case '&': { 154 Element e = (Element ) token; 155 if (valSet == null) { 156 valSet = new boolean[Element.maxIndex + 1]; 157 val = new boolean[Element.maxIndex + 1]; 158 } 160 if (valSet[e.index]) { 161 return val[e.index]; 162 } 163 for (ContentModel m = (ContentModel )content ; m != null ; m = m.next) { 164 if (m.first(token)) { 165 val[e.index] = true; 166 break; 167 } 168 } 169 valSet[e.index] = true; 170 return val[e.index]; 171 } 172 173 default: 174 return (content == token); 175 186 } 187 } 188 189 192 public Element first() { 193 switch (type) { 194 case '&': 195 case '|': 196 case '*': 197 case '?': 198 return null; 199 200 case '+': 201 case ',': 202 return ((ContentModel )content).first(); 203 204 default: 205 return (Element )content; 206 } 207 } 208 209 212 public String toString() { 213 switch (type) { 214 case '*': 215 return content + "*"; 216 case '?': 217 return content + "?"; 218 case '+': 219 return content + "+"; 220 221 case ',': 222 case '|': 223 case '&': 224 char data[] = {' ', (char)type, ' '}; 225 String str = ""; 226 for (ContentModel m = (ContentModel )content ; m != null ; m = m.next) { 227 str = str + m; 228 if (m.next != null) { 229 str += new String (data); 230 } 231 } 232 return "(" + str + ")"; 233 234 default: 235 return content.toString(); 236 } 237 } 238 } 239 | Popular Tags |