001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: OpenBeanshell.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.gui.ui.commands;
009:
010: import bsh.EvalError;
011: import bsh.Interpreter;
012: import com.uwyn.rife.gui.Rife;
013: import com.uwyn.rife.resources.ResourceFinderClasspath;
014: import com.uwyn.rife.resources.exceptions.ResourceFinderErrorException;
015: import com.uwyn.rife.swing.Command;
016: import com.uwyn.rife.swing.JDialogSystemError;
017: import com.uwyn.rife.tools.ExceptionUtils;
018: import com.uwyn.rife.tools.InnerClassException;
019: import com.uwyn.rife.tools.InputStreamUser;
020: import java.io.BufferedReader;
021: import java.io.InputStream;
022: import java.io.InputStreamReader;
023: import java.io.UnsupportedEncodingException;
024:
025: public class OpenBeanshell implements Command {
026: public void execute() {
027: (new RealExecute()).start();
028: }
029:
030: private class RealExecute extends Thread {
031: public void run() {
032: final String beanshell_desktop_path = "shared/scripts/rife_desktop.bsh";
033:
034: try {
035: (ResourceFinderClasspath.getInstance()).useStream(
036: beanshell_desktop_path, new InputStreamUser() {
037: public Object useInputStream(
038: InputStream stream)
039: throws InnerClassException {
040: InputStreamReader input_stream_reader = null;
041: BufferedReader buffered_reader = null;
042:
043: if (stream != null) {
044: try {
045: input_stream_reader = new InputStreamReader(
046: stream, "ISO8859_1");
047:
048: if (input_stream_reader != null) {
049: buffered_reader = new BufferedReader(
050: input_stream_reader);
051:
052: if (buffered_reader != null) {
053: try {
054: new Interpreter()
055: .eval(buffered_reader);
056: return null;
057: } catch (EvalError e) {
058: (new JDialogSystemError(
059: Rife
060: .getMainFrame(),
061: "OpenBeanshell.RealExecute.run() : "
062: + "Error while evaluating the beanshell desktop script : "
063: + ExceptionUtils
064: .getExceptionStackTrace(e)))
065: .setVisible(true);
066: return null;
067: }
068: }
069: } else {
070: (new JDialogSystemError(
071: Rife.getMainFrame(),
072: "OpenBeanshell.RealExecute.run() : "
073: + "Couldn't create the buffered reader for the beanshell desktop script resource at '"
074: + beanshell_desktop_path
075: + "'."))
076: .setVisible(true);
077: return null;
078: }
079: } catch (UnsupportedEncodingException e) {
080: (new JDialogSystemError(
081: Rife.getMainFrame(),
082: "OpenBeanshell.RealExecute.run() : "
083: + "Error while creating the inputstream reader for the beanshell desktop script resource at '"
084: + beanshell_desktop_path
085: + "' : "
086: + ExceptionUtils
087: .getExceptionStackTrace(e)))
088: .setVisible(true);
089: return null;
090: }
091: } else {
092: (new JDialogSystemError(
093: Rife.getMainFrame(),
094: "OpenBeanshell.RealExecute.run() : "
095: + "Couldn't open the beanshell desktop script resource at '"
096: + beanshell_desktop_path
097: + "'."))
098: .setVisible(true);
099: return null;
100: }
101: (new JDialogSystemError(Rife
102: .getMainFrame(),
103: "OpenBeanshell.RealExecute.run() : Couldn't open the beanshell desktop."))
104: .setVisible(true);
105:
106: return null;
107: }
108: });
109: } catch (ResourceFinderErrorException e) {
110: (new JDialogSystemError(
111: Rife.getMainFrame(),
112: "OpenBeanshell.RealExecute.run() : "
113: + "Error while evaluating the beanshell desktop script : "
114: + ExceptionUtils
115: .getExceptionStackTrace(e)))
116: .setVisible(true);
117: return;
118: }
119: return;
120: }
121: }
122: }
|