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.module.templating.RenderableDefinition;
37 import info.magnolia.cms.core.Content;
38 import info.magnolia.cms.util.NodeMapWrapper;
39 import info.magnolia.context.MgnlContext;
40 import info.magnolia.context.WebContext;
41 import info.magnolia.module.templating.RenderException;
42
43 import javax.servlet.http.HttpServletRequest;
44 import javax.servlet.http.HttpServletResponse;
45
46 import java.io.Writer;
47 import java.util.Map;
48
49
50
51
52
53
54
55
56 public class JspTemplateRenderer extends AbstractTemplateRenderer {
57
58 private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(JspTemplateRenderer.class);
59
60 protected void onRender(Content content, RenderableDefinition definition, Writer out, Map ctx, String templatePath) throws RenderException {
61 HttpServletRequest request = ((WebContext) MgnlContext.getInstance()).getRequest();
62 HttpServletResponse response = ((WebContext) MgnlContext.getInstance()).getResponse();
63 if (response.isCommitted()) {
64 log.warn("Attempting to forward to {}, but response is already committed.", templatePath);
65 }
66
67
68 try {
69 request.getRequestDispatcher(templatePath).forward(request, response);
70 }
71 catch (Exception e) {
72 throw new RenderException("Can't render template " + templatePath, e);
73 }
74 }
75
76
77
78
79 protected Content wrapNodeForTemplate(Content currentContent, Content mainContent) {
80 final Content wrapped = super.wrapNodeForTemplate(currentContent, mainContent);
81 return new NodeMapWrapper(wrapped, mainContent.getHandle());
82 }
83
84 protected Map newContext() {
85 return MgnlContext.getWebContext("JspTemplateRenderer can only be used with a WebContext");
86 }
87
88 protected String getPageAttributeName() {
89 return "actpage";
90 }
91
92
93 }