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.blossom.view; |
35 |
|
|
36 |
|
import java.util.Map; |
37 |
|
import javax.jcr.Node; |
38 |
|
import javax.servlet.http.HttpServletRequest; |
39 |
|
|
40 |
|
import info.magnolia.context.MgnlContext; |
41 |
|
import info.magnolia.module.blossom.render.RenderContext; |
42 |
|
import info.magnolia.rendering.context.RenderingContext; |
43 |
|
import info.magnolia.rendering.engine.RenderException; |
44 |
|
import info.magnolia.rendering.model.RenderingModel; |
45 |
|
import info.magnolia.rendering.renderer.ContextAttributeConfiguration; |
46 |
|
import info.magnolia.rendering.renderer.FreemarkerRenderer; |
47 |
|
import info.magnolia.rendering.template.RenderableDefinition; |
48 |
|
|
49 |
|
import org.springframework.web.servlet.support.RequestContext; |
50 |
|
import org.springframework.web.servlet.view.AbstractTemplateView; |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
@since |
56 |
|
|
|
|
| 0% |
Uncovered Elements: 32 (32) |
Complexity: 8 |
Complexity Density: 0.4 |
|
57 |
|
public class FreemarkerTemplateViewRenderer extends FreemarkerRenderer { |
58 |
|
|
59 |
|
private boolean exposeModelAsRequestAttributes = true; |
60 |
|
private boolean exposeSpringMacroHelpers = true; |
61 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
62 |
|
public boolean isExposeModelAsRequestAttributes() {... |
63 |
|
return exposeModelAsRequestAttributes; |
64 |
|
} |
65 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
66 |
|
public void setExposeModelAsRequestAttributes(boolean exposeModelAsRequestAttributes) {... |
67 |
|
this.exposeModelAsRequestAttributes = exposeModelAsRequestAttributes; |
68 |
|
} |
69 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
70 |
|
public boolean isExposeSpringMacroHelpers() {... |
71 |
|
return exposeSpringMacroHelpers; |
72 |
|
} |
73 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
74 |
|
public void setExposeSpringMacroHelpers(boolean exposeSpringMacroHelpers) {... |
75 |
|
this.exposeSpringMacroHelpers = exposeSpringMacroHelpers; |
76 |
|
} |
77 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
78 |
0 |
public void addContextAttribute(String name, Class<?> componentClass) {... |
79 |
0 |
ContextAttributeConfiguration attributeConfiguration = new ContextAttributeConfiguration(); |
80 |
0 |
attributeConfiguration.setName(name); |
81 |
0 |
attributeConfiguration.setComponentClass(componentClass); |
82 |
0 |
addContextAttribute(name, attributeConfiguration); |
83 |
|
} |
84 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
85 |
0 |
@Override... |
86 |
|
protected void setupContext(Map<String, Object> ctx, Node content, RenderableDefinition definition, RenderingModel<?> model, Object actionResult) { |
87 |
0 |
super.setupContext(ctx, content, definition, model, actionResult); |
88 |
0 |
ctx.putAll(RenderContext.get().getModel()); |
89 |
|
} |
90 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
91 |
0 |
@Override... |
92 |
|
protected String resolveTemplateScript(Node content, RenderableDefinition definition, RenderingModel<?> model, String actionResult) { |
93 |
0 |
return RenderContext.get().getTemplateScript(); |
94 |
|
} |
95 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 5 |
Complexity Density: 0.38 |
|
96 |
0 |
@Override... |
97 |
|
protected void onRender(Node content, RenderableDefinition definition, RenderingContext renderingCtx, Map<String, Object> ctx, String templateScript) throws RenderException { |
98 |
|
|
99 |
0 |
if (MgnlContext.isWebContext()) { |
100 |
|
|
101 |
0 |
@SuppressWarnings("unchecked") |
102 |
|
Map<String, Object> model = ctx; |
103 |
|
|
104 |
|
|
105 |
|
|
106 |
0 |
if (this.exposeSpringMacroHelpers) { |
107 |
0 |
model.put(AbstractTemplateView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE, |
108 |
|
new RequestContext( |
109 |
|
MgnlContext.getWebContext().getRequest(), |
110 |
|
MgnlContext.getWebContext().getResponse(), |
111 |
|
MgnlContext.getWebContext().getServletContext(), |
112 |
|
model)); |
113 |
|
} |
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
0 |
if (this.exposeModelAsRequestAttributes) { |
119 |
0 |
HttpServletRequest request = MgnlContext.getWebContext().getRequest(); |
120 |
0 |
for (Map.Entry<String, Object> entry : model.entrySet()) { |
121 |
0 |
String modelName = entry.getKey(); |
122 |
0 |
Object modelValue = entry.getValue(); |
123 |
0 |
if (modelValue != null) { |
124 |
0 |
request.setAttribute(modelName, modelValue); |
125 |
|
} else { |
126 |
0 |
request.removeAttribute(modelName); |
127 |
|
} |
128 |
|
} |
129 |
|
} |
130 |
|
} |
131 |
|
|
132 |
0 |
super.onRender(content, definition, renderingCtx, ctx, templateScript); |
133 |
|
} |
134 |
|
} |