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