From 936d9e8484ff73282c8c0a277310d1ffdde86e10 Mon Sep 17 00:00:00 2001 From: "Roberto C. Sanchez" Date: Sat, 29 Mar 2014 10:54:02 -0400 Subject: Imported Upstream version 1.6.1+dfsg --- bindings/java-jni/Makefile | 15 + bindings/java-jni/jni/Android.mk | 208 +++ .../jni/org_crosswire_android_sword_InstallMgr.h | 85 ++ .../jni/org_crosswire_android_sword_SWMgr.h | 141 ++ .../org_crosswire_android_sword_SWMgr_ModInfo.h | 13 + .../org_crosswire_android_sword_SWMgr_SearchHit.h | 13 + .../jni/org_crosswire_android_sword_SWModule.h | 191 +++ ...rg_crosswire_android_sword_SWModule_SearchHit.h | 13 + ...android_sword_SWModule_SearchProgressReporter.h | 13 + bindings/java-jni/jni/swordstub.cpp | 1462 ++++++++++++++++++++ bindings/java-jni/jni/webmgr.hpp | 115 ++ .../org/crosswire/android/sword/InstallMgr.java | 17 + .../src/org/crosswire/android/sword/SWMgr.java | 38 + .../src/org/crosswire/android/sword/SWModule.java | 65 + 14 files changed, 2389 insertions(+) create mode 100644 bindings/java-jni/Makefile create mode 100644 bindings/java-jni/jni/Android.mk create mode 100644 bindings/java-jni/jni/org_crosswire_android_sword_InstallMgr.h create mode 100644 bindings/java-jni/jni/org_crosswire_android_sword_SWMgr.h create mode 100644 bindings/java-jni/jni/org_crosswire_android_sword_SWMgr_ModInfo.h create mode 100644 bindings/java-jni/jni/org_crosswire_android_sword_SWMgr_SearchHit.h create mode 100644 bindings/java-jni/jni/org_crosswire_android_sword_SWModule.h create mode 100644 bindings/java-jni/jni/org_crosswire_android_sword_SWModule_SearchHit.h create mode 100644 bindings/java-jni/jni/org_crosswire_android_sword_SWModule_SearchProgressReporter.h create mode 100644 bindings/java-jni/jni/swordstub.cpp create mode 100644 bindings/java-jni/jni/webmgr.hpp create mode 100644 bindings/java-jni/src/org/crosswire/android/sword/InstallMgr.java create mode 100644 bindings/java-jni/src/org/crosswire/android/sword/SWMgr.java create mode 100644 bindings/java-jni/src/org/crosswire/android/sword/SWModule.java (limited to 'bindings/java-jni') diff --git a/bindings/java-jni/Makefile b/bindings/java-jni/Makefile new file mode 100644 index 0000000..1fd3743 --- /dev/null +++ b/bindings/java-jni/Makefile @@ -0,0 +1,15 @@ +all: + mkdir -p classes + javac -d classes src/org/crosswire/android/sword/*.java + javah -d jni -classpath classes -jni org.crosswire.android.sword.SWMgr + javah -d jni -classpath classes -jni org.crosswire.android.sword.SWModule + javah -d jni -classpath classes -jni org.crosswire.android.sword.InstallMgr + javap -s -classpath classes/ org.crosswire.android.sword.SWMgr > SWMgr.txt + javap -s -classpath classes/ org.crosswire.android.sword.SWMgr.ModInfo > ModInfo.txt + javap -s -classpath classes/ org.crosswire.android.sword.SWModule > SWModule.txt + javap -s -classpath classes/ org.crosswire.android.sword.SWModule.SearchHit > SearchHit.txt + javap -s -classpath classes/ org.crosswire.android.sword.SWModule.SearchProgressReporter > SearchProgressReporter.txt + javap -s -classpath classes/ org.crosswire.android.sword.InstallMgr > InstallMgr.txt + cp src/org/crosswire/android/sword/*.java /home/scribe/src/bishop/src/org/crosswire/android/sword/ + + diff --git a/bindings/java-jni/jni/Android.mk b/bindings/java-jni/jni/Android.mk new file mode 100644 index 0000000..6f2520d --- /dev/null +++ b/bindings/java-jni/jni/Android.mk @@ -0,0 +1,208 @@ +# Copyright (C) 2009 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# the purpose of this sample is to demonstrate how one can +# generate two distinct shared libraries and have them both +# uploaded in +# + + +LOCAL_PATH:= $(call my-dir) + +# first lib, which will be built statically +# +include $(CLEAR_VARS) + +STLPORT_BASE := $(NDK_WRAPPERS_BASE)/stlport + +LOCAL_MODULE := libswordcore +LOCAL_C_INCLUDES := ../sword/include +LOCAL_CFLAGS += -I$(STLPORT_BASE)/stlport \ + -D__NEW__ \ + -D__unix__ \ + -D__SGI_STL_INTERNAL_PAIR_H \ + -D_FTPLIB_NO_COMPAT \ + -DANDROID \ + -DOS_ANDROID +LOCAL_SRC_FILES := ../../../src/modules/comments/zcom/zcom.cpp \ +../../../src/modules/comments/rawfiles/rawfiles.cpp \ +../../../src/modules/comments/rawcom4/rawcom4.cpp \ +../../../src/modules/comments/rawcom/rawcom.cpp \ +../../../src/modules/comments/swcom.cpp \ +../../../src/modules/comments/hrefcom/hrefcom.cpp \ +../../../src/modules/swmodule.cpp \ +../../../src/modules/tests/echomod.cpp \ +../../../src/modules/genbook/swgenbook.cpp \ +../../../src/modules/genbook/rawgenbook/rawgenbook.cpp \ +../../../src/modules/lexdict/swld.cpp \ +../../../src/modules/lexdict/rawld4/rawld4.cpp \ +../../../src/modules/lexdict/zld/zld.cpp \ +../../../src/modules/lexdict/rawld/rawld.cpp \ +../../../src/modules/texts/rawtext/rawtext.cpp \ +../../../src/modules/texts/rawtext4/rawtext4.cpp \ +../../../src/modules/texts/swtext.cpp \ +../../../src/modules/texts/ztext/ztext.cpp \ +../../../src/modules/common/rawstr4.cpp \ +../../../src/modules/common/lzsscomprs.cpp \ +../../../src/modules/common/zipcomprs.cpp \ +../../../src/modules/common/rawverse4.cpp \ +../../../src/modules/common/swcipher.cpp \ +../../../src/modules/common/swcomprs.cpp \ +../../../src/modules/common/rawverse.cpp \ +../../../src/modules/common/sapphire.cpp \ +../../../src/modules/common/zstr.cpp \ +../../../src/modules/common/entriesblk.cpp \ +../../../src/modules/common/zverse.cpp \ +../../../src/modules/common/rawstr.cpp \ +../../../src/modules/filters/gbfwordjs.cpp \ +../../../src/modules/filters/utf8latin1.cpp \ +../../../src/modules/filters/utf8greekaccents.cpp \ +../../../src/modules/filters/utf16utf8.cpp \ +../../../src/modules/filters/gbfwebif.cpp \ +../../../src/modules/filters/plainfootnotes.cpp \ +../../../src/modules/filters/utf8transliterator.cpp \ +../../../src/modules/filters/gbfstrongs.cpp \ +../../../src/modules/filters/osisplain.cpp \ +../../../src/modules/filters/thmlhtmlhref.cpp \ +../../../src/modules/filters/thmlgbf.cpp \ +../../../src/modules/filters/utf8utf16.cpp \ +../../../src/modules/filters/utf8cantillation.cpp \ +../../../src/modules/filters/utf8arshaping.cpp \ +../../../src/modules/filters/cipherfil.cpp \ +../../../src/modules/filters/thmlheadings.cpp \ +../../../src/modules/filters/thmlscripref.cpp \ +../../../src/modules/filters/latin1utf8.cpp \ +../../../src/modules/filters/gbfhtml.cpp \ +../../../src/modules/filters/thmlosis.cpp \ +../../../src/modules/filters/utf8nfkd.cpp \ +../../../src/modules/filters/thmlstrongs.cpp \ +../../../src/modules/filters/osisvariants.cpp \ +../../../src/modules/filters/thmlmorph.cpp \ +../../../src/modules/filters/gbfplain.cpp \ +../../../src/modules/filters/gbfhtmlhref.cpp \ +../../../src/modules/filters/utf8html.cpp \ +../../../src/modules/filters/utf8nfc.cpp \ +../../../src/modules/filters/rtfhtml.cpp \ +../../../src/modules/filters/gbfredletterwords.cpp \ +../../../src/modules/filters/latin1utf16.cpp \ +../../../src/modules/filters/osisscripref.cpp \ +../../../src/modules/filters/thmlhtml.cpp \ +../../../src/modules/filters/gbfthml.cpp \ +../../../src/modules/filters/teihtmlhref.cpp \ +../../../src/modules/filters/gbfrtf.cpp \ +../../../src/modules/filters/gbfosis.cpp \ +../../../src/modules/filters/teirtf.cpp \ +../../../src/modules/filters/thmlwordjs.cpp \ +../../../src/modules/filters/papyriplain.cpp \ +../../../src/modules/filters/osisfootnotes.cpp \ +../../../src/modules/filters/osiswordjs.cpp \ +../../../src/modules/filters/osismorph.cpp \ +../../../src/modules/filters/osislemma.cpp \ +../../../src/modules/filters/osisredletterwords.cpp \ +../../../src/modules/filters/osisrtf.cpp \ +../../../src/modules/filters/gbfheadings.cpp \ +../../../src/modules/filters/osisruby.cpp \ +../../../src/modules/filters/osishtmlhref.cpp \ +../../../src/modules/filters/utf8bidireorder.cpp \ +../../../src/modules/filters/thmlrtf.cpp \ +../../../src/modules/filters/swoptfilter.cpp \ +../../../src/modules/filters/utf8arabicpoints.cpp \ +../../../src/modules/filters/osisstrongs.cpp \ +../../../src/modules/filters/osisheadings.cpp \ +../../../src/modules/filters/unicodertf.cpp \ +../../../src/modules/filters/gbffootnotes.cpp \ +../../../src/modules/filters/greeklexattribs.cpp \ +../../../src/modules/filters/osiswebif.cpp \ +../../../src/modules/filters/thmlfootnotes.cpp \ +../../../src/modules/filters/thmlplain.cpp \ +../../../src/modules/filters/osisosis.cpp \ +../../../src/modules/filters/utf8hebrewpoints.cpp \ +../../../src/modules/filters/osismorphsegmentation.cpp \ +../../../src/modules/filters/thmlwebif.cpp \ +../../../src/modules/filters/thmlvariants.cpp \ +../../../src/modules/filters/plainhtml.cpp \ +../../../src/modules/filters/thmllemma.cpp \ +../../../src/modules/filters/gbfmorph.cpp \ +../../../src/modules/filters/teiplain.cpp \ +../../../src/modules/filters/swbasicfilter.cpp \ +../../../src/mgr/stringmgr.cpp \ +../../../src/mgr/swmgr.cpp \ +../../../src/mgr/swsearchable.cpp \ +../../../src/mgr/localemgr.cpp \ +../../../src/mgr/swconfig.cpp \ +../../../src/mgr/markupfiltmgr.cpp \ +../../../src/mgr/encfiltmgr.cpp \ +../../../src/mgr/swfiltermgr.cpp \ +../../../src/mgr/swcacher.cpp \ +../../../src/mgr/installmgr.cpp \ +../../../src/mgr/swlocale.cpp \ +../../../src/mgr/filemgr.cpp \ +../../../src/mgr/versemgr.cpp \ +../../../src/mgr/ftptrans.cpp \ +../../../src/mgr/ftplibftpt.cpp \ +../../../src/utilfuns/swobject.cpp \ +../../../src/utilfuns/roman.cpp \ +../../../src/utilfuns/swbuf.cpp \ +../../../src/utilfuns/utilstr.cpp \ +../../../src/utilfuns/ftplib.c \ +../../../src/utilfuns/ftpparse.c \ +../../../src/utilfuns/url.cpp \ +../../../src/utilfuns/swversion.cpp \ +../../../src/utilfuns/utilxml.cpp \ +../../../src/utilfuns/swunicod.cpp \ +../../../src/utilfuns/regex.c \ +../../../src/keys/swkey.cpp \ +../../../src/keys/versetreekey.cpp \ +../../../src/keys/treekeyidx.cpp \ +../../../src/keys/versekey.cpp \ +../../../src/keys/strkey.cpp \ +../../../src/keys/treekey.cpp \ +../../../src/keys/listkey.cpp \ +../../../src/frontend/swdisp.cpp \ +../../../src/frontend/swlog.cpp \ +../../../src/utilfuns/zlib/untgz.c + +#../../../../../sword/src/mgr/curlftpt.cpp \ +#../../../../../sword/src/mgr/curlhttpt.cpp \ +#../../../../../sword/src/utilfuns/win32/dirent.cpp \ +#../../../../../sword/src/frontend/framework/femain.cpp \ +#../../../../../sword/src/frontend/im/nullim.cpp \ +#../../../../../sword/src/frontend/im/swinputmeth.cpp \ +#../../../../../sword/src/frontend/im/hebrewmcim.cpp \ + +include $(BUILD_STATIC_LIBRARY) + +# second lib, which will depend on and include the first one +# +include $(CLEAR_VARS) + +STLPORT_BASE := $(NDK_WRAPPERS_BASE)/stlport + +LOCAL_MODULE := libsword +LOCAL_C_INCLUDES := ../sword/include +LOCAL_CFLAGS += -I$(STLPORT_BASE)/stlport \ + -D__NEW__ \ + -D__SGI_STL_INTERNAL_PAIR_H \ + -DANDROID \ + -DOS_ANDROID + +LOCAL_LDLIBS += -L$(STLPORT_BASE)/build/lib/obj/arm-linux-gcc/so \ + -lstlport -lz -llog + +LOCAL_SRC_FILES := swordstub.cpp + +LOCAL_STATIC_LIBRARIES := libswordcore + +include $(BUILD_SHARED_LIBRARY) diff --git a/bindings/java-jni/jni/org_crosswire_android_sword_InstallMgr.h b/bindings/java-jni/jni/org_crosswire_android_sword_InstallMgr.h new file mode 100644 index 0000000..b80243b --- /dev/null +++ b/bindings/java-jni/jni/org_crosswire_android_sword_InstallMgr.h @@ -0,0 +1,85 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_crosswire_android_sword_InstallMgr */ + +#ifndef _Included_org_crosswire_android_sword_InstallMgr +#define _Included_org_crosswire_android_sword_InstallMgr +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_crosswire_android_sword_InstallMgr + * Method: reInit + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_InstallMgr_reInit + (JNIEnv *, jobject); + +/* + * Class: org_crosswire_android_sword_InstallMgr + * Method: setUserDisclaimerConfirmed + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_InstallMgr_setUserDisclaimerConfirmed + (JNIEnv *, jobject); + +/* + * Class: org_crosswire_android_sword_InstallMgr + * Method: syncConfig + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_org_crosswire_android_sword_InstallMgr_syncConfig + (JNIEnv *, jobject); + +/* + * Class: org_crosswire_android_sword_InstallMgr + * Method: uninstallModule + * Signature: (Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_org_crosswire_android_sword_InstallMgr_uninstallModule + (JNIEnv *, jobject, jstring); + +/* + * Class: org_crosswire_android_sword_InstallMgr + * Method: getRemoteSources + * Signature: ()[Ljava/lang/String; + */ +JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_InstallMgr_getRemoteSources + (JNIEnv *, jobject); + +/* + * Class: org_crosswire_android_sword_InstallMgr + * Method: refreshRemoteSource + * Signature: (Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_org_crosswire_android_sword_InstallMgr_refreshRemoteSource + (JNIEnv *, jobject, jstring); + +/* + * Class: org_crosswire_android_sword_InstallMgr + * Method: getRemoteModInfoList + * Signature: (Ljava/lang/String;)[Lorg/crosswire/android/sword/SWMgr/ModInfo; + */ +JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_InstallMgr_getRemoteModInfoList + (JNIEnv *, jobject, jstring); + +/* + * Class: org_crosswire_android_sword_InstallMgr + * Method: remoteInstallModule + * Signature: (Ljava/lang/String;Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_org_crosswire_android_sword_InstallMgr_remoteInstallModule + (JNIEnv *, jobject, jstring, jstring); + +/* + * Class: org_crosswire_android_sword_InstallMgr + * Method: getRemoteModuleByName + * Signature: (Ljava/lang/String;Ljava/lang/String;)Lorg/crosswire/android/sword/SWModule; + */ +JNIEXPORT jobject JNICALL Java_org_crosswire_android_sword_InstallMgr_getRemoteModuleByName + (JNIEnv *, jobject, jstring, jstring); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/bindings/java-jni/jni/org_crosswire_android_sword_SWMgr.h b/bindings/java-jni/jni/org_crosswire_android_sword_SWMgr.h new file mode 100644 index 0000000..a95cf8e --- /dev/null +++ b/bindings/java-jni/jni/org_crosswire_android_sword_SWMgr.h @@ -0,0 +1,141 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_crosswire_android_sword_SWMgr */ + +#ifndef _Included_org_crosswire_android_sword_SWMgr +#define _Included_org_crosswire_android_sword_SWMgr +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: version + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWMgr_version + (JNIEnv *, jobject); + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: reInit + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_reInit + (JNIEnv *, jobject); + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: getModInfoList + * Signature: ()[Lorg/crosswire/android/sword/SWMgr/ModInfo; + */ +JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWMgr_getModInfoList + (JNIEnv *, jobject); + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: getModuleByName + * Signature: (Ljava/lang/String;)Lorg/crosswire/android/sword/SWModule; + */ +JNIEXPORT jobject JNICALL Java_org_crosswire_android_sword_SWMgr_getModuleByName + (JNIEnv *, jobject, jstring); + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: getPrefixPath + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWMgr_getPrefixPath + (JNIEnv *, jobject); + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: getConfigPath + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWMgr_getConfigPath + (JNIEnv *, jobject); + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: setGlobalOption + * Signature: (Ljava/lang/String;Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_setGlobalOption + (JNIEnv *, jobject, jstring, jstring); + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: getGlobalOption + * Signature: (Ljava/lang/String;)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWMgr_getGlobalOption + (JNIEnv *, jobject, jstring); + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: getGlobalOptionTip + * Signature: (Ljava/lang/String;)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWMgr_getGlobalOptionTip + (JNIEnv *, jobject, jstring); + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: filterText + * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWMgr_filterText + (JNIEnv *, jobject, jstring, jstring); + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: getGlobalOptions + * Signature: ()[Ljava/lang/String; + */ +JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWMgr_getGlobalOptions + (JNIEnv *, jobject); + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: getGlobalOptionValues + * Signature: (Ljava/lang/String;)[Ljava/lang/String; + */ +JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWMgr_getGlobalOptionValues + (JNIEnv *, jobject, jstring); + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: setCipherKey + * Signature: (Ljava/lang/String;Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_setCipherKey + (JNIEnv *, jobject, jstring, jstring); + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: setJavascript + * Signature: (Z)V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_setJavascript + (JNIEnv *, jobject, jboolean); + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: getAvailableLocales + * Signature: ()[Ljava/lang/String; + */ +JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWMgr_getAvailableLocales + (JNIEnv *, jobject); + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: setDefaultLocale + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_setDefaultLocale + (JNIEnv *, jobject, jstring); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/bindings/java-jni/jni/org_crosswire_android_sword_SWMgr_ModInfo.h b/bindings/java-jni/jni/org_crosswire_android_sword_SWMgr_ModInfo.h new file mode 100644 index 0000000..f3b8fd6 --- /dev/null +++ b/bindings/java-jni/jni/org_crosswire_android_sword_SWMgr_ModInfo.h @@ -0,0 +1,13 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_crosswire_android_sword_SWMgr_ModInfo */ + +#ifndef _Included_org_crosswire_android_sword_SWMgr_ModInfo +#define _Included_org_crosswire_android_sword_SWMgr_ModInfo +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif +#endif diff --git a/bindings/java-jni/jni/org_crosswire_android_sword_SWMgr_SearchHit.h b/bindings/java-jni/jni/org_crosswire_android_sword_SWMgr_SearchHit.h new file mode 100644 index 0000000..062c579 --- /dev/null +++ b/bindings/java-jni/jni/org_crosswire_android_sword_SWMgr_SearchHit.h @@ -0,0 +1,13 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_crosswire_android_sword_SWMgr_SearchHit */ + +#ifndef _Included_org_crosswire_android_sword_SWMgr_SearchHit +#define _Included_org_crosswire_android_sword_SWMgr_SearchHit +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif +#endif diff --git a/bindings/java-jni/jni/org_crosswire_android_sword_SWModule.h b/bindings/java-jni/jni/org_crosswire_android_sword_SWModule.h new file mode 100644 index 0000000..15b1ad0 --- /dev/null +++ b/bindings/java-jni/jni/org_crosswire_android_sword_SWModule.h @@ -0,0 +1,191 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_crosswire_android_sword_SWModule */ + +#ifndef _Included_org_crosswire_android_sword_SWModule +#define _Included_org_crosswire_android_sword_SWModule +#ifdef __cplusplus +extern "C" { +#endif +#undef org_crosswire_android_sword_SWModule_SEARCHTYPE_REGEX +#define org_crosswire_android_sword_SWModule_SEARCHTYPE_REGEX 1L +#undef org_crosswire_android_sword_SWModule_SEARCHTYPE_PHRASE +#define org_crosswire_android_sword_SWModule_SEARCHTYPE_PHRASE -1L +#undef org_crosswire_android_sword_SWModule_SEARCHTYPE_MULTIWORD +#define org_crosswire_android_sword_SWModule_SEARCHTYPE_MULTIWORD -2L +#undef org_crosswire_android_sword_SWModule_SEARCHTYPE_ENTRYATTR +#define org_crosswire_android_sword_SWModule_SEARCHTYPE_ENTRYATTR -3L +#undef org_crosswire_android_sword_SWModule_SEARCHTYPE_LUCENE +#define org_crosswire_android_sword_SWModule_SEARCHTYPE_LUCENE -4L +/* + * Class: org_crosswire_android_sword_SWModule + * Method: terminateSearch + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_terminateSearch + (JNIEnv *, jobject); + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: search + * Signature: (Ljava/lang/String;IJLjava/lang/String;Lorg/crosswire/android/sword/SWModule/SearchProgressReporter;)[Lorg/crosswire/android/sword/SWModule/SearchHit; + */ +JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_search + (JNIEnv *, jobject, jstring, jint, jlong, jstring, jobject); + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: error + * Signature: ()C + */ +JNIEXPORT jchar JNICALL Java_org_crosswire_android_sword_SWModule_error + (JNIEnv *, jobject); + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: getEntrySize + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_org_crosswire_android_sword_SWModule_getEntrySize + (JNIEnv *, jobject); + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: getEntryAttribute + * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)[Ljava/lang/String; + */ +JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_getEntryAttribute + (JNIEnv *, jobject, jstring, jstring, jstring, jboolean); + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: parseKeyList + * Signature: (Ljava/lang/String;)[Ljava/lang/String; + */ +JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_parseKeyList + (JNIEnv *, jobject, jstring); + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: setKeyText + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_setKeyText + (JNIEnv *, jobject, jstring); + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: getKeyText + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWModule_getKeyText + (JNIEnv *, jobject); + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: hasKeyChildren + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_org_crosswire_android_sword_SWModule_hasKeyChildren + (JNIEnv *, jobject); + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: getKeyChildren + * Signature: ()[Ljava/lang/String; + */ +JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_getKeyChildren + (JNIEnv *, jobject); + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: getKeyParent + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWModule_getKeyParent + (JNIEnv *, jobject); + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: previous + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_previous + (JNIEnv *, jobject); + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: next + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_next + (JNIEnv *, jobject); + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: begin + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_begin + (JNIEnv *, jobject); + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: getStripText + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWModule_getStripText + (JNIEnv *, jobject); + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: getRenderText + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWModule_getRenderText + (JNIEnv *, jobject); + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: getRawEntry + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWModule_getRawEntry + (JNIEnv *, jobject); + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: setRawEntry + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_setRawEntry + (JNIEnv *, jobject, jstring); + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: getConfigEntry + * Signature: (Ljava/lang/String;)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWModule_getConfigEntry + (JNIEnv *, jobject, jstring); + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: deleteSearchFramework + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_deleteSearchFramework + (JNIEnv *, jobject); + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: hasSearchFramework + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_org_crosswire_android_sword_SWModule_hasSearchFramework + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/bindings/java-jni/jni/org_crosswire_android_sword_SWModule_SearchHit.h b/bindings/java-jni/jni/org_crosswire_android_sword_SWModule_SearchHit.h new file mode 100644 index 0000000..e79c8fd --- /dev/null +++ b/bindings/java-jni/jni/org_crosswire_android_sword_SWModule_SearchHit.h @@ -0,0 +1,13 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_crosswire_android_sword_SWModule_SearchHit */ + +#ifndef _Included_org_crosswire_android_sword_SWModule_SearchHit +#define _Included_org_crosswire_android_sword_SWModule_SearchHit +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif +#endif diff --git a/bindings/java-jni/jni/org_crosswire_android_sword_SWModule_SearchProgressReporter.h b/bindings/java-jni/jni/org_crosswire_android_sword_SWModule_SearchProgressReporter.h new file mode 100644 index 0000000..1f7de09 --- /dev/null +++ b/bindings/java-jni/jni/org_crosswire_android_sword_SWModule_SearchProgressReporter.h @@ -0,0 +1,13 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_crosswire_android_sword_SWModule_SearchProgressReporter */ + +#ifndef _Included_org_crosswire_android_sword_SWModule_SearchProgressReporter +#define _Included_org_crosswire_android_sword_SWModule_SearchProgressReporter +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif +#endif diff --git a/bindings/java-jni/jni/swordstub.cpp b/bindings/java-jni/jni/swordstub.cpp new file mode 100644 index 0000000..f3a573f --- /dev/null +++ b/bindings/java-jni/jni/swordstub.cpp @@ -0,0 +1,1462 @@ +/* + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + */ + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "webmgr.hpp" +#include "org_crosswire_android_sword_SWMgr.h" +#include "org_crosswire_android_sword_SWModule.h" +#include "org_crosswire_android_sword_InstallMgr.h" + + +using std::cerr; +using std::map; +using std::vector; + +using namespace sword; + + +WebMgr *mgr = 0; +InstallMgr *installMgr = 0; + +class AndroidLogger : public SWLog { + vector levelMapping; +public: + AndroidLogger() { + levelMapping.resize(10, 0); + levelMapping[SWLog::LOG_ERROR] = ANDROID_LOG_ERROR; + levelMapping[SWLog::LOG_WARN] = ANDROID_LOG_WARN; + levelMapping[SWLog::LOG_INFO] = ANDROID_LOG_INFO; + levelMapping[SWLog::LOG_TIMEDINFO] = ANDROID_LOG_INFO; + levelMapping[SWLog::LOG_DEBUG] = ANDROID_LOG_DEBUG; + } + virtual void logMessage(const char *message, int level) const { + SWBuf msg = message; + if (msg.size() > 512) msg.setSize(512); + __android_log_write(levelMapping[level], "libsword.so", msg.c_str()); + } +}; + + +static void init() { + if (!mgr) { + SWLog::setSystemLog(new AndroidLogger()); + SWLog::getSystemLog()->setLogLevel(SWLog::LOG_DEBUG); + SWBuf baseDir = "/sdcard/sword"; + SWBuf confPath = baseDir + "/mods.d/globals.conf"; + // be sure we have at least some config file already out there + if (!FileMgr::existsFile(confPath.c_str())) { + FileMgr::createParent(confPath.c_str()); + remove(confPath.c_str()); + + SWConfig config(confPath.c_str()); + config["Globals"]["HiAndroid"] = "weeee"; + config.Save(); + } + mgr = new WebMgr("/sdcard/sword"); + } +} + + +static void initInstall() { + + if (!installMgr) { + SWBuf baseDir = "/sdcard/sword/InstallMgr"; + SWBuf confPath = baseDir + "/InstallMgr.conf"; + // be sure we have at least some config file already out there + if (!FileMgr::existsFile(confPath.c_str())) { + FileMgr::createParent(confPath.c_str()); + remove(confPath.c_str()); + + SWConfig config(confPath.c_str()); + config["General"]["PassiveFTP"] = "true"; + config.Save(); + } + installMgr = new InstallMgr(baseDir); + } +} + + + +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWMgr_version + (JNIEnv *env, jobject me) { + + init(); + + SWVersion v; + return env->NewStringUTF(v.currentVersion); +} + + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: reInit + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_reInit + (JNIEnv *, jobject) { + + delete mgr; + mgr = 0; +} + + +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWMgr_getPrefixPath + (JNIEnv *env, jobject me) { + + init(); + + return env->NewStringUTF(mgr->prefixPath); +} + +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWMgr_getConfigPath + (JNIEnv *env, jobject me) { + + init(); + + return env->NewStringUTF(mgr->configPath); +} + + +JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWMgr_getModInfoList + (JNIEnv *env, jobject) { + + init(); + + int size = 0; + for (sword::ModMap::iterator it = mgr->Modules.begin(); it != mgr->Modules.end(); it++) { + if ((!(it->second->getConfigEntry("CipherKey"))) || (*(it->second->getConfigEntry("CipherKey")))) + size++; + } + +SWLog::getSystemLog()->logDebug("getModInfoList returning %d length array\n", size); + + jclass clazzModInfo = env->FindClass("org/crosswire/android/sword/SWMgr$ModInfo"); + jfieldID nameID = env->GetFieldID(clazzModInfo, "name", "Ljava/lang/String;"); + jfieldID descID = env->GetFieldID(clazzModInfo, "description", "Ljava/lang/String;"); + jfieldID catID = env->GetFieldID(clazzModInfo, "category", "Ljava/lang/String;"); + jfieldID langID = env->GetFieldID(clazzModInfo, "language", "Ljava/lang/String;"); + jfieldID versionID = env->GetFieldID(clazzModInfo, "version", "Ljava/lang/String;"); + jfieldID deltaID = env->GetFieldID(clazzModInfo, "delta", "Ljava/lang/String;"); + + jobjectArray ret = (jobjectArray) env->NewObjectArray(size, clazzModInfo, NULL); + + int i = 0; + for (sword::ModMap::iterator it = mgr->Modules.begin(); it != mgr->Modules.end(); it++) { + SWModule *module = it->second; + + if ((!(module->getConfigEntry("CipherKey"))) || (*(module->getConfigEntry("CipherKey")))) { + SWBuf type = module->Type(); + SWBuf cat = module->getConfigEntry("Category"); + SWBuf version = module->getConfigEntry("Version"); + if (cat.length() > 0) type = cat; + + jobject modInfo = env->AllocObject(clazzModInfo); + + jstring val; + val = env->NewStringUTF(assureValidUTF8(module->Name())); env->SetObjectField(modInfo, nameID , val); env->DeleteLocalRef(val); + val = env->NewStringUTF(assureValidUTF8(module->Description())); env->SetObjectField(modInfo, descID , val); env->DeleteLocalRef(val); + val = env->NewStringUTF(assureValidUTF8(type.c_str())); env->SetObjectField(modInfo, catID , val); env->DeleteLocalRef(val); + val = env->NewStringUTF(assureValidUTF8(module->Lang())); env->SetObjectField(modInfo, langID , val); env->DeleteLocalRef(val); + val = env->NewStringUTF(assureValidUTF8(version.c_str())); env->SetObjectField(modInfo, versionID, val); env->DeleteLocalRef(val); + val = env->NewStringUTF(assureValidUTF8("")); env->SetObjectField(modInfo, deltaID , val); env->DeleteLocalRef(val); + + env->SetObjectArrayElement(ret, i++, modInfo); + + env->DeleteLocalRef(modInfo); + + } + } + return ret; +} + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: getModuleByName + * Signature: (Ljava/lang/String;)Lorg/crosswire/android/sword/SWModule; + */ +JNIEXPORT jobject JNICALL Java_org_crosswire_android_sword_SWMgr_getModuleByName + (JNIEnv *env, jobject me, jstring modNameJS) { + + init(); + + jobject retVal = 0; + + const char *modName = env->GetStringUTFChars(modNameJS, NULL); + sword::SWModule *module = mgr->getModule(modName); + env->ReleaseStringUTFChars(modNameJS, modName); + + if (module) { + SWBuf type = module->Type(); + SWBuf cat = module->getConfigEntry("Category"); + if (cat.length() > 0) type = cat; + jfieldID fieldID; + jclass clazzSWModule = env->FindClass("org/crosswire/android/sword/SWModule"); + retVal = env->AllocObject(clazzSWModule); + fieldID = env->GetFieldID(clazzSWModule, "name", "Ljava/lang/String;"); env->SetObjectField(retVal, fieldID, env->NewStringUTF(assureValidUTF8(module->Name()))); + fieldID = env->GetFieldID(clazzSWModule, "description", "Ljava/lang/String;"); env->SetObjectField(retVal, fieldID, env->NewStringUTF(assureValidUTF8(module->Description()))); + fieldID = env->GetFieldID(clazzSWModule, "category", "Ljava/lang/String;"); env->SetObjectField(retVal, fieldID, env->NewStringUTF(assureValidUTF8(type.c_str()))); + } + return retVal; +} + + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: setGlobalOption + * Signature: (Ljava/lang/String;Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_setGlobalOption + (JNIEnv *env, jobject me, jstring optionJS, jstring valueJS) { + + init(); + + const char *option = env->GetStringUTFChars(optionJS, NULL); + const char *value = env->GetStringUTFChars(valueJS, NULL); + + mgr->setGlobalOption(option, value); + + env->ReleaseStringUTFChars(valueJS, value); + env->ReleaseStringUTFChars(optionJS, option); +} + + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: getGlobalOption + * Signature: (Ljava/lang/String;)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWMgr_getGlobalOption + (JNIEnv *env, jobject me, jstring optionJS) { + + init(); + + const char *option = env->GetStringUTFChars(optionJS, NULL); + + SWBuf value = mgr->getGlobalOption(option); + + env->ReleaseStringUTFChars(optionJS, option); + + return env->NewStringUTF(assureValidUTF8(value)); +} + + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: getGlobalOptionTip + * Signature: (Ljava/lang/String;)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWMgr_getGlobalOptionTip + (JNIEnv *env, jobject me, jstring optionJS) { + + init(); + + const char *option = env->GetStringUTFChars(optionJS, NULL); + + SWBuf value = mgr->getGlobalOptionTip(option); + + env->ReleaseStringUTFChars(optionJS, option); + + return env->NewStringUTF(assureValidUTF8(value)); +} + + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: filterText + * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWMgr_filterText + (JNIEnv *env, jobject me, jstring filterNameJS, jstring textJS) { + + init(); + + const char *filterName = env->GetStringUTFChars(filterNameJS, NULL); + const char *text = env->GetStringUTFChars(textJS, NULL); + + SWBuf buf = text; + // hmmm, in the future, provide a param to specify filter value maybe? + mgr->setGlobalOption("Greek Accents", "Off"); + char errStatus = mgr->filterText(filterName, buf); + + env->ReleaseStringUTFChars(textJS, text); + env->ReleaseStringUTFChars(filterNameJS, filterName); + + return env->NewStringUTF(assureValidUTF8(buf)); +} + + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: getGlobalOptions + * Signature: ()[Ljava/lang/String; + */ +JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWMgr_getGlobalOptions + (JNIEnv *env, jobject me) { + + init(); + + sword::StringList options = mgr->getGlobalOptions(); + int count = 0; + for (sword::StringList::iterator it = options.begin(); it != options.end(); it++) { + count++; + } + + jclass clazzString = env->FindClass("java/lang/String"); + jobjectArray ret = (jobjectArray) env->NewObjectArray(count, clazzString, NULL); + + count = 0; + for (sword::StringList::iterator it = options.begin(); it != options.end(); it++) { + env->SetObjectArrayElement(ret, count++, env->NewStringUTF(assureValidUTF8(*it))); + } + + return ret; +} + + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: getGlobalOptionValues + * Signature: (Ljava/lang/String;)[Ljava/lang/String; + */ +JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWMgr_getGlobalOptionValues + (JNIEnv *env, jobject me, jstring optionJS) { + + init(); + + const char *option = env->GetStringUTFChars(optionJS, NULL); + + sword::StringList options = mgr->getGlobalOptionValues(option); + + env->ReleaseStringUTFChars(optionJS, option); + + int count = 0; + for (sword::StringList::iterator it = options.begin(); it != options.end(); it++) { + count++; + } + jclass clazzString = env->FindClass("java/lang/String"); + jobjectArray ret = (jobjectArray) env->NewObjectArray(count, clazzString, NULL); + + count = 0; + for (sword::StringList::iterator it = options.begin(); it != options.end(); it++) { + env->SetObjectArrayElement(ret, count++, env->NewStringUTF(assureValidUTF8(*it))); + } + + return ret; +} + + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: setCipherKey + * Signature: (Ljava/lang/String;Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_setCipherKey + (JNIEnv *env, jobject me , jstring modNameJS, jstring keyJS) { + + init(); + + const char *modName = env->GetStringUTFChars(modNameJS, NULL); + const char *key = env->GetStringUTFChars(keyJS, NULL); + + mgr->setCipherKey(modName, key); + + env->ReleaseStringUTFChars(keyJS, key); + env->ReleaseStringUTFChars(modNameJS, modName); +} + + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: setJavascript + * Signature: (Z)V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_setJavascript + (JNIEnv *env, jobject me, jboolean val) { + + init(); + + mgr->setJavascript(val == JNI_TRUE); +} + + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: getAvailableLocales + * Signature: ()[Ljava/lang/String; + */ +JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWMgr_getAvailableLocales + (JNIEnv *env, jobject me) { + + init(); + + sword::StringList localeNames = LocaleMgr::getSystemLocaleMgr()->getAvailableLocales(); + int count = 0; + for (sword::StringList::iterator it = localeNames.begin(); it != localeNames.end(); it++) { + count++; + } + + jclass clazzString = env->FindClass("java/lang/String"); + jobjectArray ret = (jobjectArray) env->NewObjectArray(count, clazzString, NULL); + + count = 0; + for (sword::StringList::iterator it = localeNames.begin(); it != localeNames.end(); it++) { + env->SetObjectArrayElement(ret, count++, env->NewStringUTF(assureValidUTF8(*it))); + } + return ret; +} + + +/* + * Class: org_crosswire_android_sword_SWMgr + * Method: setDefaultLocale + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWMgr_setDefaultLocale + (JNIEnv *env, jobject me, jstring localeNameJS) { + + init(); + + const char *localeName = env->GetStringUTFChars(localeNameJS, NULL); + + LocaleMgr::getSystemLocaleMgr()->setDefaultLocaleName(localeName); + + env->ReleaseStringUTFChars(localeNameJS, localeName); +} + + + +// SWModule methods ---------------------------------------------------------------------------------- + + +SWModule *getModule(JNIEnv *env, jobject me) { + + init(); + + SWModule *module = 0; + jclass clazzSWModule = env->FindClass("org/crosswire/android/sword/SWModule"); + jfieldID fieldID = env->GetFieldID(clazzSWModule, "name", "Ljava/lang/String;"); + jfieldID sourceFieldID = env->GetFieldID(clazzSWModule, "remoteSourceName", "Ljava/lang/String;"); + jstring modNameJS = (jstring)env->GetObjectField(me, fieldID); + jstring sourceNameJS = (jstring)env->GetObjectField(me, sourceFieldID); + const char *modName = (modNameJS?env->GetStringUTFChars(modNameJS, NULL):0); + const char *sourceName = (sourceNameJS?env->GetStringUTFChars(sourceNameJS, NULL):0); + if (sourceName && *sourceName) { + initInstall(); + InstallSourceMap::iterator source = installMgr->sources.find(sourceName); + if (source == installMgr->sources.end()) { + SWMgr *mgr = source->second->getMgr(); + module = mgr->getModule(modName); + } + } + else module = mgr->getModule(modName); + if (modName) env->ReleaseStringUTFChars(modNameJS, modName); + if (sourceName) env->ReleaseStringUTFChars(sourceNameJS, sourceName); + return module; +} + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: setKeyText + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_setKeyText + (JNIEnv *env, jobject me, jstring keyTextJS) { + + init(); + + SWModule *module = getModule(env, me); + + if (module) { + const char *keyText = env->GetStringUTFChars(keyTextJS, NULL); +SWLog::getSystemLog()->logDebug("setKeyText(%s, %s)", module->Name(), keyText); + sword::SWKey *key = module->getKey(); + sword::VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key); + if (vkey && (*keyText=='+' ||*keyText=='-')) { + if (!stricmp(keyText+1, "book")) { + vkey->setBook(vkey->getBook() + ((*keyText=='+')?1:-1)); + env->ReleaseStringUTFChars(keyTextJS, keyText); + return; + } + else if (!stricmp(keyText+1, "chapter")) { + vkey->setChapter(vkey->getChapter() + ((*keyText=='+')?1:-1)); + env->ReleaseStringUTFChars(keyTextJS, keyText); + return; + } + } + + module->KeyText(keyText); + env->ReleaseStringUTFChars(keyTextJS, keyText); + } +} + + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: getKeyText + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWModule_getKeyText + (JNIEnv *env, jobject me) { + + init(); + + SWModule *module = getModule(env, me); + + jstring retVal = 0; + if (module) { + retVal = env->NewStringUTF(assureValidUTF8(module->getKeyText())); + } + return retVal; +} + + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: getRenderText + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWModule_getRenderText + (JNIEnv *env, jobject me) { + + init(); + + SWModule *module = getModule(env, me); + + jstring retVal = 0; + if (module) { + retVal = env->NewStringUTF(assureValidUTF8(module->RenderText())); + } + return retVal; +} + + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: terminateSearch + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_terminateSearch + (JNIEnv *env, jobject me) { + + init(); + + SWModule *module = getModule(env, me); + + if (module) { + module->terminateSearch = true; + } +} + + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: error + * Signature: ()C + */ +JNIEXPORT jchar JNICALL Java_org_crosswire_android_sword_SWModule_error + (JNIEnv *env, jobject me) { + + init(); + + SWModule *module = getModule(env, me); + + return (module) ? module->Error() : -99; +} + + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: getEntrySize + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_org_crosswire_android_sword_SWModule_getEntrySize + (JNIEnv *env, jobject me) { + + init(); + + SWModule *module = getModule(env, me); + + return (module) ? module->getEntrySize() : 0; +} + + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: getEntryAttribute + * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)[Ljava/lang/String; + */ +JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_getEntryAttribute + (JNIEnv *env, jobject me, jstring level1JS, jstring level2JS, jstring level3JS, jboolean filteredJS) { + + init(); + + const char *level1 = env->GetStringUTFChars(level1JS, NULL); + const char *level2 = env->GetStringUTFChars(level2JS, NULL); + const char *level3 = env->GetStringUTFChars(level3JS, NULL); + bool filtered = (filteredJS == JNI_TRUE); + + jclass clazzString = env->FindClass("java/lang/String"); + jobjectArray ret = 0; + + SWModule *module = getModule(env, me); + + if (module) { + + module->RenderText(); // force parse + vector results; + + sword::AttributeTypeList &entryAttribs = module->getEntryAttributes(); + sword::AttributeTypeList::iterator i1Start, i1End; + sword::AttributeList::iterator i2Start, i2End; + sword::AttributeValue::iterator i3Start, i3End; + + if ((level1) && (*level1)) { + i1Start = entryAttribs.find(level1); + i1End = i1Start; + if (i1End != entryAttribs.end()) + i1End++; + } + else { + i1Start = entryAttribs.begin(); + i1End = entryAttribs.end(); + } + for (;i1Start != i1End; i1Start++) { + if ((level2) && (*level2)) { + i2Start = i1Start->second.find(level2); + i2End = i2Start; + if (i2End != i1Start->second.end()) + i2End++; + } + else { + i2Start = i1Start->second.begin(); + i2End = i1Start->second.end(); + } + for (;i2Start != i2End; i2Start++) { + if ((level3) && (*level3)) { + i3Start = i2Start->second.find(level3); + i3End = i3Start; + if (i3End != i2Start->second.end()) + i3End++; + } + else { + i3Start = i2Start->second.begin(); + i3End = i2Start->second.end(); + } + for (;i3Start != i3End; i3Start++) { + results.push_back(i3Start->second); + } + if (i3Start != i3End) + break; + } + if (i2Start != i2End) + break; + } + + ret = (jobjectArray) env->NewObjectArray(results.size(), clazzString, NULL); + +SWLog::getSystemLog()->logDebug("getEntryAttributes: size returned: %d", results.size()); + + for (int i = 0; i < results.size(); i++) { + if (filtered) { + env->SetObjectArrayElement(ret, i, env->NewStringUTF(assureValidUTF8(module->RenderText(results[i].c_str())))); + } + else { + env->SetObjectArrayElement(ret, i, env->NewStringUTF(assureValidUTF8(results[i].c_str()))); + } + } + } + + env->ReleaseStringUTFChars(level3JS, level3); + env->ReleaseStringUTFChars(level2JS, level2); + env->ReleaseStringUTFChars(level1JS, level1); + + return (ret) ? ret : (jobjectArray) env->NewObjectArray(0, clazzString, NULL); +} + + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: parseKeyList + * Signature: (Ljava/lang/String;)[Ljava/lang/String; + */ +JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_parseKeyList + (JNIEnv *env, jobject me, jstring keyListTextJS) { + + init(); + + const char *keyListText = env->GetStringUTFChars(keyListTextJS, NULL); + + SWModule *module = getModule(env, me); + jclass clazzString = env->FindClass("java/lang/String"); + jobjectArray ret; + + if (module) { + sword::SWKey *k = module->getKey(); + sword::VerseKey *parser = SWDYNAMIC_CAST(VerseKey, k); + if (parser) { + sword::ListKey result; + result = parser->ParseVerseList(keyListText, *parser, true); + int count = 0; + for (result = sword::TOP; !result.Error(); result++) { + count++; + } + ret = (jobjectArray) env->NewObjectArray(count, clazzString, NULL); + + count = 0; + for (result = sword::TOP; !result.Error(); result++) { + env->SetObjectArrayElement(ret, count++, env->NewStringUTF(assureValidUTF8((const char *)result))); + } + } + else { + ret = (jobjectArray) env->NewObjectArray(1, clazzString, NULL); + env->SetObjectArrayElement(ret, 0, env->NewStringUTF(assureValidUTF8(keyListText))); + } + } + + env->ReleaseStringUTFChars(keyListTextJS, keyListText); + + return ret; +} + + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: hasKeyChildren + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_org_crosswire_android_sword_SWModule_hasKeyChildren + (JNIEnv *env, jobject me) { + + init(); + + + SWModule *module = getModule(env, me); + jboolean retVal = JNI_FALSE; + + if (module) { + sword::SWKey *key = module->getKey(); + + TreeKeyIdx *tkey = SWDYNAMIC_CAST(TreeKeyIdx, key); + if (tkey) { + retVal = (tkey->hasChildren())?JNI_TRUE:JNI_FALSE; + } + } + return retVal; +} + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: getKeyChildren + * Signature: ()[Ljava/lang/String; + */ +JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_getKeyChildren + (JNIEnv *env, jobject me) { + + init(); + + + jclass clazzString = env->FindClass("java/lang/String"); + jobjectArray ret; + + SWModule *module = getModule(env, me); + + if (module) { + sword::SWKey *key = module->getKey(); + int count = 0; + + sword::VerseKey *vkey = SWDYNAMIC_CAST(VerseKey, key); + if (vkey) { + ret = (jobjectArray) env->NewObjectArray(7, clazzString, NULL); + SWBuf num; + num.appendFormatted("%d", vkey->getTestament()); + env->SetObjectArrayElement(ret, 0, env->NewStringUTF(assureValidUTF8(num.c_str()))); + num = ""; + num.appendFormatted("%d", vkey->getBook()); + env->SetObjectArrayElement(ret, 1, env->NewStringUTF(assureValidUTF8(num.c_str()))); + num = ""; + num.appendFormatted("%d", vkey->getChapter()); + env->SetObjectArrayElement(ret, 2, env->NewStringUTF(assureValidUTF8(num.c_str()))); + num = ""; + num.appendFormatted("%d", vkey->getVerse()); + env->SetObjectArrayElement(ret, 3, env->NewStringUTF(assureValidUTF8(num.c_str()))); + num = ""; + num.appendFormatted("%d", vkey->getChapterMax()); + env->SetObjectArrayElement(ret, 4, env->NewStringUTF(assureValidUTF8(num.c_str()))); + num = ""; + num.appendFormatted("%d", vkey->getVerseMax()); + env->SetObjectArrayElement(ret, 5, env->NewStringUTF(assureValidUTF8(num.c_str()))); + env->SetObjectArrayElement(ret, 6, env->NewStringUTF(assureValidUTF8(vkey->getBookName()))); + } + else { + TreeKeyIdx *tkey = SWDYNAMIC_CAST(TreeKeyIdx, key); + if (tkey) { + if (tkey->firstChild()) { + do { + count++; + } + while (tkey->nextSibling()); + tkey->parent(); + } + ret = (jobjectArray) env->NewObjectArray(count, clazzString, NULL); + count = 0; + if (tkey->firstChild()) { + do { + env->SetObjectArrayElement(ret, count++, env->NewStringUTF(assureValidUTF8(tkey->getLocalName()))); + } + while (tkey->nextSibling()); + tkey->parent(); + } + } + } + return ret; + } +} + + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: getKeyParent + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWModule_getKeyParent + (JNIEnv *env, jobject me) { + + init(); + + + SWBuf retVal = ""; + + SWModule *module = getModule(env, me); + + if (module) { + + sword::SWKey *key = module->getKey(); + + TreeKeyIdx *tkey = SWDYNAMIC_CAST(TreeKeyIdx, key); + if (tkey) { + if (tkey->parent()) { + retVal = tkey->getText(); + } + } + } + return env->NewStringUTF(assureValidUTF8(retVal)); +} + + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: previous + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_previous + (JNIEnv *env, jobject me) { + + init(); + + + SWModule *module = getModule(env, me); + + if (module) { + module->decrement(); + } +} + + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: next + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_next + (JNIEnv *env, jobject me) { + + init(); + + + SWModule *module = getModule(env, me); + + if (module) { + module->increment(); + } +} + + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: begin + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_begin + (JNIEnv *env, jobject me) { + + init(); + + + SWModule *module = getModule(env, me); + + if (module) { + module->setPosition(sword::TOP); + } +} + + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: getStripText + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWModule_getStripText + (JNIEnv *env, jobject me) { + + init(); + + + SWBuf retVal = ""; + + SWModule *module = getModule(env, me); + + if (module) { + retVal = module->StripText(); + } + + return env->NewStringUTF(assureValidUTF8(retVal)); +} + + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: getRawEntry + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWModule_getRawEntry + (JNIEnv *env, jobject me) { + + init(); + + + SWBuf retVal = ""; + + SWModule *module = getModule(env, me); + + if (module) { + retVal = module->getRawEntry(); + } + + return env->NewStringUTF(assureValidUTF8(retVal)); +} + + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: setRawEntry + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_setRawEntry + (JNIEnv *env, jobject me, jstring newEntryTextJS) { + + init(); + + + const char *newEntryText = env->GetStringUTFChars(newEntryTextJS, NULL); + + SWModule *module = getModule(env, me); + + if (module) { + module->setEntry(newEntryText); + } + + env->ReleaseStringUTFChars(newEntryTextJS, newEntryText); +} + + +jstring newBigString(JNIEnv *env, const char *buf) { + SWBuf str = assureValidUTF8(buf); + jclass stringClass = env->FindClass("java/lang/String"); + jmethodID ctorID = env->GetMethodID(stringClass, "", "([B)V"); + + jstring result; +SWLog::getSystemLog()->logDebug("newBigString: making byte array size: %d", str.size()); + jbyteArray bytes = env->NewByteArray(str.size()); +SWLog::getSystemLog()->logDebug("newBigString: setting array region"); + + env->SetByteArrayRegion(bytes, 0, str.size(), (jbyte *)str.c_str()); +SWLog::getSystemLog()->logDebug("newBigString: newing string"); + result = (jstring)env->NewObject(stringClass, ctorID, bytes); + env->DeleteLocalRef(bytes); +SWLog::getSystemLog()->logDebug("newBigString: returning"); + return result; +} + + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: getConfigEntry + * Signature: (Ljava/lang/String;)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_crosswire_android_sword_SWModule_getConfigEntry + (JNIEnv *env, jobject me, jstring configKeyJS) { + + init(); + + + jstring retVal = 0; + + const char *configKey = env->GetStringUTFChars(configKeyJS, NULL); +SWLog::getSystemLog()->logDebug("getConfigEntry(%s)\n", configKey); + + SWModule *module = getModule(env, me); + + if (module) { + SWBuf about = module->getConfigEntry(configKey); + SWBuf assuredBuf = assureValidUTF8(about.c_str()); + retVal = env->NewStringUTF(assuredBuf.c_str()); + } + + env->ReleaseStringUTFChars(configKeyJS, configKey); + + return retVal; +} + + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: deleteSearchFramework + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_SWModule_deleteSearchFramework + (JNIEnv *env, jobject me) { + + init(); + + + SWModule *module = getModule(env, me); + + if (module) { + module->deleteSearchFramework(); + } +} + + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: hasSearchFramework + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_org_crosswire_android_sword_SWModule_hasSearchFramework + (JNIEnv *env, jobject me) { + + init(); + + + SWModule *module = getModule(env, me); + + return (module && module->hasSearchFramework()) ? JNI_TRUE : JNI_FALSE; +} + + +struct pu { + pu(JNIEnv *env, jobject pr) : env(env), progressReporter(pr), last(0) {} + JNIEnv *env; + jobject progressReporter; + char last; +}; + + +void percentUpdate(char percent, void *userData) { + struct pu *p = (struct pu *)userData; + + if (percent != p->last) { + p->last = percent; + jclass cls = p->env->GetObjectClass(p->progressReporter); + jmethodID mid = p->env->GetMethodID(cls, "progressReport", "(I)V"); + if (mid != 0) { + p->env->CallVoidMethod(p->progressReporter, mid, (jint)percent); + } + } +} + + +/* + * Class: org_crosswire_android_sword_SWModule + * Method: search + * Signature: (Ljava/lang/String;IJLjava/lang/String;Lorg/crosswire/android/sword/SWModule/SearchProgressReporter;)[Lorg/crosswire/android/sword/SWModule/SearchHit; + */ +JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_SWModule_search + (JNIEnv *env, jobject me, jstring expressionJS, jint srchType, jlong flags, jstring scopeJS, jobject progressReporter) { + + init(); + + + const char *expression = env->GetStringUTFChars(expressionJS, NULL); + const char *scope = env->GetStringUTFChars(scopeJS, NULL); + + jclass clazzSearchHit = env->FindClass("org/crosswire/android/sword/SWModule$SearchHit"); + jobjectArray ret = 0; + + SWModule *module = getModule(env, me); + + struct pu peeuuu(env, progressReporter); + + if (module) { + sword::ListKey lscope; + sword::ListKey result; + + if ((scope) && (strlen(scope)) > 0) { + sword::SWKey *p = module->CreateKey(); + sword::VerseKey *parser = SWDYNAMIC_CAST(VerseKey, p); + if (!parser) { + delete p; + parser = new VerseKey(); + } + *parser = module->getKeyText(); + lscope = parser->ParseVerseList(scope, *parser, true); + result = module->search(expression, srchType, flags, &lscope, 0, &percentUpdate, &peeuuu); + delete parser; + } + else result = module->search(expression, srchType, flags, 0, 0, &percentUpdate, &peeuuu); + + int count = 0; + for (result = sword::TOP; !result.Error(); result++) count++; + + ret = (jobjectArray) env->NewObjectArray(count, clazzSearchHit, NULL); + + // if we're sorted by score, let's re-sort by verse, because Java can always re-sort by score + result = sword::TOP; + if ((count) && (long)result.getElement()->userData) + result.sort(); + + int i = 0; + for (result = sword::TOP; !result.Error(); result++) { + jfieldID fieldID; + jobject searchHit = env->AllocObject(clazzSearchHit); + + fieldID = env->GetFieldID(clazzSearchHit, "modName", "Ljava/lang/String;"); env->SetObjectField(searchHit, fieldID, env->NewStringUTF(assureValidUTF8(module->Name()))); + fieldID = env->GetFieldID(clazzSearchHit, "key", "Ljava/lang/String;"); env->SetObjectField(searchHit, fieldID, env->NewStringUTF(assureValidUTF8((const char *)result))); + fieldID = env->GetFieldID(clazzSearchHit, "score", "J"); env->SetLongField(searchHit, fieldID, (long)result.getElement()->userData); + + env->SetObjectArrayElement(ret, i++, searchHit); + } + } + + env->ReleaseStringUTFChars(scopeJS, scope); + env->ReleaseStringUTFChars(expressionJS, expression); + + return (ret) ? ret : (jobjectArray) env->NewObjectArray(0, clazzSearchHit, NULL); +} + + + +// InstallMgr methods ---------------------------------------------------------------------------------- + + +/* + * Class: org_crosswire_android_sword_InstallMgr + * Method: reInit + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_InstallMgr_reInit + (JNIEnv *env, jobject me) { + + delete installMgr; + installMgr = 0; +} + + +/* + * Class: org_crosswire_android_sword_InstallMgr + * Method: syncConfig + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_org_crosswire_android_sword_InstallMgr_syncConfig + (JNIEnv *env, jobject me) { + + initInstall(); + + return installMgr->refreshRemoteSourceConfiguration(); +} + + +/* + * Class: org_crosswire_android_sword_InstallMgr + * Method: uninstallModule + * Signature: (Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_org_crosswire_android_sword_InstallMgr_uninstallModule + (JNIEnv *env, jobject me, jstring modNameJS) { + + init(); + initInstall(); + + const char *modName = env->GetStringUTFChars(modNameJS, NULL); + +SWLog::getSystemLog()->logDebug("uninstallModule %s\n", modName); + + SWModule *module; + ModMap::iterator it = mgr->Modules.find(modName); + if (it == mgr->Modules.end()) { + return -2; + } + module = it->second; + installMgr->removeModule(mgr, module->Name()); + + env->ReleaseStringUTFChars(modNameJS, modName); + + return 0; +} + + +/* + * Class: org_crosswire_android_sword_InstallMgr + * Method: getRemoteSources + * Signature: ()[Ljava/lang/String; + */ +JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_InstallMgr_getRemoteSources + (JNIEnv *env, jobject me) { + + initInstall(); + + jclass clazzString = env->FindClass("java/lang/String"); + jobjectArray ret; + + int count = 0; + for (InstallSourceMap::iterator it = installMgr->sources.begin(); it != installMgr->sources.end(); it++) { + count++; + } + ret = (jobjectArray) env->NewObjectArray(count, clazzString, NULL); + count = 0; + for (InstallSourceMap::iterator it = installMgr->sources.begin(); it != installMgr->sources.end(); it++) { + env->SetObjectArrayElement(ret, count++, env->NewStringUTF(assureValidUTF8(it->second->caption.c_str()))); + } + + return ret; +} + + +/* + * Class: org_crosswire_android_sword_InstallMgr + * Method: refreshRemoteSource + * Signature: (Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_org_crosswire_android_sword_InstallMgr_refreshRemoteSource + (JNIEnv *env, jobject me, jstring sourceNameJS) { + + initInstall(); + + const char *sourceName = env->GetStringUTFChars(sourceNameJS, NULL); + + InstallSourceMap::iterator source = installMgr->sources.find(sourceName); + if (source == installMgr->sources.end()) { + return -3; + } + + env->ReleaseStringUTFChars(sourceNameJS, sourceName); + + return installMgr->refreshRemoteSource(source->second); +} + + +/* + * Class: org_crosswire_android_sword_InstallMgr + * Method: getRemoteModInfoList + * Signature: (Ljava/lang/String;)[Lorg/crosswire/android/sword/SWMgr/ModInfo; + */ +JNIEXPORT jobjectArray JNICALL Java_org_crosswire_android_sword_InstallMgr_getRemoteModInfoList + (JNIEnv *env, jobject me, jstring sourceNameJS) { + +SWLog::getSystemLog()->logDebug("getRemoteModInfoList\n"); + init(); + initInstall(); + + const char *sourceName = env->GetStringUTFChars(sourceNameJS, NULL); +SWLog::getSystemLog()->logDebug("sourceName: %s\n", sourceName); + + jclass clazzModInfo = env->FindClass("org/crosswire/android/sword/SWMgr$ModInfo"); + jfieldID nameID = env->GetFieldID(clazzModInfo, "name", "Ljava/lang/String;"); + jfieldID descID = env->GetFieldID(clazzModInfo, "description", "Ljava/lang/String;"); + jfieldID catID = env->GetFieldID(clazzModInfo, "category", "Ljava/lang/String;"); + jfieldID langID = env->GetFieldID(clazzModInfo, "language", "Ljava/lang/String;"); + jfieldID versionID = env->GetFieldID(clazzModInfo, "version", "Ljava/lang/String;"); + jfieldID deltaID = env->GetFieldID(clazzModInfo, "delta", "Ljava/lang/String;"); + + InstallSourceMap::iterator source = installMgr->sources.find(sourceName); + if (source == installMgr->sources.end()) { +SWLog::getSystemLog()->logDebug("remoteListModules returning 0 length array\n"); + return (jobjectArray) env->NewObjectArray(0, clazzModInfo, NULL); + } +SWLog::getSystemLog()->logDebug("found source: %s\n", sourceName); + + map modStats = installMgr->getModuleStatus(*mgr, *source->second->getMgr()); + + int size = 0; + for (map::iterator it = modStats.begin(); it != modStats.end(); it++) { + size++; + } + +SWLog::getSystemLog()->logDebug("remoteListModules returning %d length array\n", size); + jobjectArray ret = (jobjectArray) env->NewObjectArray(size, clazzModInfo, NULL); + + int i = 0; + for (map::iterator it = modStats.begin(); it != modStats.end(); it++) { + SWModule *module = it->first; + int status = it->second; + + SWBuf version = module->getConfigEntry("Version"); + SWBuf statusString = " "; + if (it->second & InstallMgr::MODSTAT_NEW) statusString = "*"; + if (it->second & InstallMgr::MODSTAT_OLDER) statusString = "-"; + if (it->second & InstallMgr::MODSTAT_UPDATED) statusString = "+"; + + SWBuf type = module->Type(); + SWBuf cat = module->getConfigEntry("Category"); + if (cat.length() > 0) type = cat; + jobject modInfo = env->AllocObject(clazzModInfo); + + jstring val; + val = env->NewStringUTF(assureValidUTF8(module->Name())); env->SetObjectField(modInfo, nameID , val); env->DeleteLocalRef(val); + val = env->NewStringUTF(assureValidUTF8(module->Description())); env->SetObjectField(modInfo, descID , val); env->DeleteLocalRef(val); + val = env->NewStringUTF(assureValidUTF8(type.c_str())); env->SetObjectField(modInfo, catID , val); env->DeleteLocalRef(val); + val = env->NewStringUTF(assureValidUTF8(module->Lang())); env->SetObjectField(modInfo, langID , val); env->DeleteLocalRef(val); + val = env->NewStringUTF(assureValidUTF8(version.c_str())); env->SetObjectField(modInfo, versionID, val); env->DeleteLocalRef(val); + val = env->NewStringUTF(assureValidUTF8(statusString.c_str())); env->SetObjectField(modInfo, deltaID , val); env->DeleteLocalRef(val); + + env->SetObjectArrayElement(ret, i++, modInfo); + + env->DeleteLocalRef(modInfo); + } + + env->ReleaseStringUTFChars(sourceNameJS, sourceName); + + return ret; +} + + +/* + * Class: org_crosswire_android_sword_InstallMgr + * Method: remoteInstallModule + * Signature: (Ljava/lang/String;Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_org_crosswire_android_sword_InstallMgr_remoteInstallModule + (JNIEnv *env, jobject me, jstring sourceNameJS, jstring modNameJS) { + + initInstall(); + + const char *sourceName = env->GetStringUTFChars(sourceNameJS, NULL); +SWLog::getSystemLog()->logDebug("remoteInstallModule: sourceName: %s\n", sourceName); + InstallSourceMap::iterator source = installMgr->sources.find(sourceName); + env->ReleaseStringUTFChars(sourceNameJS, sourceName); + + if (source == installMgr->sources.end()) { + return -3; + } + + InstallSource *is = source->second; + SWMgr *rmgr = is->getMgr(); + SWModule *module; + + const char *modName = env->GetStringUTFChars(modNameJS, NULL); +SWLog::getSystemLog()->logDebug("remoteInstallModule: modName: %s\n", modName); + ModMap::iterator it = rmgr->Modules.find(modName); + env->ReleaseStringUTFChars(modNameJS, modName); + + if (it == rmgr->Modules.end()) { + return -4; + } + + module = it->second; + + int error = installMgr->installModule(mgr, 0, module->Name(), is); + + return error; +} + + +/* + * Class: org_crosswire_android_sword_InstallMgr + * Method: getRemoteModuleByName + * Signature: (Ljava/lang/String;Ljava/lang/String;)Lorg/crosswire/android/sword/SWModule; + */ +JNIEXPORT jobject JNICALL Java_org_crosswire_android_sword_InstallMgr_getRemoteModuleByName + (JNIEnv *env, jobject me, jstring sourceNameJS, jstring modNameJS) { + + jobject retVal = 0; + + initInstall(); + + const char *sourceName = env->GetStringUTFChars(sourceNameJS, NULL); +SWLog::getSystemLog()->logDebug("getRemoteModuleByName: sourceName: %s\n", sourceName); + InstallSourceMap::iterator source = installMgr->sources.find(sourceName); + env->ReleaseStringUTFChars(sourceNameJS, sourceName); + + if (source == installMgr->sources.end()) { +SWLog::getSystemLog()->logDebug("Couldn't find remote source [%s]\n", sourceName); + return 0; + } + + SWMgr *mgr = source->second->getMgr(); + + const char *modName = env->GetStringUTFChars(modNameJS, NULL); + sword::SWModule *module = mgr->getModule(modName); + env->ReleaseStringUTFChars(modNameJS, modName); + + if (module) { + SWBuf type = module->Type(); + SWBuf cat = module->getConfigEntry("Category"); + if (cat.length() > 0) type = cat; + jfieldID fieldID; + jclass clazzSWModule = env->FindClass("org/crosswire/android/sword/SWModule"); + retVal = env->AllocObject(clazzSWModule); + fieldID = env->GetFieldID(clazzSWModule, "name", "Ljava/lang/String;"); env->SetObjectField(retVal, fieldID, env->NewStringUTF(assureValidUTF8(module->Name()))); + fieldID = env->GetFieldID(clazzSWModule, "description", "Ljava/lang/String;"); env->SetObjectField(retVal, fieldID, env->NewStringUTF(assureValidUTF8(module->Description()))); + fieldID = env->GetFieldID(clazzSWModule, "category", "Ljava/lang/String;"); env->SetObjectField(retVal, fieldID, env->NewStringUTF(assureValidUTF8(type.c_str()))); + fieldID = env->GetFieldID(clazzSWModule, "remoteSourceName", "Ljava/lang/String;"); env->SetObjectField(retVal, fieldID, sourceNameJS); + } + + return retVal; + +} + + +/* + * Class: org_crosswire_android_sword_InstallMgr + * Method: setUserDisclaimerConfirmed + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_crosswire_android_sword_InstallMgr_setUserDisclaimerConfirmed + (JNIEnv *env, jobject me) { + + initInstall(); + + installMgr->setUserDisclaimerConfirmed(true); +} + diff --git a/bindings/java-jni/jni/webmgr.hpp b/bindings/java-jni/jni/webmgr.hpp new file mode 100644 index 0000000..7acbff9 --- /dev/null +++ b/bindings/java-jni/jni/webmgr.hpp @@ -0,0 +1,115 @@ +/* + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + */ + +#ifndef WEBMGR_HPP +#define WEBMGR_HPP + +#include +#include +#include +#include +#include +#include +#include + +using namespace sword; + +class WebMgr : public SWMgr { + OSISWordJS *osisWordJS; + ThMLWordJS *thmlWordJS; + GBFWordJS *gbfWordJS; + SWModule *defaultGreekLex; + SWModule *defaultHebLex; + SWModule *defaultGreekParse; + SWModule *defaultHebParse; + +public: +// WebMgr(SWConfig *sysConf) : SWMgr(0, sysConf, false, new MarkupFilterMgr(FMT_WEBIF)) { + WebMgr(const char *path) : SWMgr(path, false, new MarkupFilterMgr(FMT_WEBIF)) { + defaultGreekLex = 0; + defaultHebLex = 0; + defaultGreekParse = 0; + defaultHebParse = 0; + + osisWordJS = new OSISWordJS(); + thmlWordJS = new ThMLWordJS(); + gbfWordJS = new GBFWordJS(); + Load(); + osisWordJS->setDefaultModules(defaultGreekLex, defaultHebLex, defaultGreekParse, defaultHebParse); + thmlWordJS->setDefaultModules(defaultGreekLex, defaultHebLex, defaultGreekParse, defaultHebParse); + gbfWordJS->setDefaultModules(defaultGreekLex, defaultHebLex, defaultGreekParse, defaultHebParse); + osisWordJS->setMgr(this); + thmlWordJS->setMgr(this); + gbfWordJS->setMgr(this); + setGlobalOption("Textual Variants", "Primary Reading"); + } + + ~WebMgr() { + delete osisWordJS; + delete thmlWordJS; + delete gbfWordJS; + } + + + void AddGlobalOptions(SWModule *module, ConfigEntMap §ion, ConfigEntMap::iterator start, ConfigEntMap::iterator end) { + + // ThML word stuff needs to process before strongs strip + if (module->Markup() == FMT_THML) { + module->AddOptionFilter(thmlWordJS); + } + + if (module->Markup() == FMT_GBF) { + module->AddOptionFilter(gbfWordJS); + } + + // add other module filters + SWMgr::AddGlobalOptions(module, section, start, end); + + // add our special filters + if (module->getConfig().has("Feature", "GreekDef")) { + defaultGreekLex = module; + } + if (module->getConfig().has("Feature", "HebrewDef")) { + defaultHebLex = module; + } + if (module->getConfig().has("Feature", "GreekParse")) { + defaultGreekParse = module; + } + if (module->getConfig().has("Feature", "HebrewParse")) { + defaultHebParse = module; + } + if (module->getConfig().has("GlobalOptionFilter", "ThMLVariants")) { + OptionFilterMap::iterator it = optionFilters.find("ThMLVariants"); + if (it != optionFilters.end()) { + module->AddOptionFilter((*it).second); // add filter to module and option as a valid option + } + } + + if (module->Markup() == FMT_OSIS) { + module->AddOptionFilter(osisWordJS); + } + } + + + void setJavascript(bool val) { + osisWordJS->setOptionValue((val)?"On":"Off"); + thmlWordJS->setOptionValue((val)?"On":"Off"); + gbfWordJS->setOptionValue((val)?"On":"Off"); + } +}; + +#endif diff --git a/bindings/java-jni/src/org/crosswire/android/sword/InstallMgr.java b/bindings/java-jni/src/org/crosswire/android/sword/InstallMgr.java new file mode 100644 index 0000000..66c920f --- /dev/null +++ b/bindings/java-jni/src/org/crosswire/android/sword/InstallMgr.java @@ -0,0 +1,17 @@ +package org.crosswire.android.sword; + +public class InstallMgr { + + public native void reInit(); + + public native void setUserDisclaimerConfirmed(); + public native int syncConfig(); + public native int uninstallModule(String modName); + public native String [] getRemoteSources(); + public native int refreshRemoteSource(String sourceName); + public native SWMgr.ModInfo [] getRemoteModInfoList(String sourceName); + public native int remoteInstallModule(String sourceName, String modName); + public native SWModule getRemoteModuleByName(String source, String name); + +} + diff --git a/bindings/java-jni/src/org/crosswire/android/sword/SWMgr.java b/bindings/java-jni/src/org/crosswire/android/sword/SWMgr.java new file mode 100644 index 0000000..dc78485 --- /dev/null +++ b/bindings/java-jni/src/org/crosswire/android/sword/SWMgr.java @@ -0,0 +1,38 @@ +package org.crosswire.android.sword; + +public class SWMgr { + + static { + System.loadLibrary("sword"); + } + + public static class ModInfo { + public String name; + public String description; + public String category; + public String language; + public String version; + public String delta; + } + + + public native String version(); + public native void reInit(); + + public native ModInfo[] getModInfoList(); + public native SWModule getModuleByName(String name); + public native String getPrefixPath(); + public native String getConfigPath(); + public native void setGlobalOption(String option, String value); + public native String getGlobalOption(String option); + public native String getGlobalOptionTip(String option); + public native String filterText(String filterName, String text); + public native String[] getGlobalOptions(); + public native String[] getGlobalOptionValues(String option); + public native void setCipherKey(String modName, String key); + public native void setJavascript(boolean val); + public native String[] getAvailableLocales(); + public native void setDefaultLocale(String name); +} + + diff --git a/bindings/java-jni/src/org/crosswire/android/sword/SWModule.java b/bindings/java-jni/src/org/crosswire/android/sword/SWModule.java new file mode 100644 index 0000000..6a463f9 --- /dev/null +++ b/bindings/java-jni/src/org/crosswire/android/sword/SWModule.java @@ -0,0 +1,65 @@ +package org.crosswire.android.sword; + +public class SWModule { + + private String name; + private String description; + private String category; + + // if this is a shell module from a remote source... + private String remoteSourceName; + + + public static final int SEARCHTYPE_REGEX = 1; + public static final int SEARCHTYPE_PHRASE = -1; + public static final int SEARCHTYPE_MULTIWORD = -2; + public static final int SEARCHTYPE_ENTRYATTR = -3; + public static final int SEARCHTYPE_LUCENE = -4; + + private SWModule() {} // don't allow allocation, instead use factory method SWMgr.getModuleByName to retrieve an instance + + public static class SearchHit { + public String modName; + public String key; + public long score; + } + + public static interface SearchProgressReporter { + public void progressReport(int percent); + } + + public native void terminateSearch(); + public native SearchHit[] search(String expression, int searchType, long flags, String scope, SearchProgressReporter progressReporter); + public SearchHit[] search(String expression) { return search(expression, SEARCHTYPE_MULTIWORD, 0, "", null); } + public native char error(); + public native long getEntrySize(); + public native String[] getEntryAttribute(String level1, String level2, String level3, boolean filtered); + public native String[] parseKeyList(String keyText); + + // Special values handled for VerseKey modules: [+-][book|chapter] + // (e.g. "+chapter" will increment the VerseKey 1 chapter) + public native void setKeyText(String key); + + public native String getKeyText(); + public native boolean hasKeyChildren(); + + // This method returns child nodes for a genbook, + // but has special handling if called on a VerseKey module: + // [0..6] [testament, book, chapter, verse, chapterMax, verseMax, bookName] + public native String[] getKeyChildren(); + + public native String getKeyParent(); + public String getName() { return name; } + public String getDescription() { return description; } + public String getCategory() { return category; } + public native void previous(); + public native void next(); + public native void begin(); + public native String getStripText(); + public native String getRenderText(); + public native String getRawEntry(); + public native void setRawEntry(String entryBuffer); + public native String getConfigEntry(String key); + public native void deleteSearchFramework(); + public native boolean hasSearchFramework(); +} -- cgit v1.2.3