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 public NoScriptRenderer() {
71 }
72
73 @Inject
74 public NoScriptRenderer(RenderingEngine renderingEngine) {
75 super(renderingEngine);
76 }
77
78 @Override
79 public void render(RenderingContext renderingCtx, Map<String, Object> contextObjects) throws RenderException {
80 onRender(null, null, renderingCtx, contextObjects, null);
81 }
82
83 @Override
84 protected void onRender(Node content, RenderableDefinition definition, RenderingContext renderingCtx, Map<String, Object> ctx, String templateScript) throws RenderException {
85
86 List<ContentMap> components = null;
87 if (ctx.get(AreaElement.ATTRIBUTE_COMPONENT) instanceof ContentMap) {
88 components = new ArrayList<ContentMap>();
89 components.add((ContentMap) ctx.get(AreaElement.ATTRIBUTE_COMPONENT));
90 } else if (ctx.get(AreaElement.ATTRIBUTE_COMPONENTS) instanceof List) {
91 components = (List<ContentMap>) ctx.get(AreaElement.ATTRIBUTE_COMPONENTS);
92 } else {
93 return;
94 }
95
96 try {
97 Appendable out = renderingCtx.getOutputProvider().getAppendable();
98
99 for (ContentMap component : components) {
100 ComponentElement componentElement = Components.newInstance(ComponentElement.class);
101 componentElement.setContent(component.getJCRNode());
102 componentElement.begin(out);
103 componentElement.end(out);
104 }
105 } catch (Exception e) {
106 throw new RenderException(e);
107 }
108 }
109
110 @Override
111 protected Map<String, Object> newContext() {
112 return new HashMap<String, Object>();
113 }
114
115 }