PageRenderTime 55ms CodeModel.GetById 24ms 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
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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 org.gjt.sp.jedit.bsh.*;
  25. import java.io.PrintWriter;
  26. import java.io.StringWriter;
  27. import org.gjt.sp.jedit.BeanShell;
  28. import org.gjt.sp.jedit.jEdit;
  29. import org.gjt.sp.jedit.View;
  30. //}}}
  31. public class ConsoleBeanShell extends Shell
  32. {
  33. //{{{ ConsoleBeanShell constructor
  34. public ConsoleBeanShell()
  35. {
  36. super("BeanShell");
  37. } //}}}
  38. //{{{ printInfoMessage() method
  39. public void printInfoMessage(Output output)
  40. {
  41. if (jEdit.getBooleanProperty("console.shell.info.toggle"))
  42. output.print(null,jEdit.getProperty("console.beanshell.info"));
  43. } //}}}
  44. //{{{ printPrompt() method
  45. /**
  46. * Prints a prompt to the specified console.
  47. * @param output The output
  48. */
  49. public void printPrompt(Console console, Output output)
  50. {
  51. output.writeAttrs(
  52. ConsolePane.colorAttributes(console.getInfoColor()),
  53. jEdit.getProperty("console.beanshell.prompt"));
  54. output.writeAttrs(null," ");
  55. } //}}}
  56. //{{{ execute() method
  57. public void execute(Console console, String input, Output output,
  58. Output error, String command)
  59. {
  60. if (error == null) error = output;
  61. View view = console.getView();
  62. NameSpace ns = org.gjt.sp.jedit.BeanShell.getNameSpace();
  63. try
  64. {
  65. ns.setVariable("console",console);
  66. ns.setVariable("output",output);
  67. Object retVal = BeanShell._eval(view,
  68. ns,command);
  69. if(retVal != null)
  70. {
  71. ns.setVariable("retVal",retVal);
  72. BeanShell._eval(view,ns,
  73. "print(retVal);");
  74. ns.setVariable("retVal",null);
  75. }
  76. }
  77. catch(Exception e)
  78. {
  79. StringWriter s = new StringWriter();
  80. e.printStackTrace(new PrintWriter(s));
  81. error.print(console.getErrorColor(),s.toString());
  82. }
  83. finally
  84. {
  85. try
  86. {
  87. ns.setVariable("console",null);
  88. ns.setVariable("output",null);
  89. }
  90. catch(UtilEvalError e)
  91. {
  92. }
  93. }
  94. if (error != output) error.commandDone();
  95. output.commandDone();
  96. } //}}}
  97. //{{{ stop() method
  98. public void stop(Console console)
  99. {
  100. } //}}}
  101. //{{{ waitFor() method
  102. public boolean waitFor(Console console)
  103. {
  104. return true;
  105. } //}}}
  106. }