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.groovy.dialogs;
35
36 import info.magnolia.cms.core.Content;
37 import info.magnolia.cms.gui.dialog.Dialog;
38 import info.magnolia.cms.util.AlertUtil;
39 import info.magnolia.module.admininterface.dialogs.ConfiguredDialog;
40 import info.magnolia.module.groovy.support.HierarchyManagerProvider.UserContextHierarchyManagerProvider;
41 import info.magnolia.module.groovy.support.classes.MgnlGroovyClassLoader;
42
43 import javax.jcr.RepositoryException;
44 import javax.servlet.http.HttpServletRequest;
45 import javax.servlet.http.HttpServletResponse;
46
47 import org.codehaus.groovy.control.CompilationFailedException;
48
49
50
51
52
53
54
55 public class MgnlGroovyDialog extends ConfiguredDialog {
56
57 private final static MgnlGroovyClassLoader CL_TO_VERIFY_SOURCE = new MgnlGroovyClassLoader(new UserContextHierarchyManagerProvider());
58
59 public MgnlGroovyDialog(String name, HttpServletRequest request, HttpServletResponse response, Content configNode) {
60 super(name, request, response, configNode);
61 }
62
63 protected Dialog createDialog(Content configNode, Content storageNode) throws RepositoryException {
64
65 Dialog dialog = super.createDialog(configNode, storageNode);
66
67 dialog.setJavascriptSources("http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js");
68 dialog.setJavascriptSources(request.getContextPath() + "/.resources/js/MgnlGroovy.js");
69 return dialog;
70 }
71
72
73
74
75
76
77
78
79
80
81 @Override
82 protected boolean validate() {
83 if(!super.validate()){
84 return false;
85 }
86 boolean isScript = Boolean.valueOf(params.getParameter("script")) ;
87
88 try {
89 if(isScript){
90 CL_TO_VERIFY_SOURCE.verify(params.getParameter("text"), false, null);
91 } else {
92 CL_TO_VERIFY_SOURCE.verify(params.getParameter("text"),true, params.getParameter("mgnlPath"));
93 }
94 }
95 catch (CompilationFailedException e) {
96 AlertUtil.setMessage(e.getCause()!= null ? e.getCause().getMessage() : e.getMessage());
97 return false;
98 }
99 return true;
100 }
101 }