1 | /** |
---|
2 | * MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface. |
---|
3 | * Copyright (C) 2012 Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior |
---|
4 | * |
---|
5 | * This program is free software: you can redistribute it and/or modify |
---|
6 | * it under the terms of the GNU Affero General Public License as |
---|
7 | * published by the Free Software Foundation, either version 3 of the |
---|
8 | * License, or (at your option) any later version. |
---|
9 | * |
---|
10 | * This program is distributed in the hope that it will be useful, |
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | * GNU Affero General Public License for more details. |
---|
14 | * |
---|
15 | * You should have received a copy of the GNU Affero General Public License |
---|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
17 | */ |
---|
18 | |
---|
19 | /******************************************************************************\ |
---|
20 | * |
---|
21 | * This product was developed by |
---|
22 | * |
---|
23 | * SERVIÃO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO), |
---|
24 | * |
---|
25 | * a government company established under Brazilian law (5.615/70), |
---|
26 | * at Department of Development of Porto Alegre. |
---|
27 | * |
---|
28 | \******************************************************************************/ |
---|
29 | |
---|
30 | package serpro.mailarchiver.view.admin; |
---|
31 | |
---|
32 | import serpro.mailarchiver.service.Settings; |
---|
33 | import serpro.mailarchiver.service.find.FBinaryBody; |
---|
34 | import serpro.mailarchiver.service.find.FFolder; |
---|
35 | import serpro.mailarchiver.service.find.FMessage; |
---|
36 | import serpro.mailarchiver.service.web.ArchiveServices; |
---|
37 | import serpro.mailarchiver.util.ArchiveServicesProxyFactory; |
---|
38 | import serpro.mailarchiver.util.ConsoleMediator; |
---|
39 | import serpro.mailarchiver.util.Environment; |
---|
40 | import serpro.mailarchiver.util.Logger; |
---|
41 | import serpro.mailarchiver.util.RequestContextInheritingThread; |
---|
42 | import serpro.mailarchiver.view.BaseComponent; |
---|
43 | |
---|
44 | import org.springframework.beans.factory.annotation.Autowired; |
---|
45 | import org.springframework.orm.jdo.JdoTransactionManager; |
---|
46 | |
---|
47 | import com.vaadin.ui.VerticalLayout; |
---|
48 | |
---|
49 | import org.vaadin.console.Console; |
---|
50 | |
---|
51 | import com.eventrouter.DispatchContext; |
---|
52 | |
---|
53 | import bsh.Interpreter; |
---|
54 | |
---|
55 | public class Terminal extends BaseComponent.Panel { |
---|
56 | |
---|
57 | private static final Logger log = Logger.getLocalLogger(); |
---|
58 | |
---|
59 | @Autowired private Environment environment; |
---|
60 | @Autowired private FFolder findFolder; |
---|
61 | @Autowired private FMessage findMessage; |
---|
62 | @Autowired private FBinaryBody findBinaryBody; |
---|
63 | @Autowired private ArchiveServices archiveServices; |
---|
64 | @Autowired private ArchiveServicesProxyFactory archiveServicesProxyFactory; |
---|
65 | @Autowired private JdoTransactionManager txManager; |
---|
66 | @Autowired private DispatchContext dispatchContext; |
---|
67 | @Autowired private Settings settings; |
---|
68 | |
---|
69 | private Console console; |
---|
70 | private ConsoleMediator mediator; |
---|
71 | private Interpreter interpreter; |
---|
72 | |
---|
73 | Terminal() { |
---|
74 | new TerminalController(getDisplayId()); |
---|
75 | } |
---|
76 | |
---|
77 | @Override |
---|
78 | public final String getDisplayId() { |
---|
79 | return "terminal"; |
---|
80 | } |
---|
81 | |
---|
82 | @Override |
---|
83 | public Terminal init() { |
---|
84 | |
---|
85 | setSizeFull(); |
---|
86 | setScrollable(true); |
---|
87 | |
---|
88 | VerticalLayout panelVLo = new VerticalLayout(); |
---|
89 | panelVLo.setMargin(false); |
---|
90 | panelVLo.setSpacing(false); |
---|
91 | panelVLo.setSizeFull(); |
---|
92 | |
---|
93 | console = new Console(); |
---|
94 | console.setPs(""); |
---|
95 | console.setCols(400); |
---|
96 | console.setRows(100); |
---|
97 | console.setMaxBufferSize(4000); |
---|
98 | console.setGreeting("Welcome to MailArchiver BeanShell Console."); |
---|
99 | console.setPrintPromptOnInput(true); |
---|
100 | console.reset(); |
---|
101 | console.focus(); |
---|
102 | |
---|
103 | panelVLo.addComponent(console); |
---|
104 | |
---|
105 | setContent(panelVLo); |
---|
106 | |
---|
107 | mediator = new ConsoleMediator(console); |
---|
108 | interpreter = new Interpreter(mediator) { |
---|
109 | { |
---|
110 | //TRACE = true; |
---|
111 | } |
---|
112 | @Override |
---|
113 | public void run() { |
---|
114 | try { |
---|
115 | super.run(); |
---|
116 | } |
---|
117 | catch(Throwable t) { |
---|
118 | log.error(t, "terminal"); |
---|
119 | } |
---|
120 | } |
---|
121 | }; |
---|
122 | |
---|
123 | interpreter.setExitOnEOF(false); |
---|
124 | |
---|
125 | try { |
---|
126 | interpreter.set("environment", environment); |
---|
127 | interpreter.set("findFolder", findFolder); |
---|
128 | interpreter.set("findMessage", findMessage); |
---|
129 | interpreter.set("findBinaryBody", findBinaryBody); |
---|
130 | interpreter.set("archiveServices", archiveServices); |
---|
131 | interpreter.set("archiveServicesProxy", archiveServicesProxyFactory.getProxy()); |
---|
132 | interpreter.set("txManager", txManager); |
---|
133 | interpreter.set("dispatchContext", dispatchContext); |
---|
134 | interpreter.set("settings", settings); |
---|
135 | |
---|
136 | interpreter.eval("import serpro.mailarchiver.util.transaction.ReadOnlyTx"); |
---|
137 | interpreter.eval("import serpro.mailarchiver.util.transaction.ReadWriteTx"); |
---|
138 | } |
---|
139 | catch(Exception e) { |
---|
140 | log.error(e, "Interpreter setup"); |
---|
141 | } |
---|
142 | |
---|
143 | new RequestContextInheritingThread(interpreter).start(); |
---|
144 | |
---|
145 | interpreter.getNameSpace().importCommands("serpro.mailarchiver.util.bshcommands"); |
---|
146 | |
---|
147 | return this; |
---|
148 | } |
---|
149 | } |
---|