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.Template; |
39 |
|
import info.magnolia.module.templating.RenderableDefinition; |
40 |
|
import info.magnolia.module.templating.RenderException; |
41 |
|
import info.magnolia.objectfactory.Classes; |
42 |
|
import info.magnolia.objectfactory.MgnlInstantiationException; |
43 |
|
import org.apache.commons.lang.StringUtils; |
44 |
|
|
45 |
|
import javax.servlet.ServletException; |
46 |
|
import javax.servlet.http.HttpServlet; |
47 |
|
import javax.servlet.http.HttpServletRequest; |
48 |
|
import javax.servlet.http.HttpServletResponse; |
49 |
|
import java.io.IOException; |
50 |
|
import java.io.Writer; |
51 |
|
import java.util.Map; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
@author |
67 |
|
@version |
68 |
|
|
|
|
| 6.9% |
Uncovered Elements: 27 (29) |
Complexity: 10 |
Complexity Density: 0.5 |
|
69 |
|
public class ServletTemplateRenderer extends AbstractTemplateRenderer { |
70 |
|
private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ServletTemplateRenderer.class); |
71 |
|
|
|
|
| 4.2% |
Uncovered Elements: 23 (24) |
Complexity: 8 |
Complexity Density: 0.44 |
|
72 |
1
|
public void renderTemplate(Content content, Template template, Writer out) throws IOException, RenderException {... |
73 |
1
|
final HttpServletRequest request = MgnlContext.getWebContext("ServletTemplateRenderer can only be used with a WebContext").getRequest(); |
74 |
0
|
final HttpServletResponse response = MgnlContext.getWebContext("ServletTemplateRenderer can only be used with a WebContext").getResponse(); |
75 |
0
|
final String className = template.getParameter("className"); |
76 |
|
|
77 |
0
|
if (StringUtils.isEmpty(className)) { |
78 |
|
|
79 |
0
|
final String path = template.getTemplatePath(); |
80 |
0
|
if (StringUtils.isEmpty(path)) { |
81 |
0
|
throw new IllegalStateException("path or className is missing for servlet template " + template.getName() + ", returning a 404 error"); |
82 |
|
} |
83 |
|
|
84 |
0
|
if (response.isCommitted()) { |
85 |
0
|
log.warn("Forwarding to {} for request {}, but response is already committed.", path, request.getRequestURL()); |
86 |
|
} |
87 |
|
|
88 |
|
|
89 |
0
|
try { |
90 |
0
|
request.getRequestDispatcher(path).forward(request, response); |
91 |
|
} catch (ServletException e) { |
92 |
0
|
throw new RenderException(e); |
93 |
|
} |
94 |
|
} else { |
95 |
|
|
96 |
0
|
try { |
97 |
0
|
final HttpServlet servlet = Classes.newInstance(className); |
98 |
0
|
servlet.service(request, response); |
99 |
|
} catch (ServletException e) { |
100 |
0
|
throw new RenderException(e); |
101 |
|
} catch (MgnlInstantiationException e) { |
102 |
0
|
throw new RenderException(e); |
103 |
|
} catch (ClassNotFoundException e) { |
104 |
0
|
throw new RenderException(e); |
105 |
|
} |
106 |
|
} |
107 |
|
} |
108 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
109 |
0
|
protected Map newContext() {... |
110 |
0
|
throw new IllegalStateException(); |
111 |
|
} |
112 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
113 |
0
|
protected void onRender(Content content, RenderableDefinition definition, Writer out, Map ctx, String templatePath) throws RenderException {... |
114 |
0
|
throw new IllegalStateException(); |
115 |
|
} |
116 |
|
|
117 |
|
} |