summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 005fe2a)
raw | patch | inline | side by side (parent: 005fe2a)
author | ishmal <ishmal@users.sourceforge.net> | |
Mon, 10 Mar 2008 04:48:47 +0000 (04:48 +0000) | ||
committer | ishmal <ishmal@users.sourceforge.net> | |
Mon, 10 Mar 2008 04:48:47 +0000 (04:48 +0000) |
diff --git a/src/bind/java/org/inkscape/cmn/ScriptRunner.java b/src/bind/java/org/inkscape/cmn/ScriptRunner.java
index 1addfc72e0f2913bca04a66b2b55b092f15469fa..1214a66d4308053af5b93b1194e2a22bf3783d2d 100644 (file)
* Authors:
* Bob Jamison
*
- * Copyright (C) 2007 Bob Jamison
+ * Copyright (C) 2007-2008 Bob Jamison
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
+ * version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
import javax.script.*;
import java.io.FileReader;
+import java.io.PrintStream;
+import java.io.OutputStream;
import java.io.IOException;
import javax.swing.JOptionPane;
+/**
+ * Runs scripts
+ */
+public class ScriptRunner
+{
+long backPtr;
-public class ScriptRunner
+/**
+ * Redirect stdout
+ */
+private native void stdOutWrite(long ptr, int b);
+class StdOutStream extends OutputStream
{
+public void write(int b)
+{
+ stdOutWrite(backPtr, b);
+}
+
+}
+
+
+
+/**
+ * Redirect stderr
+ */
+private native void stdErrWrite(long ptr, int b);
+class StdErrStream extends OutputStream
+{
+
+public void write(int b)
+{
+ stdErrWrite(backPtr, b);
+}
+
+
+}
static void err(String message)
-public static boolean run(String lang, String str)
+/**
+ * Run a script buffer
+ *
+ * @param lang the scripting language to run
+ * @param str the script buffer to execute
+ * @return true if successful, else false
+ */
+public boolean run(String lang, String str)
{
ScriptEngineManager factory = new ScriptEngineManager();
// create JavaScript engine
return true;
}
-public static boolean runFile(String lang, String fname)
+
+/**
+ * Run a script file
+ *
+ * @param lang the scripting language to run
+ * @param fname the script file to execute
+ * @return true if successful, else false
+ */
+public boolean runFile(String lang, String fname)
{
ScriptEngineManager factory = new ScriptEngineManager();
// create JavaScript engine
}
+/**
+ * Constructor
+ * @param backPtr pointer back to the C context that called this
+ */
+public ScriptRunner(long backPtr)
+{
+ this.backPtr = backPtr;
+ System.setOut(new PrintStream(new StdOutStream()));
+ System.setErr(new PrintStream(new StdErrStream()));
+}
+
+
+
+private static ScriptRunner _instance = null;
+
+
+public static ScriptRunner getInstance(long backPtr)
+{
+ if (_instance == null)
+ _instance = new ScriptRunner(backPtr);
+ return _instance;
+}
+
+
+/**
+ * Run a script buffer
+ *
+ * @param backPtr pointer back to the C context that called this
+ * @param lang the scripting language to run
+ * @param str the script buffer to execute
+ * @return true if successful, else false
+ */
+public static boolean run(long ptr, String lang, String str)
+{
+ ScriptRunner runner = getInstance(ptr);
+ return runner.run(lang, str);
+}
+
+
+/**
+ * Run a script file
+ *
+ * @param backPtr pointer back to the C context that called this
+ * @param lang the scripting language to run
+ * @param fname the script file to execute
+ * @return true if successful, else false
+ */
+public static boolean runFile(long ptr, String lang, String fname)
+{
+ ScriptRunner runner = getInstance(ptr);
+ return runner.runFile(lang, fname);
+}
+
+
}
index 18b041471892d3dec4cfcf23b31af6a802596d8e..ce595fa8569f0078daf3dec22ad5ab697629b4ca 100644 (file)
* Authors:
* Bob Jamison
*
- * Copyright (C) 2007 Bob Jamison
+ * Copyright (C) 2007-2008 Bob Jamison
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
diff --git a/src/bind/javabind.cpp b/src/bind/javabind.cpp
index 36facee88084ccdf018a3931533fc310c81ea645..a25be353eb5ccdfb241aa194934f6046ea888029 100644 (file)
--- a/src/bind/javabind.cpp
+++ b/src/bind/javabind.cpp
* Authors:
* Bob Jamison
*
- * Copyright (C) 2007 Bob Jamison
+ * Copyright (C) 2007-2008 Bob Jamison
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
+ * version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
}
+static void stdOutWrite(jlong ptr, jint ch)
+{
+ JavaBinderyImpl *bind = (JavaBinderyImpl *)ptr;
+ bind->stdOut(ch);
+}
+
+static void stdErrWrite(jlong ptr, jint ch)
+{
+ JavaBinderyImpl *bind = (JavaBinderyImpl *)ptr;
+ bind->stdErr(ch);
+}
+
+
+static JNINativeMethod scriptRunnerMethods[] =
+{
+{ (char *)"stdOutWrite", (char *)"(JI)V", (void *)stdOutWrite },
+{ (char *)"stdErrWrite", (char *)"(JI)V", (void *)stdErrWrite },
+{ NULL, NULL, NULL }
+};
bool JavaBinderyImpl::loadJVM()
{
msg("Lib path is: '%s'", libpath.c_str());
JavaVMInitArgs vm_args;
- JavaVMOption options[4];
+ JavaVMOption options[2];
options[0].optionString = (char *)classpath.c_str();
options[1].optionString = (char *)libpath.c_str();
vm_args.version = JNI_VERSION_1_2;
return false;
}
+ if (!registerNatives("org/inkscape/cmn/ScriptRunner",
+ scriptRunnerMethods))
+ {
+ return false;
+ }
return true;
}
methodName.c_str(), signature.c_str());
return false;
}
+ /**
+ * Assemble your parameters into a form usable by JNI
+ */
jvalue *jvals = new jvalue[params.size()];
for (unsigned int i=0 ; i<params.size() ; i++)
{
diff --git a/src/bind/javabind.h b/src/bind/javabind.h
index 24db22e207627b385e7769b6425df1a9302cdaed..f01627a1533125e20366991ce676a8bdc214109b 100644 (file)
--- a/src/bind/javabind.h
+++ b/src/bind/javabind.h
{
return false;
}
+
+ virtual String stdOutGet()
+ {
+ return stdOutBuf;
+ }
+
+ virtual void stdOutClear()
+ {
+ stdOutBuf.clear();
+ }
+
+ virtual String stdErrGet()
+ {
+ return stdErrBuf;
+ }
+
+ virtual void stdErrClear()
+ {
+ stdErrBuf.clear();
+ }
+
+ virtual void stdOut(int ch)
+ {
+ stdOutBuf.push_back((char)ch);
+ }
+
+ virtual void stdErr(int ch)
+ {
+ stdErrBuf.push_back((char)ch);
+ }
/**
* Return a singleton instance of this bindery
*/
static JavaBindery *getInstance();
+
+protected:
+
+
+ String stdOutBuf;
+ String stdErrBuf;
};