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