01: package com.opensymphony.module.sitemesh.multipass;
02:
03: import com.opensymphony.module.sitemesh.PageParser;
04: import com.opensymphony.module.sitemesh.Page;
05: import com.opensymphony.module.sitemesh.html.util.CharArray;
06: import com.opensymphony.module.sitemesh.html.HTMLProcessor;
07: import com.opensymphony.module.sitemesh.html.BasicRule;
08: import com.opensymphony.module.sitemesh.html.Tag;
09:
10: import javax.servlet.http.HttpServletResponse;
11: import java.io.IOException;
12:
13: public class MultipassReplacementPageParser implements PageParser {
14: private final Page page;
15: private final HttpServletResponse response;
16:
17: public MultipassReplacementPageParser(Page page,
18: HttpServletResponse response) {
19: this .page = page;
20: this .response = response;
21: }
22:
23: public Page parse(char[] data) throws IOException {
24: final CharArray result = new CharArray(4096);
25: HTMLProcessor processor = new HTMLProcessor(data, result);
26: processor.addRule(new BasicRule("sitemesh:multipass") {
27: public void process(Tag tag) {
28: String id = tag.getAttributeValue("id", true);
29: if (!page.isPropertySet("_sitemesh.removefrompage."
30: + id)) {
31: currentBuffer().append(page.getProperty(id));
32: }
33: }
34: });
35: processor.process();
36:
37: result.writeTo(response.getWriter());
38: return null;
39: }
40: }
|