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.paragraphs; |
35 |
|
|
36 |
|
import freemarker.template.TemplateException; |
37 |
|
import info.magnolia.module.templating.RenderableDefinition; |
38 |
|
import info.magnolia.module.templating.RenderingModel; |
39 |
|
import info.magnolia.cms.core.Content; |
40 |
|
import info.magnolia.context.MgnlContext; |
41 |
|
import info.magnolia.freemarker.FreemarkerHelper; |
42 |
|
import info.magnolia.module.templating.RenderException; |
43 |
|
import org.apache.commons.lang.exception.ExceptionUtils; |
44 |
|
import org.slf4j.Logger; |
45 |
|
import org.slf4j.LoggerFactory; |
46 |
|
|
47 |
|
import javax.servlet.jsp.JspWriter; |
48 |
|
import java.io.IOException; |
49 |
|
import java.io.PrintWriter; |
50 |
|
import java.io.Writer; |
51 |
|
import java.util.HashMap; |
52 |
|
import java.util.Locale; |
53 |
|
import java.util.Map; |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
@author |
61 |
|
@version |
62 |
|
|
|
|
| 72.7% |
Uncovered Elements: 9 (33) |
Complexity: 12 |
Complexity Density: 0.57 |
|
63 |
|
public class FreemarkerParagraphRenderer extends AbstractParagraphRenderer { |
64 |
|
|
65 |
|
private static Logger log = LoggerFactory.getLogger(FreemarkerParagraphRenderer.class); |
66 |
|
|
67 |
|
private final FreemarkerHelper fmHelper; |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
73 |
1
|
public FreemarkerParagraphRenderer() {... |
74 |
1
|
this(FreemarkerHelper.getInstance()); |
75 |
|
} |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
6
|
FreemarkerParagraphRenderer(FreemarkerHelper fmRenderer) {... |
78 |
6
|
this.fmHelper = fmRenderer; |
79 |
|
} |
80 |
|
|
|
|
| 52.6% |
Uncovered Elements: 9 (19) |
Complexity: 7 |
Complexity Density: 0.54 |
|
81 |
3
|
protected void onRender(Content content, RenderableDefinition definition, Writer out, final Map ctx, String templatePath) throws RenderException {... |
82 |
3
|
final Locale locale = MgnlContext.getAggregationState().getLocale(); |
83 |
|
|
84 |
3
|
boolean wrap = false; |
85 |
3
|
try { |
86 |
3
|
if (out instanceof JspWriter) { |
87 |
|
|
88 |
0
|
wrap = true; |
89 |
0
|
out = new PrintWriter(out); |
90 |
|
} |
91 |
3
|
log.debug ("About to call FM renderer with {}wrapped writer: {}", wrap? "" : "un", out ); |
92 |
3
|
fmHelper.render(templatePath, locale, definition.getI18nBasename(), ctx, out); |
93 |
|
|
94 |
|
|
95 |
|
} catch (TemplateException e) { |
96 |
|
|
97 |
|
|
98 |
|
}catch (Exception e) { |
99 |
0
|
throw new RenderException("Can't render paragraph template " + templatePath + ": " + ExceptionUtils.getRootCauseMessage(e), e); |
100 |
|
} finally { |
101 |
3
|
if (wrap) { |
102 |
0
|
try { |
103 |
0
|
out.flush(); |
104 |
|
} catch (IOException e) { |
105 |
|
|
106 |
0
|
e.printStackTrace(); |
107 |
|
} |
108 |
|
} |
109 |
|
} |
110 |
|
} |
111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
112 |
3
|
protected Map saveContextState(Map ctx) {... |
113 |
3
|
Map state = super.saveContextState(ctx); |
114 |
3
|
saveAttribute(ctx, state, "params"); |
115 |
3
|
return state; |
116 |
|
} |
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
118 |
3
|
protected void setupContext(Map ctx, Content content, RenderableDefinition definition, RenderingModel state, Object actionResult) {... |
119 |
3
|
super.setupContext(ctx, content, definition, state, actionResult); |
120 |
3
|
setContextAttribute(ctx, "params", MgnlContext.getParameters()); |
121 |
|
} |
122 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
123 |
3
|
protected Map newContext() {... |
124 |
3
|
return new HashMap(); |
125 |
|
} |
126 |
|
|
127 |
|
} |