1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.module.templating.renderers;
35
36 import info.magnolia.cms.core.Content;
37 import info.magnolia.context.MgnlContext;
38 import info.magnolia.module.templating.AbstractRenderer;
39 import info.magnolia.module.templating.RenderException;
40 import info.magnolia.module.templating.TemplateRenderer;
41 import info.magnolia.module.templating.Template;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
44
45 import javax.servlet.ServletException;
46 import javax.servlet.http.HttpServletRequest;
47 import javax.servlet.http.HttpServletResponse;
48 import java.io.IOException;
49 import java.io.PrintWriter;
50 import java.io.Writer;
51
52
53
54
55
56
57
58
59 public abstract class AbstractTemplateRenderer extends AbstractRenderer implements TemplateRenderer {
60 private static final Logger log = LoggerFactory.getLogger(AbstractTemplateRenderer.class);
61
62
63
64
65 public void renderTemplate(Template template, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
66 final Content content = MgnlContext.getAggregationState().getMainContent();
67 final PrintWriter out = response.getWriter();
68 try {
69 renderTemplate(content, template, out);
70 } catch (RenderException e) {
71 throw new ServletException(e);
72 }
73 }
74
75 public void renderTemplate(Content content, Template template, Writer out) throws RenderException, IOException {
76 try {
77 render(content, template, out);
78 } finally{
79 out.flush();
80 }
81 }
82 }