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.engine; |
35 |
|
|
36 |
|
import java.io.IOException; |
37 |
|
import java.io.Writer; |
38 |
|
|
39 |
|
import info.magnolia.cms.core.AggregationState; |
40 |
|
import info.magnolia.cms.core.Content; |
41 |
|
import info.magnolia.cms.core.ItemType; |
42 |
|
import info.magnolia.context.MgnlContext; |
43 |
|
import info.magnolia.module.templating.Paragraph; |
44 |
|
import info.magnolia.module.templating.ParagraphManager; |
45 |
|
import info.magnolia.module.templating.ParagraphRenderer; |
46 |
|
import info.magnolia.module.templating.ParagraphRendererManager; |
47 |
|
import info.magnolia.module.templating.RenderException; |
48 |
|
import info.magnolia.module.templating.RenderableDefinition; |
49 |
|
import info.magnolia.module.templating.Template; |
50 |
|
import info.magnolia.module.templating.TemplateManager; |
51 |
|
import info.magnolia.module.templating.TemplateRenderer; |
52 |
|
import info.magnolia.module.templating.TemplateRendererManager; |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
@author |
60 |
|
@version |
61 |
|
|
62 |
|
|
|
|
| 0% |
Uncovered Elements: 48 (48) |
Complexity: 14 |
Complexity Density: 0.48 |
|
63 |
|
public class DefaultRenderingEngine implements RenderingEngine { |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
|
|
| 0% |
Uncovered Elements: 27 (27) |
Complexity: 10 |
Complexity Density: 0.67 |
|
68 |
|
protected enum RenderingHelper { |
69 |
|
PARAGRAPH { |
70 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
0
|
public RenderableDefinition getDefinition(String definitionName) {... |
72 |
0
|
return ParagraphManager.getInstance().getParagraphDefinition(definitionName); |
73 |
|
} |
74 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
75 |
0
|
public Object getRenderer(RenderableDefinition definition) {... |
76 |
0
|
return ParagraphRendererManager.getInstance().getRenderer(definition.getType()); |
77 |
|
} |
78 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
0
|
void render(Content content, RenderableDefinition definition, Object renderer, Writer out) throws RenderException, IOException {... |
80 |
0
|
((ParagraphRenderer) renderer).render(content, (Paragraph) definition, out); |
81 |
|
} |
82 |
|
}, |
83 |
|
|
84 |
|
TEMPLATE { |
85 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 5 |
Complexity Density: 0.5 |
|
86 |
0
|
public RenderableDefinition getDefinition(String definitionName) {... |
87 |
0
|
AggregationState state = getAggregationStateSafely(); |
88 |
0
|
String extension = null; |
89 |
0
|
if (state != null) { |
90 |
0
|
extension = state.getExtension(); |
91 |
|
} |
92 |
0
|
Template template = TemplateManager.getInstance().getTemplateDefinition(definitionName); |
93 |
0
|
if (template != null && extension != null) { |
94 |
0
|
Template subTemplate = template.getSubTemplate(extension); |
95 |
0
|
if (subTemplate != null) { |
96 |
0
|
template = subTemplate; |
97 |
|
} |
98 |
|
} |
99 |
0
|
return template; |
100 |
|
|
101 |
|
} |
102 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
103 |
0
|
public Object getRenderer(RenderableDefinition definition) {... |
104 |
0
|
return TemplateRendererManager.getInstance().getRenderer(definition.getType()); |
105 |
|
} |
106 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
107 |
0
|
public void render(Content content, RenderableDefinition definition, Object renderer, Writer out) throws RenderException, IOException {... |
108 |
0
|
((TemplateRenderer) renderer).renderTemplate(content, (Template) definition, out); |
109 |
|
} |
110 |
|
}; |
111 |
|
|
112 |
|
abstract RenderableDefinition getDefinition(String definitionName); |
113 |
|
|
114 |
|
abstract Object getRenderer(RenderableDefinition definition); |
115 |
|
|
116 |
|
abstract void render(Content content, RenderableDefinition definition, Object renderer, Writer out) throws RenderException, IOException; |
117 |
|
} |
118 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
119 |
0
|
public void render(Content content, Writer out) throws RenderException {... |
120 |
0
|
render(content, determineAssignedDefinitionName(content), out); |
121 |
|
} |
122 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
123 |
0
|
public void render(Content content, String definitionName, Writer out) throws RenderException {... |
124 |
|
|
125 |
|
|
126 |
0
|
if (content != null && content.isNodeType(ItemType.CONTENTNODE.getSystemName())) { |
127 |
0
|
render(content, definitionName, RenderingHelper.PARAGRAPH, out); |
128 |
|
} |
129 |
|
else { |
130 |
0
|
render(content, definitionName, RenderingHelper.TEMPLATE, out); |
131 |
|
} |
132 |
|
} |
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
137 |
0
|
protected String determineAssignedDefinitionName(Content content) {... |
138 |
0
|
return content.getMetaData().getTemplate(); |
139 |
|
} |
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
|
|
| 0% |
Uncovered Elements: 31 (31) |
Complexity: 7 |
Complexity Density: 0.33 |
|
144 |
0
|
protected void render(Content content, String definitionName, RenderingHelper helper, Writer out) throws RenderException {... |
145 |
0
|
Content orgMainContent = null; |
146 |
0
|
Content orgCurrentContent = null; |
147 |
|
|
148 |
0
|
AggregationState state = getAggregationStateSafely(); |
149 |
0
|
if (state != null) { |
150 |
0
|
orgMainContent = state.getMainContent(); |
151 |
0
|
orgCurrentContent = state.getCurrentContent(); |
152 |
|
|
153 |
0
|
state.setCurrentContent(content); |
154 |
|
|
155 |
0
|
if (orgMainContent == null) { |
156 |
0
|
state.setMainContent(content); |
157 |
|
} |
158 |
|
} |
159 |
|
|
160 |
0
|
RenderableDefinition definition = helper.getDefinition(definitionName); |
161 |
0
|
if (definition == null) { |
162 |
0
|
throw new RenderException("Can't find renderable definition " + definitionName + " for content: " + content.getHandle()); |
163 |
|
} |
164 |
|
|
165 |
0
|
Object renderer = helper.getRenderer(definition); |
166 |
0
|
if (renderer == null) { |
167 |
0
|
throw new RenderException("Can't find renderer for type " + definition.getType() + " of content: " + content.getHandle()); |
168 |
|
} |
169 |
|
|
170 |
0
|
try { |
171 |
0
|
helper.render(content, definition, renderer, out); |
172 |
|
} |
173 |
|
catch (IOException e) { |
174 |
0
|
throw new RenderException("Can't render " + content.getHandle(), e); |
175 |
|
} |
176 |
|
|
177 |
0
|
if (state != null) { |
178 |
0
|
state.setMainContent(orgMainContent); |
179 |
0
|
state.setCurrentContent(orgCurrentContent); |
180 |
|
} |
181 |
|
} |
182 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
183 |
0
|
protected static AggregationState getAggregationStateSafely() {... |
184 |
0
|
if (MgnlContext.isWebContext()) { |
185 |
0
|
return MgnlContext.getAggregationState(); |
186 |
|
} |
187 |
0
|
return null; |
188 |
|
} |
189 |
|
|
190 |
|
} |