01: package com.opensymphony.module.sitemesh.html.rules;
02:
03: import com.opensymphony.module.sitemesh.html.BasicRule;
04: import com.opensymphony.module.sitemesh.html.Tag;
05: import com.opensymphony.module.sitemesh.html.CustomTag;
06:
07: /**
08: * Very simple rule for replacing all occurences of one tag with another.
09: *
10: * <p>For example, to convert all <b> tags to <strong>:</p>
11: * <p>html.addRule(new TagReplaceRule("b", "strong"));</p>
12: *
13: * @author Joe Walnes
14: */
15: public class TagReplaceRule extends BasicRule {
16:
17: private final String newTagName;
18:
19: public TagReplaceRule(String originalTagName, String newTagName) {
20: super (originalTagName);
21: this .newTagName = newTagName;
22: }
23:
24: public void process(Tag tag) {
25: CustomTag customTag = new CustomTag(tag);
26: customTag.setName(newTagName);
27: customTag.writeTo(currentBuffer());
28: }
29: }
|