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;
35
36 import java.lang.reflect.Constructor;
37 import javax.jcr.RepositoryException;
38 import javax.servlet.http.HttpServletRequest;
39 import javax.servlet.http.HttpServletResponse;
40
41 import info.magnolia.cms.core.Content;
42 import info.magnolia.cms.gui.dialog.Dialog;
43 import info.magnolia.cms.gui.dialog.DialogFactory;
44
45
46
47
48
49
50
51
52
53 public class ConfiguredDialogHandlerProvider implements DialogHandlerProvider {
54
55 private String id;
56 private Content configNode;
57 private Class<? extends DialogMVCHandler> dialogHandlerClass;
58
59 public ConfiguredDialogHandlerProvider(String id, Content configNode, Class<? extends DialogMVCHandler> dialogHandlerClass) {
60 this.id = id;
61 this.configNode = configNode;
62 this.dialogHandlerClass = dialogHandlerClass;
63 }
64
65 @Override
66 public String getId() {
67 return id;
68 }
69
70 @Override
71 public Content getDialogConfigNode() {
72 return configNode;
73 }
74
75 @Override
76 public Dialog getDialog() throws RepositoryException {
77 return DialogFactory.getDialogInstance(null, null, null, configNode);
78 }
79
80 @Override
81 public DialogMVCHandler getDialogHandler(HttpServletRequest request, HttpServletResponse response) {
82
83 try {
84 Content configNode = this.configNode;
85 if (configNode != null) {
86 try {
87 Constructor<? extends DialogMVCHandler> constructor = dialogHandlerClass.getConstructor(new Class[]{
88 String.class,
89 HttpServletRequest.class,
90 HttpServletResponse.class,
91 Content.class});
92 return constructor.newInstance(id, request, response, configNode);
93 } catch (NoSuchMethodException e) {
94 Constructor<? extends DialogMVCHandler> constructor = dialogHandlerClass.getConstructor(new Class[]{
95 String.class,
96 HttpServletRequest.class,
97 HttpServletResponse.class});
98 return constructor.newInstance(id, request, response);
99 }
100 }
101
102 Constructor<? extends DialogMVCHandler> constructor = dialogHandlerClass.getConstructor(new Class[]{
103 String.class,
104 HttpServletRequest.class,
105 HttpServletResponse.class});
106 return constructor.newInstance(id, request, response);
107 } catch (Exception e) {
108 throw new InvalidDialogHandlerException(id, e);
109 }
110 }
111 }