| 1 | |
package org.webslinger.macros; |
| 2 | |
|
| 3 | |
import java.io.IOException; |
| 4 | |
import java.io.Writer; |
| 5 | |
import java.util.Map; |
| 6 | |
import javax.servlet.ServletException; |
| 7 | |
|
| 8 | |
import org.apache.bsf.BSFException; |
| 9 | |
|
| 10 | |
import org.webslinger.PathContext; |
| 11 | |
import org.webslinger.Webslinger; |
| 12 | |
import org.webslinger.WebslingerInvoker.AlterPlan; |
| 13 | |
import org.webslinger.WebslingerInvoker.Plan; |
| 14 | |
import org.webslinger.template.TemplateMacro; |
| 15 | |
import org.webslinger.template.TemplateManager; |
| 16 | |
|
| 17 | |
public class MergeMacro extends AbstractSimpleMacro { |
| 18 | |
protected MergeMacro(String name, boolean withTemplate, boolean isBlock) { |
| 19 | 100 | super(name, withTemplate, isBlock); |
| 20 | 100 | } |
| 21 | |
|
| 22 | |
protected boolean render(TemplateManager manager, Webslinger parent, Writer writer, Args args, Map<String, Object> context, Body body) throws IOException, BSFException { |
| 23 | 67 | PathContext pc = parent.resolvePath(args.get("name", 0)); |
| 24 | |
|
| 25 | 67 | parent.getResponse().flushBuffer(); |
| 26 | 67 | final PathContext[] templates = getTemplates(parent, args, 1); |
| 27 | 67 | parent.getInvoker().getPlan().merge(parent, pc, context, writer, new AlterPlan() { |
| 28 | |
protected void alterPlan(Plan plan) throws IOException, ServletException { |
| 29 | 67 | plan.addTemplates(templates); |
| 30 | 67 | } |
| 31 | |
}); |
| 32 | 67 | return true; |
| 33 | |
} |
| 34 | |
} |
| 35 | |
|