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.templating.renderers;
35
36 import info.magnolia.jcr.util.ContentMap;
37 import info.magnolia.objectfactory.Components;
38 import info.magnolia.rendering.context.RenderingContext;
39 import info.magnolia.rendering.engine.RenderException;
40 import info.magnolia.rendering.engine.RenderingEngine;
41 import info.magnolia.rendering.renderer.AbstractRenderer;
42 import info.magnolia.rendering.template.RenderableDefinition;
43 import info.magnolia.templating.elements.AreaElement;
44 import info.magnolia.templating.elements.ComponentElement;
45
46 import java.util.ArrayList;
47 import java.util.HashMap;
48 import java.util.List;
49 import java.util.Map;
50
51 import javax.inject.Inject;
52 import javax.jcr.Node;
53
54 import org.slf4j.Logger;
55 import org.slf4j.LoggerFactory;
56
57
58
59
60
61
62 public class NoScriptRenderer extends AbstractRenderer {
63
64 public static final String NO_SCRIPT_RENDERER = "noscript";
65 private final Logger log = LoggerFactory.getLogger(getClass());
66
67
68
69
70 @Deprecated
71 public NoScriptRenderer() {
72 }
73
74 @Inject
75 public NoScriptRenderer(RenderingEngine renderingEngine) {
76 super(renderingEngine);
77 }
78
79 @Override
80 public void render(RenderingContext renderingCtx, Map<String, Object> contextObjects) throws RenderException {
81 onRender(null, null, renderingCtx, contextObjects, null);
82 }
83
84 @Override
85 protected void onRender(Node content, RenderableDefinition definition, RenderingContext renderingCtx, Map<String, Object> ctx, String templateScript) throws RenderException {
86
87 List<ContentMap> components = null;
88 if (ctx.get(AreaElement.ATTRIBUTE_COMPONENT) instanceof ContentMap) {
89 components = new ArrayList<ContentMap>();
90 components.add((ContentMap) ctx.get(AreaElement.ATTRIBUTE_COMPONENT));
91 } else if (ctx.get(AreaElement.ATTRIBUTE_COMPONENTS) instanceof List) {
92 components = (List<ContentMap>) ctx.get(AreaElement.ATTRIBUTE_COMPONENTS);
93 } else {
94 return;
95 }
96
97 try {
98 Appendable out = renderingCtx.getOutputProvider().getAppendable();
99
100 for (ContentMap component : components) {
101 ComponentElement componentElement = Components.newInstance(ComponentElement.class);
102 componentElement.setContent(component.getJCRNode());
103 componentElement.begin(out);
104 componentElement.end(out);
105 }
106 } catch (Exception e) {
107 throw new RenderException(e);
108 }
109 }
110
111 @Override
112 protected Map<String, Object> newContext() {
113 return new HashMap<String, Object>();
114 }
115
116 }