mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 09:49:19 +02:00
BookReadingException can be thrown from native code
This commit is contained in:
parent
5f6223353d
commit
0e476c760c
4 changed files with 32 additions and 3 deletions
|
@ -17,6 +17,8 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <ZLFile.h>
|
||||
|
||||
#include "AndroidUtil.h"
|
||||
|
||||
JavaVM *AndroidUtil::ourJavaVM = 0;
|
||||
|
@ -37,6 +39,7 @@ const char * const AndroidUtil::Class_ZLFile = "org/geometerplus/zlibrary/core/f
|
|||
const char * const AndroidUtil::Class_Book = "org/geometerplus/fbreader/library/Book";
|
||||
const char * const AndroidUtil::Class_Tag = "org/geometerplus/fbreader/library/Tag";
|
||||
const char * const AndroidUtil::Class_NativeBookModel = "org/geometerplus/fbreader/bookmodel/NativeBookModel";
|
||||
const char * const AndroidUtil::Class_BookReadingException = "org/geometerplus/fbreader/bookmodel/BookReadingException";
|
||||
|
||||
jmethodID AndroidUtil::MID_java_lang_String_toLowerCase;
|
||||
jmethodID AndroidUtil::MID_java_lang_String_toUpperCase;
|
||||
|
@ -103,6 +106,8 @@ jmethodID AndroidUtil::MID_NativeBookModel_createTextModel;
|
|||
jmethodID AndroidUtil::MID_NativeBookModel_setBookTextModel;
|
||||
jmethodID AndroidUtil::MID_NativeBookModel_setFootnoteModel;
|
||||
|
||||
jmethodID AndroidUtil::SMID_BookReadingException_throwForFile;
|
||||
|
||||
JNIEnv *AndroidUtil::getEnv() {
|
||||
JNIEnv *env;
|
||||
ourJavaVM->GetEnv((void **)&env, JNI_VERSION_1_2);
|
||||
|
@ -216,6 +221,10 @@ bool AndroidUtil::init(JavaVM* jvm) {
|
|||
CHECK_NULL( MID_NativeBookModel_setFootnoteModel = env->GetMethodID(cls, "setFootnoteModel", "(Lorg/geometerplus/zlibrary/text/model/ZLTextModel;)V") );
|
||||
env->DeleteLocalRef(cls);
|
||||
|
||||
CHECK_NULL( cls = env->FindClass(Class_BookReadingException) );
|
||||
CHECK_NULL( SMID_BookReadingException_throwForFile = env->GetStaticMethodID(cls, "throwForFile", "(Ljava/lang/String;Lorg/geometerplus/zlibrary/core/filesystem/ZLFile;)V") );
|
||||
env->DeleteLocalRef(cls);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -299,6 +308,14 @@ void AndroidUtil::throwRuntimeException(JNIEnv *env, const std::string &message)
|
|||
env->ThrowNew(cls, message.c_str());
|
||||
}
|
||||
|
||||
void AndroidUtil::throwBookReadingException(JNIEnv *env, const std::string &resourceId, const std::string &filePath) {
|
||||
// TODO: implement
|
||||
void AndroidUtil::throwBookReadingException(const std::string &resourceId, const ZLFile &file) {
|
||||
JNIEnv *env = getEnv();
|
||||
jclass cls = env->FindClass("org/geometerplus/fbreader/bookmodel/BookReadingException");
|
||||
env->CallStaticVoidMethod(
|
||||
cls,
|
||||
SMID_BookReadingException_throwForFile,
|
||||
AndroidUtil::createJavaString(env, resourceId),
|
||||
AndroidUtil::createZLFile(env, file.path())
|
||||
);
|
||||
// TODO: clear cls & ZLFile object references
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class ZLFile;
|
||||
|
||||
class AndroidUtil {
|
||||
|
||||
private:
|
||||
|
@ -47,6 +49,7 @@ public:
|
|||
static const char * const Class_Book;
|
||||
static const char * const Class_Tag;
|
||||
static const char * const Class_NativeBookModel;
|
||||
static const char * const Class_BookReadingException;
|
||||
|
||||
static jmethodID MID_java_lang_String_toLowerCase;
|
||||
static jmethodID MID_java_lang_String_toUpperCase;
|
||||
|
@ -113,6 +116,8 @@ public:
|
|||
static jmethodID MID_NativeBookModel_setBookTextModel;
|
||||
static jmethodID MID_NativeBookModel_setFootnoteModel;
|
||||
|
||||
static jmethodID SMID_BookReadingException_throwForFile;
|
||||
|
||||
public:
|
||||
static bool init(JavaVM* jvm);
|
||||
static JNIEnv *getEnv();
|
||||
|
@ -127,7 +132,7 @@ public:
|
|||
static jobjectArray createStringArray(JNIEnv *env, const std::vector<std::string> &data);
|
||||
|
||||
static void throwRuntimeException(JNIEnv *env, const std::string &message);
|
||||
static void throwBookReadingException(JNIEnv *env, const std::string &resourceId, const std::string &filePath);
|
||||
static void throwBookReadingException(const std::string &resourceId, const ZLFile &file);
|
||||
};
|
||||
|
||||
#endif /* __ANDROIDUTIL_H__ */
|
||||
|
|
|
@ -84,6 +84,9 @@
|
|||
public void setBookTextModel(**);
|
||||
public void setFootnoteModel(**);
|
||||
}
|
||||
-keepclassmembers class org.geometerplus.fbreader.bookmodel.BookReadingException {
|
||||
public static void throwForFile(**,**);
|
||||
}
|
||||
|
||||
-keepclasseswithmembernames class * {
|
||||
native <methods>;
|
||||
|
|
|
@ -27,6 +27,10 @@ import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
|||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
|
||||
public final class BookReadingException extends Exception {
|
||||
public static void throwForFile(String resourceId, ZLFile file) throws BookReadingException {
|
||||
throw new BookReadingException(resourceId, file);
|
||||
}
|
||||
|
||||
private static String getResourceText(String resourceId) {
|
||||
return ZLResource.resource("bookReadingException").getResource(resourceId).getValue();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue