[sword-svn] r3641 - in trunk/bindings: cordova/cordova-plugin-crosswire-sword/src/android cordova/cordova-plugin-crosswire-sword/www java-jni/jni java-jni/src/org/crosswire/android/sword
scribe at crosswire.org
scribe at crosswire.org
Fri May 31 20:31:08 MST 2019
Author: scribe
Date: 2019-05-31 20:31:08 -0700 (Fri, 31 May 2019)
New Revision: 3641
Modified:
trunk/bindings/cordova/cordova-plugin-crosswire-sword/src/android/SWORD.java
trunk/bindings/cordova/cordova-plugin-crosswire-sword/www/SWORD.js
trunk/bindings/java-jni/jni/swordstub.cpp
trunk/bindings/java-jni/src/org/crosswire/android/sword/SWModule.java
Log:
cordova plugin: Added getRemoteModuleByName and support handling remote SWModule object. Added support for null results from getConfigEntry
Modified: trunk/bindings/cordova/cordova-plugin-crosswire-sword/src/android/SWORD.java
===================================================================
--- trunk/bindings/cordova/cordova-plugin-crosswire-sword/src/android/SWORD.java 2019-05-30 21:54:06 UTC (rev 3640)
+++ trunk/bindings/cordova/cordova-plugin-crosswire-sword/src/android/SWORD.java 2019-06-01 03:31:08 UTC (rev 3641)
@@ -143,6 +143,25 @@
}
callbackContext.success(r);
}
+ else if (action.equals("InstallMgr_getRemoteModuleByName")) {
+ SWModule mod = installMgr.getRemoteModuleByName(args.getString(0), args.getString(1));
+ // didn't find module is not an error
+ if (mod == null) { callbackContext.success(); return true; }
+
+ JSONObject m = new JSONObject();
+ m.put("name", mod.getName());
+ m.put("description", mod.getDescription());
+ m.put("category", mod.getCategory());
+ m.put("remoteSourceName", mod.getRemoteSourceName());
+ m.put("direction", mod.getConfigEntry("Direction"));
+ m.put("language", mod.getConfigEntry("Lang"));
+ m.put("font", mod.getConfigEntry("Font"));
+ m.put("shortCopyright", mod.getConfigEntry("ShortCopyright"));
+ m.put("shortPromo", mod.getConfigEntry("ShortPromo"));
+ m.put("cipherKey", mod.getConfigEntry("CipherKey"));
+Log.d(TAG, "SWModule_getRemoteModuleByName("+args.getString(0)+", " + args.getString(1) + " returned successfully.");
+ callbackContext.success(m);
+ }
else if (action.equals("InstallMgr_remoteInstallModule")) {
final String repo = args.getString(0);
final String modName = args.getString(1);
@@ -461,7 +480,7 @@
callbackContext.success(r);
}
else if (action.equals("SWModule_getConfigEntry")) {
- SWModule mod = mgr.getModuleByName(args.getString(0));
+ SWModule mod = new SWModule(args.getString(0), args.getString(2));
if (mod == null) { callbackContext.error("couldn't find module: " + args.getString(0)); return true; }
callbackContext.success(mod.getConfigEntry(args.getString(1)));
}
Modified: trunk/bindings/cordova/cordova-plugin-crosswire-sword/www/SWORD.js
===================================================================
--- trunk/bindings/cordova/cordova-plugin-crosswire-sword/www/SWORD.js 2019-05-30 21:54:06 UTC (rev 3640)
+++ trunk/bindings/cordova/cordova-plugin-crosswire-sword/www/SWORD.js 2019-06-01 03:31:08 UTC (rev 3641)
@@ -59,6 +59,15 @@
return retVal;
}
+InstallMgr.prototype.getRemoteModuleByName = function(sourceName, modName, callback) {
+ var mod = null;
+ exec(function(m) { if (m.name) mod = new SWModule(m); if (callback) callback(mod); },
+ function(err) { utils.alert('[ERROR] problem: ' + err); },
+ "SWORD", "InstallMgr_getRemoteModuleByName", [sourceName, modName]
+ );
+ return mod;
+}
+
// callback({ status : preStatus|update|complete, totalBytes : n, completedBytes : n, message : displayable });
InstallMgr.prototype.remoteInstallModule = function(sourceName, modName, callback) {
var retVal = null;
@@ -79,14 +88,16 @@
}
function SWModule(modInfo) {
- this.name = modInfo.name;
- this.description = modInfo.description;
- this.category = modInfo.category;
- this.direction = modInfo.direction;
- this.language = modInfo.language;
- this.font = modInfo.font;
- this.shortCopyright = modInfo.shortCopyright;
- this.shortPromo = modInfo.shortPromo;
+ this.name = modInfo.name;
+ this.description = modInfo.description;
+ this.category = modInfo.category;
+ this.direction = modInfo.direction;
+ this.language = modInfo.language;
+ this.font = modInfo.font;
+ this.shortCopyright = modInfo.shortCopyright;
+ this.shortPromo = modInfo.shortPromo;
+ this.cipherKey = modInfo.cipherKey;
+ this.remoteSourceName = modInfo.remoteSourceName;
}
SWModule.prototype.SEARCHTYPE_REGEX = 1;
@@ -190,7 +201,7 @@
var retVal = '';
exec(callback?callback:function(m) { if (m) retVal = m; },
function(err) { utils.alert('[ERROR] problem: ' + err); },
- "SWORD", "SWModule_getConfigEntry", [this.name, key]
+ "SWORD", "SWModule_getConfigEntry", [this.name, key, this.remoteSourceName]
);
return retVal;
}
Modified: trunk/bindings/java-jni/jni/swordstub.cpp
===================================================================
--- trunk/bindings/java-jni/jni/swordstub.cpp 2019-05-30 21:54:06 UTC (rev 3640)
+++ trunk/bindings/java-jni/jni/swordstub.cpp 2019-06-01 03:31:08 UTC (rev 3641)
@@ -1034,10 +1034,12 @@
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);
+SWLog::getSystemLog()->logDebug("libsword: lookup up module %s at from source: %s", modName?modName:"null", sourceName?sourceName:"null");
+
if (sourceName && *sourceName) {
initInstall(env);
InstallSourceMap::iterator source = installMgr->sources.find(sourceName);
- if (source == installMgr->sources.end()) {
+ if (source != installMgr->sources.end()) {
SWMgr *mgr = source->second->getMgr();
module = mgr->getModule(modName);
}
@@ -1638,13 +1640,18 @@
SWModule *module = getModule(env, me);
if (module) {
- SWBuf confValue = module->getConfigEntry(configKey);
- // special processing if we're requesting About-- kindof cheese
- if (!strcmp("About", configKey)) {
- RTFHTML().processText(confValue);
+SWLog::getSystemLog()->logDebug("getConfigEntry, found module.");
+
+
+ const char *configValue = module->getConfigEntry(configKey);
+ if (configValue) {
+ SWBuf confValue = configValue;
+ // special processing if we're requesting About-- kindof cheese
+ if (!strcmp("About", configKey)) {
+ RTFHTML().processText(confValue);
+ }
+ retVal = strToUTF8Java(env, assureValidUTF8(confValue.c_str()));
}
- SWBuf assuredBuf = assureValidUTF8(confValue.c_str());
- retVal = strToUTF8Java(env, assuredBuf.c_str());
}
env->ReleaseStringUTFChars(configKeyJS, configKey);
@@ -2076,23 +2083,26 @@
initInstall(env);
- 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);
+ const char *sourceNameC = env->GetStringUTFChars(sourceNameJS, NULL);
+ SWBuf sourceName = sourceNameC;
+SWLog::getSystemLog()->logDebug("getRemoteModuleByName: sourceName: %s\n", sourceName.c_str());
+ InstallSourceMap::iterator source = installMgr->sources.find(sourceName.c_str());
+ env->ReleaseStringUTFChars(sourceNameJS, sourceNameC);
if (source == installMgr->sources.end()) {
-SWLog::getSystemLog()->logDebug("Couldn't find remote source [%s]\n", sourceName);
+SWLog::getSystemLog()->logDebug("Couldn't find remote source [%s]\n", sourceName.c_str());
return 0;
}
SWMgr *mgr = source->second->getMgr();
- const char *modName = env->GetStringUTFChars(modNameJS, NULL);
- sword::SWModule *module = mgr->getModule(modName);
- env->ReleaseStringUTFChars(modNameJS, modName);
+ const char *modNameC = env->GetStringUTFChars(modNameJS, NULL);
+ SWBuf modName = modNameC;
+ sword::SWModule *module = mgr->getModule(modName.c_str());
+ env->ReleaseStringUTFChars(modNameJS, modNameC);
if (module) {
+SWLog::getSystemLog()->logDebug("Found remote module [%s]: %s\n", sourceName.c_str(), modName.c_str());
SWBuf type = module->getType();
SWBuf cat = module->getConfigEntry("Category");
if (cat.length() > 0) type = cat;
@@ -2103,6 +2113,7 @@
fieldID = env->GetFieldID(clazzSWModule, "description", "Ljava/lang/String;"); env->SetObjectField(retVal, fieldID, strToUTF8Java(env, assureValidUTF8(module->getDescription())));
fieldID = env->GetFieldID(clazzSWModule, "category", "Ljava/lang/String;"); env->SetObjectField(retVal, fieldID, strToUTF8Java(env, assureValidUTF8(type.c_str())));
fieldID = env->GetFieldID(clazzSWModule, "remoteSourceName", "Ljava/lang/String;"); env->SetObjectField(retVal, fieldID, sourceNameJS);
+SWLog::getSystemLog()->logDebug("returning remote module [%s]: %s\n", sourceName.c_str(), modName.c_str());
}
return retVal;
Modified: trunk/bindings/java-jni/src/org/crosswire/android/sword/SWModule.java
===================================================================
--- trunk/bindings/java-jni/src/org/crosswire/android/sword/SWModule.java 2019-05-30 21:54:06 UTC (rev 3640)
+++ trunk/bindings/java-jni/src/org/crosswire/android/sword/SWModule.java 2019-06-01 03:31:08 UTC (rev 3641)
@@ -50,6 +50,7 @@
public static final int VERSEKEY_BOOKABBREV = 9;
private SWModule() {} // don't allow allocation, instead use factory method SWMgr.getModuleByName to retrieve an instance
+ public SWModule(String name, String remoteSourceName) { this.name = name; this.remoteSourceName = remoteSourceName; } // ok, well, our stub can create a shell with name and remoteSourceName
public static class SearchHit {
public String modName;
@@ -85,6 +86,7 @@
public String getName() { return name; }
public String getDescription() { return description; }
public String getCategory() { return category; }
+ public String getRemoteSourceName() { return remoteSourceName; }
public native void previous();
public native void next();
public native void begin();
More information about the sword-cvs
mailing list