1 7 8 package javax.swing.text.html.parser; 9 10 import java.util.BitSet ; 11 import java.util.Vector ; 12 import java.io.*; 13 14 15 29 final 30 class TagStack implements DTDConstants { 31 TagElement tag; 32 Element elem; 33 ContentModelState state; 34 TagStack next; 35 BitSet inclusions; 36 BitSet exclusions; 37 boolean net; 38 boolean pre; 39 40 43 TagStack(TagElement tag, TagStack next) { 44 this.tag = tag; 45 this.elem = tag.getElement(); 46 this.next = next; 47 48 Element elem = tag.getElement(); 49 if (elem.getContent() != null) { 50 this.state = new ContentModelState (elem.getContent()); 51 } 52 53 if (next != null) { 54 inclusions = next.inclusions; 55 exclusions = next.exclusions; 56 pre = next.pre; 57 } 58 if (tag.isPreformatted()) { 59 pre = true; 60 } 61 62 if (elem.inclusions != null) { 63 if (inclusions != null) { 64 inclusions = (BitSet )inclusions.clone(); 65 inclusions.or(elem.inclusions); 66 } else { 67 inclusions = elem.inclusions; 68 } 69 } 70 if (elem.exclusions != null) { 71 if (exclusions != null) { 72 exclusions = (BitSet )exclusions.clone(); 73 exclusions.or(elem.exclusions); 74 } else { 75 exclusions = elem.exclusions; 76 } 77 } 78 } 79 80 84 public Element first() { 85 return (state != null) ? state.first() : null; 86 } 87 88 92 public ContentModel contentModel() { 93 if (state == null) { 94 return null; 95 } else { 96 return state.getModel(); 97 } 98 } 99 100 106 boolean excluded(int elemIndex) { 107 return (exclusions != null) && exclusions.get(elem.getIndex()); 108 } 109 110 115 boolean included(Vector elemVec, DTD dtd) { 116 117 for (int i = 0 ; i < inclusions.size(); i++) { 118 if (inclusions.get(i)) { 119 elemVec.addElement(dtd.getElement(i)); 120 System.out.println("Element add thru' inclusions: " + dtd.getElement(i).getName()); 121 } 122 } 123 return (!elemVec.isEmpty()); 124 } 125 126 127 132 boolean advance(Element elem) { 133 if ((exclusions != null) && exclusions.get(elem.getIndex())) { 134 return false; 135 } 136 if (state != null) { 137 ContentModelState newState = state.advance(elem); 138 if (newState != null) { 139 state = newState; 140 return true; 141 } 142 } else if (this.elem.getType() == ANY) { 143 return true; 144 } 145 return (inclusions != null) && inclusions.get(elem.getIndex()); 146 } 147 148 151 boolean terminate() { 152 return (state == null) || state.terminate(); 153 } 154 155 158 public String toString() { 159 return (next == null) ? 160 "<" + tag.getElement().getName() + ">" : 161 next + " <" + tag.getElement().getName() + ">"; 162 } 163 } 164 165 class NPrintWriter extends PrintWriter { 166 167 private int numLines = 5; 168 private int numPrinted = 0; 169 170 public NPrintWriter (int numberOfLines) { 171 super(System.out); 172 numLines = numberOfLines; 173 } 174 175 public void println(char[] array) { 176 if (numPrinted >= numLines) { 177 return; 178 } 179 180 char[] partialArray = null; 181 182 for (int i = 0; i < array.length; i++) { 183 if (array[i] == '\n') { 184 numPrinted++; 185 } 186 187 if (numPrinted == numLines) { 188 System.arraycopy(array, 0, partialArray, 0, i); 189 } 190 } 191 192 if (partialArray != null) { 193 super.print(partialArray); 194 } 195 196 if (numPrinted == numLines) { 197 return; 198 } 199 200 super.println(array); 201 numPrinted++; 202 } 203 } 204 205 206 | Popular Tags |