PageRenderTime 52ms CodeModel.GetById 43ms app.highlight 7ms RepoModel.GetById 0ms app.codeStats 0ms

/bundles/plugins-trunk/Console/console/ConsoleBeanShell.java

#
Java | 119 lines | 73 code | 13 blank | 33 comment | 7 complexity | bd538428a07d430c591a4a8dfe09c8ca MD5 | raw file
  1/*
  2 * ConsoleBeanShell.java - Executes commands in jEdit's BeanShell interpreter
  3 * :tabSize=8:indentSize=8:noTabs=false:
  4 * :folding=explicit:collapseFolds=1:
  5 *
  6 * Copyright (C) 2000, 2001 Slava Pestov
  7 *
  8 * This program is free software; you can redistribute it and/or
  9 * modify it under the terms of the GNU General Public License
 10 * as published by the Free Software Foundation; either version 2
 11 * of the License, or any later version.
 12 *
 13 * This program is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16 * GNU General Public License for more details.
 17 *
 18 * You should have received a copy of the GNU General Public License
 19 * along with this program; if not, write to the Free Software
 20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 21 */
 22
 23package console;
 24
 25//{{{ Imports
 26import org.gjt.sp.jedit.bsh.*;
 27import java.io.PrintWriter;
 28import java.io.StringWriter;
 29import org.gjt.sp.jedit.BeanShell;
 30import org.gjt.sp.jedit.jEdit;
 31import org.gjt.sp.jedit.View;
 32//}}}
 33
 34public class ConsoleBeanShell extends Shell
 35{
 36	//{{{ ConsoleBeanShell constructor
 37	public ConsoleBeanShell()
 38	{
 39		super("BeanShell");
 40	} //}}}
 41
 42	//{{{ printInfoMessage() method
 43	public void printInfoMessage(Output output)
 44	{
 45		if (jEdit.getBooleanProperty("console.shell.info.toggle"))
 46			output.print(null,jEdit.getProperty("console.beanshell.info"));
 47	} //}}}
 48
 49	//{{{ printPrompt() method
 50	/**
 51	 * Prints a prompt to the specified console.
 52	 * @param output The output
 53	 */
 54	public void printPrompt(Console console, Output output)
 55	{
 56		output.writeAttrs(
 57			ConsolePane.colorAttributes(console.getInfoColor()),
 58			jEdit.getProperty("console.beanshell.prompt"));
 59		output.writeAttrs(null," ");
 60	} //}}}
 61	
 62
 63	//{{{ execute() method
 64	public void execute(Console console, String input, Output output,
 65		Output error, String command)
 66	{
 67		if (error == null) error = output;
 68		View view = console.getView();
 69
 70		NameSpace ns = org.gjt.sp.jedit.BeanShell.getNameSpace();
 71		try
 72		{
 73			ns.setVariable("console",console);
 74			ns.setVariable("output",output);
 75			Object retVal = BeanShell._eval(view,
 76				ns,command);
 77
 78			if(retVal != null)
 79			{
 80				ns.setVariable("retVal",retVal);
 81				BeanShell._eval(view,ns,
 82					"print(retVal);");
 83				ns.setVariable("retVal",null);
 84			}
 85		}
 86		catch(Exception e)
 87		{
 88			StringWriter s = new StringWriter();
 89			e.printStackTrace(new PrintWriter(s));
 90			error.print(console.getErrorColor(),s.toString());
 91		}
 92		finally
 93		{
 94			try
 95			{
 96				ns.setVariable("console",null);
 97				ns.setVariable("output",null);
 98			}
 99			catch(UtilEvalError e)
100			{
101			}
102		}
103		if (error != output) error.commandDone();
104		output.commandDone();
105
106	} //}}}
107
108	//{{{ stop() method
109	public void stop(Console console)
110	{
111	} //}}}
112
113	//{{{ waitFor() method
114	public boolean waitFor(Console console)
115	{
116		return true;
117	} //}}}
118
119}