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.admininterface.dialogs;
35
36 import info.magnolia.cms.core.Content;
37 import info.magnolia.cms.util.NodeDataUtil;
38 import info.magnolia.module.admininterface.DialogMVCHandler;
39 import info.magnolia.objectfactory.ClassFactory;
40 import info.magnolia.objectfactory.Classes;
41
42 import javax.servlet.http.HttpServletRequest;
43 import javax.servlet.http.HttpServletResponse;
44
45 import org.apache.commons.lang.StringUtils;
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
48
49
50
51
52
53 public class ConfiguredDialog extends DialogMVCHandler {
54
55 private static Logger log = LoggerFactory.getLogger(ConfiguredDialog.class);
56
57 private Content configNode;
58
59 public ConfiguredDialog(String name, HttpServletRequest request, HttpServletResponse response, Content configNode) {
60 super(name, request, response);
61 this.configNode = configNode;
62
63
64 this.setItemType(NodeDataUtil.getString(configNode, "itemType", this.getItemType()));
65 this.setJsExecutedAfterSaving(NodeDataUtil.getString(configNode, "jsExecutedAfterSaving", this.getJsExecutedAfterSaving()));
66 }
67
68
69
70
71
72 public Content getConfigNode() {
73 return configNode;
74 }
75
76 public static ConfiguredDialog getConfiguredDialog(String name, Content configNode, HttpServletRequest request,
77 HttpServletResponse response) {
78 return getConfiguredDialog(name, configNode, request, response, ConfiguredDialog.class);
79 }
80
81
82
83
84
85
86
87
88
89 public static ConfiguredDialog getConfiguredDialog(String name, Content configNode, HttpServletRequest request,
90 HttpServletResponse response, Class<ConfiguredDialog> defaultClass) {
91
92 final ClassFactory classFactory = Classes.getClassFactory();
93
94 String className = null;
95 try {
96 Class<ConfiguredDialog> handlerClass = defaultClass;
97 try {
98 className = configNode.getNodeData("class").getString();
99 if (StringUtils.isNotEmpty(className)) {
100 handlerClass = classFactory.forName(className);
101 }
102 }
103 catch (Exception e) {
104 log.error("Unable to load class {}", className);
105 }
106
107 return classFactory.newInstance(handlerClass, name, request, response, configNode);
108 }
109 catch (Exception e) {
110 log.error("can't instantiate dialog: ", e);
111 return null;
112 }
113 }
114
115 }