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.context.MgnlContext;
38 import info.magnolia.objectfactory.Classes;
39 import info.magnolia.objectfactory.MgnlInstantiationException;
40 import info.magnolia.rendering.template.configured.ConfiguredTemplateDefinition;
41
42 import java.lang.reflect.InvocationTargetException;
43 import java.util.HashMap;
44 import java.util.Map;
45
46 import org.apache.commons.beanutils.BeanUtils;
47 import org.apache.commons.lang.ArrayUtils;
48 import org.apache.commons.lang.builder.ToStringBuilder;
49
50
51
52
53
54
55
56 @Deprecated
57 public class AbstractRenderable extends ConfiguredTemplateDefinition implements RenderableDefinition {
58 private String name;
59 private String title;
60 private String templateScript;
61 private String dialog;
62 private String renderType;
63 private String description;
64 private String i18nBasename;
65
66
67 private Map parameters = new HashMap();
68
69
70
71
72 @Override
73 public String determineTemplatePath(String actionResult, RenderingModel model) {
74 return this.getTemplateScript();
75 }
76
77
78
79
80 @Override
81 public RenderingModel newModel(Content content, RenderableDefinition definition, RenderingModel parentModel) throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
82 try {
83 final RenderingModel model = Classes.getClassFactory().newInstance((Class<? extends RenderingModel>) getModelClass(), new Class[] { Content.class, definition.getClass(), RenderingModel.class }, content, definition, parentModel);
84 final Map<String, String> params = MgnlContext.getParameters();
85 if (params != null) {
86 BeanUtils.populate(model, params);
87 }
88 return model;
89 } catch (MgnlInstantiationException e) {
90 throw new IllegalArgumentException(MISSING_CONSTRUCTOR_MESSAGE + "Can't instantiate " + getModelClass(), e);
91 }
92 }
93
94 @Override
95 public String getName() {
96 return this.name;
97 }
98
99 @Override
100 public String getTitle() {
101 return this.title;
102 }
103
104
105
106
107 @Deprecated
108 @Override
109 public String getTemplatePath() {
110 return getTemplateScript();
111 }
112
113 @Override
114 public String getTemplateScript() {
115 return this.templateScript;
116 }
117
118
119
120
121 @Deprecated
122 @Override
123 public String getType() {
124 return getRenderType();
125 }
126
127 @Override
128 public String getRenderType() {
129 return renderType;
130 }
131
132 @Override
133 public String getDescription() {
134 return this.description;
135 }
136
137 @Override
138 public void setDescription(String description) {
139 this.description = description;
140 }
141
142 @Override
143 public void setName(String name) {
144 this.name = name;
145 }
146
147
148
149
150 @Deprecated
151 public void setTemplatePath(String templatePath) {
152 setTemplateScript(templatePath);
153 }
154
155 @Override
156 public void setTemplateScript(String templateScript) {
157 this.templateScript = templateScript;
158 }
159
160
161
162
163 @Deprecated
164 public void setType(String type) {
165 setRenderType(type);
166 }
167
168 @Override
169 public void setRenderType(String renderType) {
170 this.renderType = renderType;
171 }
172
173 @Override
174 public void setTitle(String title) {
175 this.title = title;
176 }
177
178 @Override
179 public String getDialog() {
180 return this.dialog;
181 }
182
183 @Override
184 public void setDialog(String dialog) {
185 this.dialog = dialog;
186 }
187
188 @Override
189 public String getI18nBasename() {
190 return this.i18nBasename;
191 }
192
193 @Override
194 public void setI18nBasename(String basename) {
195 this.i18nBasename = basename;
196 }
197
198 @Override
199 public Map getParameters() {
200 return this.parameters;
201 }
202
203 @Override
204 public void setParameters(Map params) {
205 this.parameters = params;
206 }
207
208 @Override
209 public String toString() {
210 return new ToStringBuilder(this)
211 .append("name", this.name)
212 .append("type", this.renderType)
213 .append("description", this.description)
214 .append("dialog", this.dialog)
215 .append("title", this.title)
216 .append("templateScript", this.templateScript)
217 .toString();
218 }
219
220 private static final Class<?>[] MODEL_CONSTRUCTOR_TYPES = new Class[] { Content.class, RenderableDefinition.class, RenderingModel.class };
221 private static final String MISSING_CONSTRUCTOR_MESSAGE;
222 static {
223 MISSING_CONSTRUCTOR_MESSAGE = "A model class must define a constructor with types " + ArrayUtils.toString(MODEL_CONSTRUCTOR_TYPES) + ". ";
224 }
225 }