/plugins/Console/tags/release-3-5/console/ConsoleBeanShell.java

# · Java · 96 lines · 57 code · 11 blank · 28 comment · 2 complexity · 0ec3d80e28e7c754990036ac18ec3a5e 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. package console;
  23. //{{{ Imports
  24. import bsh.EvalError;
  25. import bsh.NameSpace;
  26. import java.io.PrintWriter;
  27. import java.io.StringWriter;
  28. import org.gjt.sp.jedit.BeanShell;
  29. import org.gjt.sp.jedit.jEdit;
  30. import org.gjt.sp.jedit.View;
  31. import org.gjt.sp.util.Log;
  32. //}}}
  33. public class ConsoleBeanShell extends Shell
  34. {
  35. //{{{ ConsoleBeanShell constructor
  36. public ConsoleBeanShell()
  37. {
  38. super("BeanShell");
  39. } //}}}
  40. //{{{ printInfoMessage() method
  41. public void printInfoMessage(Output output)
  42. {
  43. output.print(null,jEdit.getProperty("console.beanshell.info"));
  44. } //}}}
  45. //{{{ execute() method
  46. public void execute(Console console, String input, Output output,
  47. Output error, String command)
  48. {
  49. View view = console.getView();
  50. NameSpace ns = org.gjt.sp.jedit.BeanShell.getNameSpace();
  51. try
  52. {
  53. ns.setVariable("console",console);
  54. ns.setVariable("output",output);
  55. Object retVal = BeanShell._eval(view,
  56. BeanShell.getNameSpace(),command);
  57. if(retVal != null)
  58. {
  59. ns.setVariable("retVal",retVal);
  60. BeanShell._eval(view,BeanShell.getNameSpace(),
  61. "print(retVal);");
  62. ns.setVariable("retVal",null);
  63. }
  64. ns.setVariable("console",null);
  65. ns.setVariable("output",null);
  66. }
  67. catch(Exception e)
  68. {
  69. StringWriter s = new StringWriter();
  70. e.printStackTrace(new PrintWriter(s));
  71. error.print(console.getErrorColor(),s.toString());
  72. }
  73. output.commandDone();
  74. error.commandDone();
  75. } //}}}
  76. //{{{ stop() method
  77. public void stop(Console console)
  78. {
  79. } //}}}
  80. //{{{ waitFor() method
  81. public boolean waitFor(Console console)
  82. {
  83. return true;
  84. } //}}}
  85. }