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.cms.gui.dialog;
35
36 import info.magnolia.cms.core.Content;
37 import info.magnolia.objectfactory.ClassFactory;
38 import info.magnolia.objectfactory.Classes;
39
40 import javax.jcr.RepositoryException;
41 import javax.servlet.http.HttpServletRequest;
42 import javax.servlet.http.HttpServletResponse;
43 import java.util.HashMap;
44 import java.util.Map;
45
46
47
48
49
50
51
52
53 public final class DialogFactory {
54 private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(DialogFactory.class);
55
56
57
58
59
60 private static Map<String, Class<DialogControl>> controls = new HashMap<String, Class<DialogControl>>();
61
62
63
64
65 private DialogFactory() {
66
67 }
68
69
70
71
72
73
74
75 public static void registerDialog(String name, Class<DialogControl> dialogClass) {
76
77
78 log.debug("Registering control [{}]", name);
79
80 controls.put(name, dialogClass);
81 }
82
83
84
85
86
87
88
89
90 public static DialogControl loadDialog(HttpServletRequest request, HttpServletResponse response,
91 Content storageNode, Content configNode) throws RepositoryException {
92 String controlType = configNode.getNodeData("controlType").getString();
93
94 return getDialogControlInstanceByName(request, response, storageNode, configNode, controlType);
95 }
96
97 public static Dialog getDialogInstance(HttpServletRequest request, HttpServletResponse response,
98 Content storageNode, Content configNode) throws RepositoryException {
99 Dialog dialog = new Dialog();
100 dialog.init(request, response, storageNode, configNode);
101 return dialog;
102 }
103
104 public static DialogStatic getDialogStaticInstance(HttpServletRequest request, HttpServletResponse response,
105 Content storageNode, Content configNode) throws RepositoryException {
106 DialogStatic dialog = new DialogStatic();
107 dialog.init(request, response, storageNode, configNode);
108 return dialog;
109 }
110
111 public static DialogHidden getDialogHiddenInstance(HttpServletRequest request, HttpServletResponse response,
112 Content storageNode, Content configNode) throws RepositoryException {
113 DialogHidden dialog = new DialogHidden();
114 dialog.init(request, response, storageNode, configNode);
115 return dialog;
116 }
117
118 public static DialogEdit getDialogEditInstance(HttpServletRequest request, HttpServletResponse response,
119 Content storageNode, Content configNode) throws RepositoryException {
120 DialogEdit dialog = new DialogEdit();
121 dialog.init(request, response, storageNode, configNode);
122 return dialog;
123 }
124
125 public static DialogButton getDialogButtonInstance(HttpServletRequest request, HttpServletResponse response,
126 Content storageNode, Content configNode) throws RepositoryException {
127 DialogButton dialog = new DialogButton();
128 dialog.init(request, response, storageNode, configNode);
129 return dialog;
130 }
131
132 public static DialogPassword getDialogPasswordInstance(HttpServletRequest request, HttpServletResponse response,
133 Content storageNode, Content configNode) throws RepositoryException {
134 DialogPassword dialog = new DialogPassword();
135 dialog.init(request, response, storageNode, configNode);
136 return dialog;
137 }
138
139 public static DialogButtonSet getDialogButtonSetInstance(HttpServletRequest request, HttpServletResponse response,
140 Content storageNode, Content configNode) throws RepositoryException {
141 DialogButtonSet dialog = new DialogButtonSet();
142 dialog.init(request, response, storageNode, configNode);
143 return dialog;
144 }
145
146 public static DialogInclude getDialogIncludeInstance(HttpServletRequest request, HttpServletResponse response,
147 Content storageNode, Content configNode) throws RepositoryException {
148 DialogInclude dialog = new DialogInclude();
149 dialog.init(request, response, storageNode, configNode);
150 return dialog;
151 }
152
153 public static DialogSelect getDialogSelectInstance(HttpServletRequest request, HttpServletResponse response,
154 Content storageNode, Content configNode) throws RepositoryException {
155 DialogSelect dialog = new DialogSelect();
156 dialog.init(request, response, storageNode, configNode);
157 return dialog;
158 }
159
160
161
162
163
164
165
166
167
168
169
170
171 public static DialogControl getDialogControlInstanceByName(HttpServletRequest request, HttpServletResponse response,
172 Content storageNode, Content configNode, String controlType) throws RepositoryException {
173
174 final ClassFactory classFactory = Classes.getClassFactory();
175 Class<DialogControl> dialogClass = controls.get(controlType);
176
177 if (dialogClass == null) {
178 try {
179 dialogClass = classFactory.forName(controlType);
180 }
181 catch (ClassNotFoundException e) {
182 throw new IllegalArgumentException("Unknown control type: \"" + controlType + "\"");
183 }
184 }
185
186
187 final DialogControl control = classFactory.newInstance(dialogClass);
188 control.init(request, response, storageNode, configNode);
189 return control;
190 }
191 }