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 freemarker.template.TemplateException; |
37 |
|
import info.magnolia.module.templating.RenderableDefinition; |
38 |
|
import info.magnolia.cms.core.Content; |
39 |
|
import info.magnolia.context.MgnlContext; |
40 |
|
import info.magnolia.freemarker.FreemarkerHelper; |
41 |
|
import info.magnolia.module.templating.RenderException; |
42 |
|
|
43 |
|
import java.io.Writer; |
44 |
|
import java.util.HashMap; |
45 |
|
import java.util.Locale; |
46 |
|
import java.util.Map; |
47 |
|
|
48 |
|
import org.apache.commons.lang.exception.ExceptionUtils; |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
@version |
53 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 6 |
Complexity Density: 0.86 |
|
54 |
|
public class FreemarkerTemplateRenderer extends AbstractTemplateRenderer { |
55 |
|
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(FreemarkerTemplateRenderer.class); |
56 |
|
|
57 |
|
private final FreemarkerHelper fmHelper; |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
63 |
0
|
public FreemarkerTemplateRenderer() {... |
64 |
0
|
this(FreemarkerHelper.getInstance()); |
65 |
|
} |
66 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
0
|
FreemarkerTemplateRenderer(FreemarkerHelper fmRenderer) {... |
68 |
0
|
this.fmHelper = fmRenderer; |
69 |
|
} |
70 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 3 |
Complexity Density: 0.75 |
|
71 |
0
|
protected void onRender(Content content, RenderableDefinition definition, Writer out, Map ctx, String templatePath) throws RenderException {... |
72 |
0
|
final Locale locale = MgnlContext.getAggregationState().getLocale(); |
73 |
|
|
74 |
0
|
try { |
75 |
0
|
fmHelper.render(templatePath, locale, definition.getI18nBasename(), ctx, out); |
76 |
|
} |
77 |
|
catch (TemplateException e) { |
78 |
|
|
79 |
|
} |
80 |
|
catch (Exception e) { |
81 |
|
|
82 |
0
|
throw new RenderException("Can't render template " + templatePath + ": " + ExceptionUtils.getRootCauseMessage(e), e); |
83 |
|
} |
84 |
|
} |
85 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
86 |
0
|
protected Map newContext() {... |
87 |
0
|
return new HashMap(); |
88 |
|
} |
89 |
|
} |