01: package com.opensymphony.module.sitemesh.html.tokenizer;
02:
03: import com.opensymphony.module.sitemesh.html.Tag;
04: import com.opensymphony.module.sitemesh.html.Text;
05:
06: /**
07: * Handler passed to {@link TagTokenizer} that will receive callbacks as 'tags' and 'text' are encountered.
08: *
09: * @author Joe Walnes
10: * @see TagTokenizer
11: */
12: public interface TokenHandler {
13:
14: /**
15: * Before attempting to parse a tag, the tokenizer will ask the handler whether the tag should be processed - avoiding
16: * additional tag parsing makes the tokenizer quicker.
17: * <p/>
18: * If true is returned, the tokenizer will fully parse the tag and pass it into the {@link #tag(com.opensymphony.module.sitemesh.html.Tag)} method.
19: * If false is returned, the tokenizer will not try to parse the tag and pass it to the #{@link #text(com.opensymphony.module.sitemesh.html.Text)} method,
20: * untouched.
21: */
22: boolean shouldProcessTag(String name);
23:
24: /**
25: * Called when tokenizer encounters an HTML tag (open, close or empty).
26: *
27: * The Tag instance passed in should not be kept beyond the scope of this method as the tokenizer will attempt
28: * to reuse it.
29: */
30: void tag(Tag tag);
31:
32: /**
33: * Called when tokenizer encounters anything other than a well-formed HTML tag.
34: *
35: * The Text object is used instead of a String to allow the String to be lazy-loaded.
36: *
37: * The Text instance passed in should not be kept beyond the scope of this method as the tokenizer will attempt
38: * to reuse it.
39: */
40: void text(Text text);
41:
42: /**
43: * Called when tokenizer encounters something it cannot correctly parse. Typically the parsing will continue and the
44: * unparseable will be treated as a plain text block, however this callback provides indication of this.
45: *
46: * @param message Error message
47: * @param line Line number in input that error occured
48: * @param column Column number in input that error occured
49: */
50: void warning(String message, int line, int column);
51:
52: }
|