/** * MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface. * Copyright (C) 2012 Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ /******************************************************************************\ * * This product was developed by * * SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO), * * a government company established under Brazilian law (5.615/70), * at Department of Development of Porto Alegre. * \******************************************************************************/ package serpro.mailarchiver.view.admin; import serpro.mailarchiver.service.Settings; import serpro.mailarchiver.service.find.FBinaryBody; import serpro.mailarchiver.service.find.FFolder; import serpro.mailarchiver.service.find.FMessage; import serpro.mailarchiver.service.web.ArchiveServices; import serpro.mailarchiver.util.ArchiveServicesProxyFactory; import serpro.mailarchiver.util.ConsoleMediator; import serpro.mailarchiver.util.Environment; import serpro.mailarchiver.util.Logger; import serpro.mailarchiver.util.RequestContextInheritingThread; import serpro.mailarchiver.view.BaseComponent; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.orm.jdo.JdoTransactionManager; import com.vaadin.ui.VerticalLayout; import org.vaadin.console.Console; import com.eventrouter.DispatchContext; import bsh.Interpreter; public class Terminal extends BaseComponent.Panel { private static final Logger log = Logger.getLocalLogger(); @Autowired private Environment environment; @Autowired private FFolder findFolder; @Autowired private FMessage findMessage; @Autowired private FBinaryBody findBinaryBody; @Autowired private ArchiveServices archiveServices; @Autowired private ArchiveServicesProxyFactory archiveServicesProxyFactory; @Autowired private JdoTransactionManager txManager; @Autowired private DispatchContext dispatchContext; @Autowired private Settings settings; private Console console; private ConsoleMediator mediator; private Interpreter interpreter; Terminal() { new TerminalController(getDisplayId()); } @Override public final String getDisplayId() { return "terminal"; } @Override public Terminal init() { setSizeFull(); setScrollable(true); VerticalLayout panelVLo = new VerticalLayout(); panelVLo.setMargin(false); panelVLo.setSpacing(false); panelVLo.setSizeFull(); console = new Console(); console.setPs(""); console.setCols(400); console.setRows(100); console.setMaxBufferSize(4000); console.setGreeting("Welcome to MailArchiver BeanShell Console."); console.setPrintPromptOnInput(true); console.reset(); console.focus(); panelVLo.addComponent(console); setContent(panelVLo); mediator = new ConsoleMediator(console); interpreter = new Interpreter(mediator) { { //TRACE = true; } @Override public void run() { try { super.run(); } catch(Throwable t) { log.error(t, "terminal"); } } }; interpreter.setExitOnEOF(false); try { interpreter.set("environment", environment); interpreter.set("findFolder", findFolder); interpreter.set("findMessage", findMessage); interpreter.set("findBinaryBody", findBinaryBody); interpreter.set("archiveServices", archiveServices); interpreter.set("archiveServicesProxy", archiveServicesProxyFactory.getProxy()); interpreter.set("txManager", txManager); interpreter.set("dispatchContext", dispatchContext); interpreter.set("settings", settings); interpreter.eval("import serpro.mailarchiver.util.transaction.ReadOnlyTx"); interpreter.eval("import serpro.mailarchiver.util.transaction.ReadWriteTx"); } catch(Exception e) { log.error(e, "Interpreter setup"); } new RequestContextInheritingThread(interpreter).start(); interpreter.getNameSpace().importCommands("serpro.mailarchiver.util.bshcommands"); return this; } }