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