summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1d9fba0)
raw | patch | inline | side by side (parent: 1d9fba0)
author | ishmal <ishmal@users.sourceforge.net> | |
Thu, 3 Apr 2008 13:23:49 +0000 (13:23 +0000) | ||
committer | ishmal <ishmal@users.sourceforge.net> | |
Thu, 3 Apr 2008 13:23:49 +0000 (13:23 +0000) |
src/bind/javabind.cpp | patch | blob | history |
diff --git a/src/bind/javabind.cpp b/src/bind/javabind.cpp
index c62981f1f09ce577fd7a2539085656da11e8a813..fe9cff4df1ef236f8e4c89ad9bb76331a34e3fe6 100644 (file)
--- a/src/bind/javabind.cpp
+++ b/src/bind/javabind.cpp
return buf;
}
+
+/**
+ * Convert a java string to a C++ string
+ */
+String getString(JNIEnv *env, jstring jstr)
+{
+ const char *chars = env->GetStringUTFChars(jstr, JNI_FALSE);
+ String str = chars;
+ env->ReleaseStringUTFChars(jstr, chars);
+ return str;
+}
+
+
+/**
+ * Check if the VM has encountered an Exception. If so, get the String for it
+ * and clear the exception
+ */
String getExceptionString(JNIEnv *env)
{
String buf;
jclass cls = env->GetObjectClass(exc);
jmethodID mid = env->GetMethodID(cls, "toString", "()Ljava/lang/String;");
jstring jstr = (jstring) env->CallObjectMethod(exc, mid);
- const char *str = env->GetStringUTFChars(jstr, JNI_FALSE);
- buf.append(str);
- env->ReleaseStringUTFChars(jstr, str);
+ buf.append(getString(env, jstr));
env->ExceptionClear();
return buf;
}
env->SetDoubleField(obj, fid, val);
}
-String getString(JNIEnv *env, jstring jstr)
-{
- const char *chars = env->GetStringUTFChars(jstr, JNI_FALSE);
- String str = chars;
- env->ReleaseStringUTFChars(jstr, chars);
- return str;
-}
-
String getObjString(JNIEnv *env, jobject obj, const char *name)
{
jfieldID fid = env->GetFieldID(env->GetObjectClass(obj), name, "Ljava/lang/String;");
};
+/**
+ * Return the directory of the .exe that is currently running
+ */
static String getExePath()
{
- char exeName[80];
- GetModuleFileName(NULL, exeName, 80);
+ char exeName[MAX_PATH+1];
+ GetModuleFileName(NULL, exeName, MAX_PATH);
char *slashPos = strrchr(exeName, '\\');
if (slashPos)
*slashPos = '\0';
}
+/**
+ * Check a directory for several possibilities of sub-locations
+ * under it, where a jvm might exist.
+ */
static String checkPathUnderRoot(const String &root)
{
for (const char **path = commonJavaPaths ; *path ; path++)
+/**
+ * Attempt to find and load a jvm.dll file. Find the createVM()
+ * function's address and return it
+ */
static CreateVMFunc getCreateVMFunc()
{
bool found = false;
String libname;
/**
- * First, look for an embedded jre in the $INKSCAPE dir.
+ * First, look for an embedded jre in the .exe's dir.
* This allows us to package our own JRE if we want to.
*/
String inkscapeHome = getExePath();
return createVM;
}
+/**
+ * Return the directory where the Java classes/libs/resources are
+ * located
+ */
static void getJavaRoot(String &javaroot)
{
javaroot = getExePath();
}
+/**
+ * Some common places on a Unix filesystem where JVMs are
+ * often found.
+ */
static const char *commonJavaPaths[] =
{
"/usr/lib/jvm/jre",
NULL
};
+
+
/**
* Look for a Java VM (libjvm.so) in several Unix places
*/
+/**
+ * Attempt to find and load a jvm.dll file. Find the createVM()
+ * function's address and return it
+ */
static CreateVMFunc getCreateVMFunc()
{
String libname;
}
+/**
+ * Return the directory where the Java classes/libs/resources are
+ * located
+ */
static void getJavaRoot(String &javaroot)
{
javaroot = INKSCAPE_BINDDIR;
* This is provided to scripts can grab the current copy or the
* repr tree. If anyone has a smarter way of doing this, please implement.
*/
-jstring JNICALL documentGet(JNIEnv *env, jobject /*obj*/, jlong ptr)
+jstring JNICALL documentGet(JNIEnv *env, jobject /*obj*/, jlong /*ptr*/)
{
- JavaBinderyImpl *bind = (JavaBinderyImpl *)ptr;
+ //JavaBinderyImpl *bind = (JavaBinderyImpl *)ptr;
String buf = sp_repr_save_buf((SP_ACTIVE_DOCUMENT)->rdoc);
jstring jstr = env->NewStringUTF(buf.c_str());
return jstr;
* This is provided to scripts can load an XML tree into Inkscape.
* If anyone has a smarter way of doing this, please implement.
*/
-jboolean JNICALL documentSet(JNIEnv *env, jobject /*obj*/, jlong ptr, jstring jstr)
+jboolean JNICALL documentSet(JNIEnv *env, jobject /*obj*/, jlong /*ptr*/, jstring jstr)
{
- JavaBinderyImpl *bind = (JavaBinderyImpl *)ptr;
+ //JavaBinderyImpl *bind = (JavaBinderyImpl *)ptr;
String s = getString(env, jstr);
SPDocument *doc = sp_document_new_from_mem(s.c_str(), s.size(), true);
}