214 * Returns the start position of the current block. Block is |
214 * Returns the start position of the current block. Block is |
215 * overloaded here, it really means the current start position for |
215 * overloaded here, it really means the current start position for |
216 * the current comment tag, text, block.... This is provided for |
216 * the current comment tag, text, block.... This is provided for |
217 * subclassers that wish to know the start of the current block when |
217 * subclassers that wish to know the start of the current block when |
218 * called with one of the handleXXX methods. |
218 * called with one of the handleXXX methods. |
|
219 * |
|
220 * @return the start position of the current block |
219 */ |
221 */ |
220 int getBlockStartPosition() { |
222 int getBlockStartPosition() { |
221 return Math.max(0, lastBlockStartPos - 1); |
223 return Math.max(0, lastBlockStartPos - 1); |
222 } |
224 } |
223 |
225 |
224 /** |
226 /** |
225 * Makes a TagElement. |
227 * Makes a TagElement. |
|
228 * |
|
229 * @param elem the element storing the tag definition |
|
230 * @param fictional the value of the flag "{@code fictional}" to be set for the tag |
|
231 * |
|
232 * @return the created {@code TagElement} |
226 */ |
233 */ |
227 protected TagElement makeTag(Element elem, boolean fictional) { |
234 protected TagElement makeTag(Element elem, boolean fictional) { |
228 return new TagElement(elem, fictional); |
235 return new TagElement(elem, fictional); |
229 } |
236 } |
230 |
237 |
|
238 /** |
|
239 * Makes a TagElement. |
|
240 * |
|
241 * @param elem the element storing the tag definition |
|
242 * |
|
243 * @return the created {@code TagElement} |
|
244 */ |
231 protected TagElement makeTag(Element elem) { |
245 protected TagElement makeTag(Element elem) { |
232 return makeTag(elem, false); |
246 return makeTag(elem, false); |
233 } |
247 } |
234 |
248 |
|
249 /** |
|
250 * Returns attributes for the current tag. |
|
251 * |
|
252 * @return {@code SimpleAttributeSet} containing the attributes |
|
253 */ |
235 protected SimpleAttributeSet getAttributes() { |
254 protected SimpleAttributeSet getAttributes() { |
236 return attributes; |
255 return attributes; |
237 } |
256 } |
238 |
257 |
|
258 /** |
|
259 * Removes the current attributes. |
|
260 */ |
239 protected void flushAttributes() { |
261 protected void flushAttributes() { |
240 attributes.removeAttributes(attributes); |
262 attributes.removeAttributes(attributes); |
241 } |
263 } |
242 |
264 |
243 /** |
265 /** |
244 * Called when PCDATA is encountered. |
266 * Called when PCDATA is encountered. |
|
267 * |
|
268 * @param text the section text |
245 */ |
269 */ |
246 protected void handleText(char text[]) { |
270 protected void handleText(char text[]) { |
247 } |
271 } |
248 |
272 |
249 /** |
273 /** |
250 * Called when an HTML title tag is encountered. |
274 * Called when an HTML title tag is encountered. |
|
275 * |
|
276 * @param text the title text |
251 */ |
277 */ |
252 protected void handleTitle(char text[]) { |
278 protected void handleTitle(char text[]) { |
253 // default behavior is to call handleText. Subclasses |
279 // default behavior is to call handleText. Subclasses |
254 // can override if necessary. |
280 // can override if necessary. |
255 handleText(text); |
281 handleText(text); |
256 } |
282 } |
257 |
283 |
258 /** |
284 /** |
259 * Called when an HTML comment is encountered. |
285 * Called when an HTML comment is encountered. |
|
286 * |
|
287 * @param text the comment being handled |
260 */ |
288 */ |
261 protected void handleComment(char text[]) { |
289 protected void handleComment(char text[]) { |
262 } |
290 } |
263 |
291 |
|
292 /** |
|
293 * Called when the content terminates without closing the HTML comment. |
|
294 */ |
264 protected void handleEOFInComment() { |
295 protected void handleEOFInComment() { |
265 // We've reached EOF. Our recovery strategy is to |
296 // We've reached EOF. Our recovery strategy is to |
266 // see if we have more than one line in the comment; |
297 // see if we have more than one line in the comment; |
267 // if so, we pretend that the comment was an unterminated |
298 // if so, we pretend that the comment was an unterminated |
268 // single line comment, and reparse the lines after the |
299 // single line comment, and reparse the lines after the |
286 } |
317 } |
287 } |
318 } |
288 |
319 |
289 /** |
320 /** |
290 * Called when an empty tag is encountered. |
321 * Called when an empty tag is encountered. |
|
322 * |
|
323 * @param tag the tag being handled |
|
324 * @throws ChangedCharSetException if the document charset was changed |
291 */ |
325 */ |
292 protected void handleEmptyTag(TagElement tag) throws ChangedCharSetException { |
326 protected void handleEmptyTag(TagElement tag) throws ChangedCharSetException { |
293 } |
327 } |
294 |
328 |
295 /** |
329 /** |
296 * Called when a start tag is encountered. |
330 * Called when a start tag is encountered. |
|
331 * |
|
332 * @param tag the tag being handled |
297 */ |
333 */ |
298 protected void handleStartTag(TagElement tag) { |
334 protected void handleStartTag(TagElement tag) { |
299 } |
335 } |
300 |
336 |
301 /** |
337 /** |
302 * Called when an end tag is encountered. |
338 * Called when an end tag is encountered. |
|
339 * |
|
340 * @param tag the tag being handled |
303 */ |
341 */ |
304 protected void handleEndTag(TagElement tag) { |
342 protected void handleEndTag(TagElement tag) { |
305 } |
343 } |
306 |
344 |
307 /** |
345 /** |
308 * An error has occurred. |
346 * An error has occurred. |
|
347 * |
|
348 * @param ln the number of line containing the error |
|
349 * @param msg the error message |
309 */ |
350 */ |
310 protected void handleError(int ln, String msg) { |
351 protected void handleError(int ln, String msg) { |
311 /* |
352 /* |
312 Thread.dumpStack(); |
353 Thread.dumpStack(); |
313 System.out.println("**** " + stack); |
354 System.out.println("**** " + stack); |
1525 |
1582 |
1526 /** |
1583 /** |
1527 * Parse markup declarations. |
1584 * Parse markup declarations. |
1528 * Currently only handles the Document Type Declaration markup. |
1585 * Currently only handles the Document Type Declaration markup. |
1529 * Returns true if it is a markup declaration false otherwise. |
1586 * Returns true if it is a markup declaration false otherwise. |
|
1587 * |
|
1588 * @param strBuff the markup declaration |
|
1589 * @return {@code true} if this is a valid markup declaration; |
|
1590 * otherwise {@code false} |
|
1591 * @throws IOException if an I/O error occurs |
1530 */ |
1592 */ |
1531 protected boolean parseMarkupDeclarations(StringBuffer strBuff) throws IOException { |
1593 protected boolean parseMarkupDeclarations(StringBuffer strBuff) throws IOException { |
1532 |
1594 |
1533 /* Currently handles only the DOCTYPE */ |
1595 /* Currently handles only the DOCTYPE */ |
1534 if ((strBuff.length() == "DOCTYPE".length()) && |
1596 if ((strBuff.length() == "DOCTYPE".length()) && |