2
* This is a simple mechanism to bind Inkscape to Java, and thence
3
* to all of the nice things that can be layered upon that.
8
* Copyright (C) 2007 Bob Jamison
10
* This library is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU Lesser General Public
12
* License as published by the Free Software Foundation; either
13
* version 2.1 of the License, or (at your option) any later version.
15
* This library is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
* Lesser General Public License for more details.
20
* You should have received a copy of the GNU Lesser General Public
21
* License along with this library; if not, write to the Free Software
22
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
package org.inkscape.cmn;
27
import javax.script.*;
28
import java.io.FileReader;
29
import java.io.IOException;
30
import javax.swing.JOptionPane;
35
public class ScriptRunner
40
static void err(String message)
42
JOptionPane.showMessageDialog(null, message,
43
"Script Error", JOptionPane.ERROR_MESSAGE);
48
public static boolean run(String lang, String str)
50
ScriptEngineManager factory = new ScriptEngineManager();
51
// create JavaScript engine
52
ScriptEngine engine = factory.getEngineByName(lang);
53
// evaluate JavaScript code from given file - specified by first argument
58
catch (javax.script.ScriptException e)
60
err("Executing script: " + e);
65
public static boolean runFile(String lang, String fname)
67
ScriptEngineManager factory = new ScriptEngineManager();
68
// create JavaScript engine
69
ScriptEngine engine = factory.getEngineByName(lang);
70
// evaluate JavaScript code from given file - specified by first argument
75
in = new FileReader(fname);
77
catch (java.io.IOException e)
79
err("Executing file: " + e);
86
catch (javax.script.ScriptException e)
88
err("Executing file: " + e);
95
catch (java.io.IOException e)
97
err("Executing file: " + e);