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 final 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 @Override
73 public Content getConfigNode() {
74 return configNode;
75 }
76
77 public static ConfiguredDialog getConfiguredDialog(String name, Content configNode, HttpServletRequest request,
78 HttpServletResponse response) {
79 return getConfiguredDialog(name, configNode, request, response, ConfiguredDialog.class);
80 }
81
82
83
84
85
86
87
88
89
90 public static ConfiguredDialog getConfiguredDialog(String name, Content configNode, HttpServletRequest request,
91 HttpServletResponse response, Class<ConfiguredDialog> defaultClass) {
92
93 final ClassFactory classFactory = Classes.getClassFactory();
94
95 String className = null;
96 try {
97 Class<ConfiguredDialog> handlerClass = defaultClass;
98 try {
99 className = configNode.getNodeData("class").getString();
100 if (StringUtils.isNotEmpty(className)) {
101 handlerClass = classFactory.forName(className);
102 }
103 }
104 catch (Exception e) {
105 log.error("Unable to load class {}", className);
106 }
107
108 return classFactory.newInstance(handlerClass, name, request, response, configNode);
109 }
110 catch (Exception e) {
111 log.error("can't instantiate dialog: ", e);
112 return null;
113 }
114 }
115
116 }