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; |
35 |
|
|
36 |
|
import info.magnolia.cms.core.Content; |
37 |
|
import info.magnolia.cms.core.ItemType; |
38 |
|
import info.magnolia.cms.beans.config.ObservedManager; |
39 |
|
import info.magnolia.objectfactory.Classes; |
40 |
|
import info.magnolia.objectfactory.Components; |
41 |
|
|
42 |
|
import java.util.Collection; |
43 |
|
import java.util.HashMap; |
44 |
|
import java.util.Iterator; |
45 |
|
import java.util.Map; |
46 |
|
|
47 |
|
import org.apache.commons.lang.StringUtils; |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
@author |
53 |
|
@version |
54 |
|
|
|
|
| 0% |
Uncovered Elements: 31 (31) |
Complexity: 10 |
Complexity Density: 0.5 |
|
55 |
|
public class TemplateRendererManager extends ObservedManager { |
56 |
|
|
57 |
|
private static final String ND_RENDERER = "renderer"; |
58 |
|
|
59 |
|
private static final String ND_TYPE = "type"; |
60 |
|
|
61 |
|
private Map renderers = new HashMap(); |
62 |
|
|
63 |
|
|
64 |
|
@return |
65 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
0
|
public static TemplateRendererManager getInstance() {... |
67 |
0
|
return Components.getSingleton(TemplateRendererManager.class); |
68 |
|
} |
69 |
|
|
70 |
|
|
71 |
|
@see |
72 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 6 |
Complexity Density: 0.4 |
|
73 |
0
|
protected void onRegister(Content node) {... |
74 |
0
|
Collection list = node.getChildren(ItemType.CONTENTNODE); |
75 |
0
|
for (Iterator iter = list.iterator(); iter.hasNext();) { |
76 |
0
|
Content tr = (Content) iter.next(); |
77 |
0
|
String type = tr.getNodeData(ND_TYPE).getString(); |
78 |
0
|
String rendererClass = tr.getNodeData(ND_RENDERER).getString(); |
79 |
|
|
80 |
0
|
if (StringUtils.isEmpty(type)) { |
81 |
0
|
type = tr.getName(); |
82 |
|
} |
83 |
|
|
84 |
0
|
if (StringUtils.isBlank(type) || StringUtils.isBlank(rendererClass)) { |
85 |
0
|
log.warn("Can't register template render at {}, type=\"{}\" renderer=\"{}\"", new Object[]{tr.getHandle(), type, rendererClass}); |
86 |
0
|
continue; |
87 |
|
} |
88 |
|
|
89 |
|
|
90 |
0
|
try { |
91 |
0
|
final TemplateRenderer renderer = (TemplateRenderer) Classes.newInstance(rendererClass); |
92 |
0
|
log.debug("Registering template render [{}] for type {}", rendererClass, type); |
93 |
0
|
registerTemplateRenderer(type, renderer); |
94 |
|
} |
95 |
|
catch (Exception e) { |
96 |
0
|
log.warn("Can't register template renderer at {}, type=\"{}\" renderer=\"{}\" due to a {} exception: {}", new Object[]{tr.getHandle(), type, rendererClass, e.getClass().getName(), e.getMessage()}, e); |
97 |
|
} |
98 |
|
|
99 |
|
} |
100 |
|
|
101 |
|
} |
102 |
|
|
103 |
|
|
104 |
|
@see |
105 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
106 |
0
|
protected void onClear() {... |
107 |
0
|
this.renderers.clear(); |
108 |
|
} |
109 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
110 |
0
|
public void registerTemplateRenderer(String type, TemplateRenderer instance) {... |
111 |
0
|
synchronized (renderers) { |
112 |
0
|
renderers.put(type, instance); |
113 |
|
} |
114 |
|
} |
115 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
116 |
0
|
public TemplateRenderer getRenderer(String type) {... |
117 |
0
|
return (TemplateRenderer) renderers.get(type); |
118 |
|
} |
119 |
|
|
120 |
|
} |