source: contrib/MailArchiver/sources/src/serpro/mailarchiver/view/admin/Terminal.java @ 6785

Revision 6785, 5.1 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado codigo do MailArchiver?. Documentação na subpasta DOCS.

Line 
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
30package serpro.mailarchiver.view.admin;
31
32import serpro.mailarchiver.service.Settings;
33import serpro.mailarchiver.service.find.FBinaryBody;
34import serpro.mailarchiver.service.find.FFolder;
35import serpro.mailarchiver.service.find.FMessage;
36import serpro.mailarchiver.service.web.ArchiveServices;
37import serpro.mailarchiver.util.ArchiveServicesProxyFactory;
38import serpro.mailarchiver.util.ConsoleMediator;
39import serpro.mailarchiver.util.Environment;
40import serpro.mailarchiver.util.Logger;
41import serpro.mailarchiver.util.RequestContextInheritingThread;
42import serpro.mailarchiver.view.BaseComponent;
43
44import org.springframework.beans.factory.annotation.Autowired;
45import org.springframework.orm.jdo.JdoTransactionManager;
46
47import com.vaadin.ui.VerticalLayout;
48
49import org.vaadin.console.Console;
50
51import com.eventrouter.DispatchContext;
52
53import bsh.Interpreter;
54
55public 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}
Note: See TracBrowser for help on using the repository browser.