KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > module > sitemesh > html > BasicRule


1 package com.opensymphony.module.sitemesh.html;
2
3 public abstract class BasicRule implements TagRule {
4
5     private final String JavaDoc[] acceptableTagNames;
6
7     protected HTMLProcessorContext context;
8
9     protected BasicRule(String JavaDoc[] acceptableTagNames) {
10         this.acceptableTagNames = acceptableTagNames;
11     }
12
13     protected BasicRule(String JavaDoc acceptableTagName) {
14         this.acceptableTagNames = new String JavaDoc[] {acceptableTagName};
15     }
16
17     protected BasicRule() {
18         this.acceptableTagNames = null;
19     }
20
21     public void setContext(HTMLProcessorContext context) {
22         this.context = context;
23     }
24
25     public boolean shouldProcess(String JavaDoc name) {
26         if (acceptableTagNames == null || acceptableTagNames.length < 1) {
27             throw new UnsupportedOperationException JavaDoc(getClass().getName()
28                     + " should be constructed with acceptableTagNames OR should implement shouldProcess()");
29         }
30
31         for (int i=0; i<acceptableTagNames.length; i++) {
32             if (name.toLowerCase().equals(acceptableTagNames[i])) return true;
33         }
34         return false;
35     }
36
37     public abstract void process(Tag tag);
38
39 }
40
Popular Tags