01: package com.opensymphony.module.sitemesh.html;
02:
03: import com.opensymphony.module.sitemesh.html.util.CharArray;
04:
05: public abstract class BasicRule implements TagRule {
06:
07: private final String[] acceptableTagNames;
08:
09: protected HTMLProcessorContext context;
10:
11: protected BasicRule(String[] acceptableTagNames) {
12: this .acceptableTagNames = acceptableTagNames;
13: }
14:
15: protected BasicRule(String acceptableTagName) {
16: this .acceptableTagNames = new String[] { acceptableTagName };
17: }
18:
19: protected BasicRule() {
20: this .acceptableTagNames = null;
21: }
22:
23: public void setContext(HTMLProcessorContext context) {
24: this .context = context;
25: }
26:
27: public boolean shouldProcess(String name) {
28: if (acceptableTagNames == null || acceptableTagNames.length < 1) {
29: throw new UnsupportedOperationException(
30: getClass().getName()
31: + " should be constructed with acceptableTagNames OR should implement shouldProcess()");
32: }
33:
34: for (int i = 0; i < acceptableTagNames.length; i++) {
35: if (name.equals(acceptableTagNames[i]))
36: return true;
37: }
38: return false;
39: }
40:
41: public abstract void process(Tag tag);
42:
43: protected CharArray currentBuffer() {
44: return context.currentBuffer();
45: }
46:
47: }
|