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.objectfactory.Components;
37 import info.magnolia.rendering.renderer.ContextAttributeConfiguration;
38
39 import java.util.HashMap;
40 import java.util.Map;
41
42 import org.springframework.beans.factory.config.AbstractFactoryBean;
43
44
45
46
47
48
49
50 public class SiteAwareFreemarkerTemplateViewRendererFactoryBean extends AbstractFactoryBean<SiteAwareFreemarkerTemplateViewRenderer> {
51
52 private Map<String, ContextAttributeConfiguration> contextAttributes = new HashMap<String, ContextAttributeConfiguration>();
53 private boolean exposeModelAsRequestAttributes = true;
54 private boolean exposeSpringMacroHelpers = true;
55
56 public Map<String, ContextAttributeConfiguration> getContextAttributes() {
57 return contextAttributes;
58 }
59
60 public void setContextAttributes(Map<String, ContextAttributeConfiguration> contextAttributes) {
61 this.contextAttributes = contextAttributes;
62 }
63
64 public void addContextAttribute(String name, ContextAttributeConfiguration contextAttributeConfiguration) {
65 this.contextAttributes.put(name, contextAttributeConfiguration);
66 }
67
68 public void addContextAttribute(String name, Class<?> componentClass) {
69 ContextAttributeConfiguration attributeConfiguration = new ContextAttributeConfiguration();
70 attributeConfiguration.setName(name);
71 attributeConfiguration.setComponentClass(componentClass);
72 addContextAttribute(name, attributeConfiguration);
73 }
74
75 public boolean isExposeModelAsRequestAttributes() {
76 return exposeModelAsRequestAttributes;
77 }
78
79 public void setExposeModelAsRequestAttributes(boolean exposeModelAsRequestAttributes) {
80 this.exposeModelAsRequestAttributes = exposeModelAsRequestAttributes;
81 }
82
83 public boolean isExposeSpringMacroHelpers() {
84 return exposeSpringMacroHelpers;
85 }
86
87 public void setExposeSpringMacroHelpers(boolean exposeSpringMacroHelpers) {
88 this.exposeSpringMacroHelpers = exposeSpringMacroHelpers;
89 }
90
91 @Override
92 public Class<?> getObjectType() {
93 return SiteAwareFreemarkerTemplateViewRenderer.class;
94 }
95
96 @Override
97 protected SiteAwareFreemarkerTemplateViewRenderer createInstance() throws Exception {
98 SiteAwareFreemarkerTemplateViewRenderer renderer = Components.newInstance(SiteAwareFreemarkerTemplateViewRenderer.class);
99 renderer.setExposeModelAsRequestAttributes(exposeModelAsRequestAttributes);
100 renderer.setExposeSpringMacroHelpers(exposeSpringMacroHelpers);
101 renderer.setContextAttributes(contextAttributes);
102 return renderer;
103 }
104 }